Skip to content

Commit 85beb05

Browse files
committed
Simplify signature of mld_poly_uniform_eta_4x
mld_poly_uniform_eta_4x before was taking 4 separate nonce values. However, we were using only consecutive nonces in all call sites (except for the irrelevant values - which were 0xFF). This commit changes the function signature to take only a single nonce. This aligns mld_poly_uniform_eta_4x with mld_poly_uniform_gamma1_4x which was adjusted in the previous commit. Signed-off-by: Matthias J. Kannwischer <[email protected]>
1 parent 35ae404 commit 85beb05

File tree

4 files changed

+25
-26
lines changed

4 files changed

+25
-26
lines changed

mldsa/poly.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -391,30 +391,31 @@ __contract__(
391391
*
392392
* Description: Sample four polynomials with uniformly random coefficients
393393
* in [-MLDSA_ETA,MLDSA_ETA] by performing rejection sampling on
394-
* the output stream from SHAKE256(seed|nonce_i)
394+
* the output streams of
395+
* SHAKE256(seed|nonce),
396+
* SHAKE256(seed|nonce + 1),
397+
* SHAKE256(seed|nonce + 2),
398+
* SHAKE256(seed|nonce + 3).
395399
*
396400
* Arguments: - mld_poly *r0: pointer to first output polynomial
397401
* - mld_poly *r1: pointer to second output polynomial
398402
* - mld_poly *r2: pointer to third output polynomial
399403
* - mld_poly *r3: pointer to fourth output polynomial
400404
* - const uint8_t seed[]: byte array with seed of length
401405
* MLDSA_CRHBYTES
402-
* - uint8_t nonce0: first nonce
403-
* - uint8_t nonce1: second nonce
404-
* - uint8_t nonce2: third nonce
405-
* - uint8_t nonce3: fourth nonce
406+
* - uint8_t nonce: 16-bit nonce
406407
**************************************************/
407408
MLD_INTERNAL_API
408409
void mld_poly_uniform_eta_4x(mld_poly *r0, mld_poly *r1, mld_poly *r2,
409410
mld_poly *r3, const uint8_t seed[MLDSA_CRHBYTES],
410-
uint8_t nonce0, uint8_t nonce1, uint8_t nonce2,
411-
uint8_t nonce3)
411+
uint8_t nonce)
412412
__contract__(
413413
requires(memory_no_alias(r0, sizeof(mld_poly)))
414414
requires(memory_no_alias(r1, sizeof(mld_poly)))
415415
requires(memory_no_alias(r2, sizeof(mld_poly)))
416416
requires(memory_no_alias(r3, sizeof(mld_poly)))
417417
requires(memory_no_alias(seed, MLDSA_CRHBYTES))
418+
requires(nonce <= UINT8_MAX - 3)
418419
assigns(memory_slice(r0, sizeof(mld_poly)))
419420
assigns(memory_slice(r1, sizeof(mld_poly)))
420421
assigns(memory_slice(r2, sizeof(mld_poly)))

mldsa/poly_kl.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,7 @@ __contract__(
321321
MLD_INTERNAL_API
322322
void mld_poly_uniform_eta_4x(mld_poly *r0, mld_poly *r1, mld_poly *r2,
323323
mld_poly *r3, const uint8_t seed[MLDSA_CRHBYTES],
324-
uint8_t nonce0, uint8_t nonce1, uint8_t nonce2,
325-
uint8_t nonce3)
324+
uint8_t nonce)
326325
{
327326
/* Temporary buffers for XOF output before rejection sampling */
328327
MLD_ALIGN uint8_t
@@ -339,10 +338,11 @@ void mld_poly_uniform_eta_4x(mld_poly *r0, mld_poly *r1, mld_poly *r2,
339338
mld_memcpy(extseed[1], seed, MLDSA_CRHBYTES);
340339
mld_memcpy(extseed[2], seed, MLDSA_CRHBYTES);
341340
mld_memcpy(extseed[3], seed, MLDSA_CRHBYTES);
342-
extseed[0][MLDSA_CRHBYTES] = nonce0;
343-
extseed[1][MLDSA_CRHBYTES] = nonce1;
344-
extseed[2][MLDSA_CRHBYTES] = nonce2;
345-
extseed[3][MLDSA_CRHBYTES] = nonce3;
341+
/* Safety: Truncation is safe because nonce it at most 11 */
342+
extseed[0][MLDSA_CRHBYTES] = nonce;
343+
extseed[1][MLDSA_CRHBYTES] = (uint8_t)(nonce + 1);
344+
extseed[2][MLDSA_CRHBYTES] = (uint8_t)(nonce + 2);
345+
extseed[3][MLDSA_CRHBYTES] = (uint8_t)(nonce + 3);
346346
extseed[0][MLDSA_CRHBYTES + 1] = 0;
347347
extseed[1][MLDSA_CRHBYTES + 1] = 0;
348348
extseed[2][MLDSA_CRHBYTES + 1] = 0;

mldsa/sign.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -120,27 +120,25 @@ __contract__(
120120
/* Sample short vectors s1 and s2 */
121121
#if MLD_CONFIG_PARAMETER_SET == 44
122122
mld_poly_uniform_eta_4x(&s1->vec[0], &s1->vec[1], &s1->vec[2], &s1->vec[3],
123-
seed, 0, 1, 2, 3);
123+
seed, 0);
124124
mld_poly_uniform_eta_4x(&s2->vec[0], &s2->vec[1], &s2->vec[2], &s2->vec[3],
125-
seed, 4, 5, 6, 7);
125+
seed, 4);
126126
#elif MLD_CONFIG_PARAMETER_SET == 65
127127
mld_poly_uniform_eta_4x(&s1->vec[0], &s1->vec[1], &s1->vec[2], &s1->vec[3],
128-
seed, 0, 1, 2, 3);
128+
seed, 0);
129129
mld_poly_uniform_eta_4x(&s1->vec[4], &s2->vec[0], &s2->vec[1],
130-
&s2->vec[2] /* irrelevant */, seed, 4, 5, 6,
131-
0xFF /* irrelevant */);
130+
&s2->vec[2] /* irrelevant */, seed, 4);
132131
mld_poly_uniform_eta_4x(&s2->vec[2], &s2->vec[3], &s2->vec[4], &s2->vec[5],
133-
seed, 7, 8, 9, 10);
132+
seed, 7);
134133
#elif MLD_CONFIG_PARAMETER_SET == 87
135134
mld_poly_uniform_eta_4x(&s1->vec[0], &s1->vec[1], &s1->vec[2], &s1->vec[3],
136-
seed, 0, 1, 2, 3);
135+
seed, 0);
137136
mld_poly_uniform_eta_4x(&s1->vec[4], &s1->vec[5], &s1->vec[6],
138-
&s2->vec[0] /* irrelevant */, seed, 4, 5, 6,
139-
0xFF /* irrelevant */);
137+
&s2->vec[0] /* irrelevant */, seed, 4);
140138
mld_poly_uniform_eta_4x(&s2->vec[0], &s2->vec[1], &s2->vec[2], &s2->vec[3],
141-
seed, 7, 8, 9, 10);
139+
seed, 7);
142140
mld_poly_uniform_eta_4x(&s2->vec[4], &s2->vec[5], &s2->vec[6], &s2->vec[7],
143-
seed, 11, 12, 13, 14);
141+
seed, 11);
144142
#endif /* MLD_CONFIG_PARAMETER_SET == 87 */
145143
}
146144

proofs/cbmc/poly_uniform_eta_4x/poly_uniform_eta_4x_harness.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ void harness(void)
77
{
88
mld_poly *r0, *r1, *r2, *r3;
99
const uint8_t *seed;
10-
uint8_t n0, n1, n2, n3;
10+
uint8_t nonce;
1111

12-
mld_poly_uniform_eta_4x(r0, r1, r2, r3, seed, n0, n1, n2, n3);
12+
mld_poly_uniform_eta_4x(r0, r1, r2, r3, seed, nonce);
1313
}

0 commit comments

Comments
 (0)