Skip to content

Commit 064cfe2

Browse files
committed
Make ML-DSA signing w1e variable aware of SMALL_STACK
1 parent b562d5c commit 064cfe2

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

wolfcrypt/src/dilithium.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8675,7 +8675,7 @@ static int dilithium_sign_with_seed_mu(dilithium_key* key,
86758675
/* Step 11: Start rejection sampling loop */
86768676
do {
86778677
byte aseed[DILITHIUM_GEN_A_SEED_SZ];
8678-
byte w1e[DILITHIUM_MAX_W1_ENC_SZ];
8678+
WC_DECLARE_VAR(w1e, byte, DILITHIUM_MAX_W1_ENC_SZ, 0);
86798679
sword32* w = w1;
86808680
byte* commit = sig;
86818681
byte r;
@@ -8906,11 +8906,17 @@ static int dilithium_sign_with_seed_mu(dilithium_key* key,
89068906
byte* ze = sig + params->lambda / 4;
89078907

89088908
/* Step 15: Encode w1. */
8909-
dilithium_vec_encode_w1(w1, params->k, params->gamma2, w1e);
8910-
/* Step 15: Hash mu and encoded w1.
8911-
* Step 32: Hash is stored in signature. */
8912-
ret = dilithium_hash256(&key->shake, mu, DILITHIUM_MU_SZ,
8913-
w1e, params->w1EncSz, commit, params->lambda / 4);
8909+
WC_ALLOC_VAR_EX(w1e, byte, DILITHIUM_MAX_W1_ENC_SZ,
8910+
key->heap, DYNAMIC_TYPE_DILITHIUM, ret=MEMORY_E);
8911+
if (WC_VAR_OK(w1e)) {
8912+
dilithium_vec_encode_w1(w1, params->k, params->gamma2,
8913+
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);
8918+
}
8919+
WC_FREE_VAR_EX(w1e, key->heap, DYNAMIC_TYPE_DILITHIUM);
89148920
if (ret == 0) {
89158921
/* Step 17: Compute c from first 256 bits of commit. */
89168922
ret = dilithium_sample_in_ball_ex(params->level,

0 commit comments

Comments
 (0)