Skip to content

Commit 90f43cc

Browse files
committed
INS-14641 Add a command to do just Dilithium NTT
For measuring leakage in the forward NTT stage of Dilithium. For example, when the challenge is or the S1 private key is converted to the frequency domain.
1 parent fbcd1bd commit 90f43cc

4 files changed

Lines changed: 41 additions & 0 deletions

File tree

src/dilithium/wrapper.c

100644100755
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "./params.h"
33
#include "./api.h"
44
#include "./sign.h"
5+
#include "./poly.h"
56
#include <string.h>
67

78
#if DILITHIUM_PUBLIC_KEY_SIZE != CRYPTO_PUBLICKEYBYTES
@@ -13,6 +14,9 @@
1314
#if DILITHIUM_SIGNATURE_SIZE != CRYPTO_BYTES
1415
#error invalid signature size, update me!
1516
#endif
17+
#if DILITHIUM_N != N
18+
#error invalid N, update me!
19+
#endif
1620

1721
int getDilithiumAlgorithmVariant() {
1822
return DILITHIUM_MODE;
@@ -39,3 +43,9 @@ int DilithiumState_sign(const DilithiumState* self, uint8_t* signature, const ui
3943
size_t signatureSize = DILITHIUM_SIGNATURE_SIZE;
4044
return crypto_sign_signature(signature, &signatureSize, message, DILITHIUM_MESSAGE_SIZE, self->m_sk);
4145
}
46+
47+
int Dilithium_ntt(uint32_t* coefficients) {
48+
poly* coeffs = (poly*)coefficients;
49+
poly_ntt(coeffs);
50+
return 0;
51+
}

src/dilithium/wrapper.h

100644100755
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#define DILITHIUM_PRIVATE_KEY_SIZE 4016
99
#define DILITHIUM_SIGNATURE_SIZE 3293
1010
#define DILITHIUM_MESSAGE_SIZE 16
11+
#define DILITHIUM_N 256
1112
#define DILITHIUM_SIGNED_MESSAGE_SIZE (DILITHIUM_SIGNATURE_SIZE + DILITHIUM_MESSAGE_SIZE)
1213

1314
/**
@@ -79,4 +80,14 @@ int DilithiumState_verify(const DilithiumState* self, uint8_t *signedMessage);
7980
*/
8081
int DilithiumState_sign(const DilithiumState* self, uint8_t* signature, const uint8_t* message);
8182

83+
///
84+
/// @brief Perform a forward NTT.
85+
///
86+
/// @param[inout] coefficients Buffer of polynomial coefficients in integer
87+
/// domain. The computation is done in-place, and
88+
/// this array contains the coefficients in the
89+
/// frequency domain after this function returns.
90+
///
91+
int Dilithium_ntt(uint32_t *coefficients);
92+
8293
#endif // _DILITHIUM_WRAPPER_H_

src/main.c

100644100755
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,17 @@ int main(void) {
298298
break;
299299
}
300300

301+
case CMD_SW_DILITHIUM_NTT: {
302+
int32_t polynomialBuffer[DILITHIUM_N];
303+
// Receive the polynomial coefficients.
304+
get_bytes(sizeof(int32_t)*DILITHIUM_N, (uint8_t*)polynomialBuffer);
305+
BEGIN_INTERESTING_STUFF;
306+
Dilithium_ntt(polynomialBuffer);
307+
END_INTERESTING_STUFF;
308+
// No reply is sent.
309+
break;
310+
}
311+
301312
case CMD_SW_KYBER512_SET_PUBLIC_AND_PRIVATE_KEY: {
302313
// Receive the input parameters and handle the request.
303314
get_bytes(KYBER512_PUBLIC_KEY_SIZE, Kyber512State_getPublicKey(&kyber512));

src/main.h

100644100755
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,15 @@
216216
/// 16-bit unsigned integer in little endian order that contains the private key size
217217
#define CMD_SW_DILITHIUM_GET_KEY_SIZES 0x94
218218

219+
/// Perform Dilithium NTT.
220+
///
221+
/// Expected Input:
222+
/// A total of DILITHIUM_N 32-bit integers in little endian order.
223+
///
224+
/// Output:
225+
/// No reply is sent back.
226+
#define CMD_SW_DILITHIUM_NTT 0x9A
227+
219228
#define CMD_SWDES_ENC_MISALIGNED 0x14
220229
#define CMD_SWAES128_ENC_MISALIGNED 0x1E
221230
#define CMD_SWDES_ENC_DUMMYROUNDS 0x15

0 commit comments

Comments
 (0)