Skip to content

Commit 594164d

Browse files
committed
ML-DSA: Add reduction step
If the invntt implementation cannot guarantee to provide small enough results, a reduction step is needed. For now, C, AVX2 and ARMv8 invntt implementations provide the guarantee of small integers. The other implementations need to be analyzed. The change is obtained from https://github.com/pq-code-package/mldsa-native Reported-by: Hanno Becker <beckphan@amazon.co.uk> Signed-off-by: Stephan Mueller <smueller@chronox.de>
1 parent 4376310 commit 594164d

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

ml-dsa/src/armv8/dilithium_signature_armv8.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
/* We need twice the buffer size as we have a 2 lane SHAKE SIMD implemenation */
2626
#define LC_POLY_UNIFOR_BUF_SIZE_MULTIPLIER 2
2727

28+
/* The C implementation of invntt produces small enough integers */
29+
#define LC_DILITHIUM_INVNTT_SMALL
30+
2831
#include "dilithium_poly.h"
2932
#include "dilithium_poly_common.h"
3033
#include "dilithium_poly_armv8.h"

ml-dsa/src/dilithium_signature_c.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
/* We need once the buffer size to handle the hashing */
3232
#define LC_POLY_UNIFOR_BUF_SIZE_MULTIPLIER 1
3333

34+
/* The C implementation of invntt produces small enough integers */
35+
#define LC_DILITHIUM_INVNTT_SMALL
36+
3437
#include "dilithium_poly.h"
3538
#include "dilithium_poly_common.h"
3639
#include "dilithium_poly_c.h"

ml-dsa/src/dilithium_signature_impl.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,21 @@ static int lc_dilithium_keypair_impl(struct lc_dilithium_pk *pk,
190190
dilithium_print_polyveck(&ws->t1,
191191
"Keygen - T K x N matrix after add S2:");
192192

193+
/*
194+
* Reference: The following reduction is not present in the reference
195+
* implementation. Omitting this reduction requires the output of
196+
* the invntt to be small enough such that the addition of s2 does
197+
* not result in absolute values >= LC_DILITHIUM_Q. While the C, x86_64,
198+
* and AArch64 invntt implementations produce small enough
199+
* values for this to work out, it complicates the bounds
200+
* reasoning. Therefore, add an additional reduction, allowing to
201+
* relax the bounds requirements for the invntt, especially when adding
202+
* new invntt assembler implementations.
203+
*/
204+
#ifndef LC_DILITHIUM_INVNTT_SMALL
205+
polyveck_reduce(&ws->t1);
206+
#endif
207+
193208
/* Extract t1 and write public key */
194209
polyveck_caddq(&ws->t1);
195210
dilithium_print_polyveck(&ws->t1, "Keygen - T K x N matrix caddq:");

0 commit comments

Comments
 (0)