Skip to content

Commit 2b6181c

Browse files
committed
Make ML-DSA signing w1e variable aware of SMALL_STACK
1 parent dd80dd2 commit 2b6181c

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

wolfcrypt/src/dilithium.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8679,7 +8679,7 @@ static int dilithium_sign_with_seed_mu(dilithium_key* key,
86798679
/* Step 11: Start rejection sampling loop */
86808680
do {
86818681
byte aseed[DILITHIUM_GEN_A_SEED_SZ];
8682-
byte w1e[DILITHIUM_MAX_W1_ENC_SZ];
8682+
WC_DECLARE_VAR(w1e, byte, DILITHIUM_MAX_W1_ENC_SZ, 0);
86838683
sword32* w = w1;
86848684
byte* commit = sig;
86858685
byte r;
@@ -8910,11 +8910,17 @@ static int dilithium_sign_with_seed_mu(dilithium_key* key,
89108910
byte* ze = sig + params->lambda / 4;
89118911

89128912
/* Step 15: Encode w1. */
8913-
dilithium_vec_encode_w1(w1, params->k, params->gamma2, w1e);
8914-
/* Step 15: Hash mu and encoded w1.
8915-
* Step 32: Hash is stored in signature. */
8916-
ret = dilithium_hash256(&key->shake, mu, DILITHIUM_MU_SZ,
8917-
w1e, params->w1EncSz, commit, params->lambda / 4);
8913+
WC_ALLOC_VAR_EX(w1e, byte, DILITHIUM_MAX_W1_ENC_SZ,
8914+
key->heap, DYNAMIC_TYPE_DILITHIUM, ret=MEMORY_E);
8915+
if (WC_VAR_OK(w1e)) {
8916+
dilithium_vec_encode_w1(w1, params->k, params->gamma2,
8917+
w1e);
8918+
/* Step 15: Hash mu and encoded w1.
8919+
* Step 32: Hash is stored in signature. */
8920+
ret = dilithium_hash256(&key->shake, mu, DILITHIUM_MU_SZ,
8921+
w1e, params->w1EncSz, commit, params->lambda / 4);
8922+
}
8923+
WC_FREE_VAR_EX(w1e, key->heap, DYNAMIC_TYPE_DILITHIUM);
89188924
if (ret == 0) {
89198925
/* Step 17: Compute c from first 256 bits of commit. */
89208926
ret = dilithium_sample_in_ball_ex(params->level,

0 commit comments

Comments
 (0)