Skip to content

Commit f31f484

Browse files
[crypto] ML-DSA-87: Rounding and computation of T0 and T1
Signed-off-by: Andrea Caforio <andrea.caforio@lowrisc.org>
1 parent f5a673e commit f31f484

4 files changed

Lines changed: 200 additions & 0 deletions

File tree

sw/otbn/crypto/mldsa87/keygen/mldsa87_keygen_ops.s

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
.globl sample_s
88
.globl compute_t
9+
.globl encode_t
910

1011
.text
1112

@@ -261,3 +262,58 @@ compute_t:
261262
/* End of loop */
262263

263264
ret
265+
266+
/**
267+
* Round and encode T.
268+
*
269+
* This routine unmasks the arithmetically shared vector T, rounds it to T0 and
270+
* T1 vectors which are then encoded on-the-fly.
271+
*
272+
* Two polynomial slots are required for the storage of intermediate results.
273+
*
274+
* @param[in] x2: DMEM address of the first arithmetic share of T (8192 bytes).
275+
* @param[in] x3: DMEM address of the second arithmetic share of T (8192 bytes).
276+
* @param[in] x4: DMEM address of the encoded T0 vector (3328 bytes).
277+
* @param[in] x5: DMEM address of the encoded T1 vector (2560 bytes).
278+
* @param[in] x6: DMEM address of polynomial slot 0 (1024 bytes).
279+
* @param[in] x7: DMEM address of polynomial slot 1 (1024 bytes).
280+
*/
281+
encode_t:
282+
/* Prepare DMEM address registers. */
283+
addi x8, x2, 0 /* T (share 0) */
284+
addi x9, x3, 0 /* T (share 1) */
285+
addi x10, x4, 0 /* T0_enc */
286+
addi x11, x5, 0 /* T1_enc */
287+
288+
/* Unmask, round and encode each T polynomial. */
289+
loopi 8, 18
290+
/* Securely unmask T into slot 0. */
291+
addi x2, x8, 0
292+
addi x3, x9, 0
293+
addi x4, x6, 0
294+
jal x1, sec_unmask
295+
296+
/* Split T into T0 and T1 in slots 0 and 1. */
297+
addi x2, x6, 0
298+
addi x3, x6, 0
299+
addi x4, x7, 0
300+
jal x1, power2round
301+
302+
/* Encode T0 into the output location. */
303+
addi x2, x6, 0
304+
addi x3, x10, 0
305+
jal x1, encode_t0
306+
307+
/* Encode T1 into the output location. */
308+
addi x2, x7, 0
309+
addi x3, x11, 0
310+
jal x1, encode_t1
311+
312+
/* Advance T and output pointers.*/
313+
addi x8, x8, 1024
314+
addi x9, x9, 1024
315+
addi x10, x10, 416
316+
addi x11, x11, 320
317+
/* End of loop */
318+
319+
ret

sw/otbn/crypto/mldsa87/keygen/tests/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ unit_tests = [
3333
"mldsa87_keygen_encode_s_test",
3434
"mldsa87_keygen_sample_s_test",
3535
"mldsa87_keygen_compute_t_test",
36+
"mldsa87_keygen_encode_t_test",
3637
]
3738

3839
[

0 commit comments

Comments
 (0)