Skip to content

Commit a81efc0

Browse files
committed
Small Stack ECC Pairwise Consistency Test
1. Update the ECC PCT to use the key's heap to allocate any buffers for the test. This is similar to how RSA does it. 2. Put the buffers on the stack if not using small stack option.
1 parent b990840 commit a81efc0

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

wolfcrypt/src/ecc.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10211,23 +10211,31 @@ static int _ecc_pairwise_consistency_test(ecc_key* key, WC_RNG* rng)
1021110211
}
1021210212

1021310213
if (!err && (flags & WC_ECC_FLAG_DEC_SIGN)) {
10214+
#ifndef WOLFSSL_SMALL_STACK
10215+
byte sig[MAX_ECC_BYTES + WC_SHA256_DIGEST_SIZE];
10216+
#else
1021410217
byte* sig;
10218+
#endif
1021510219
byte* digest;
1021610220
word32 sigLen, digestLen;
1021710221
int dynRng = 0, res = 0;
1021810222

1021910223
sigLen = (word32)wc_ecc_sig_size(key);
1022010224
digestLen = WC_SHA256_DIGEST_SIZE;
10221-
sig = (byte*)XMALLOC(sigLen + digestLen, NULL, DYNAMIC_TYPE_ECC);
10225+
#ifdef WOLFSSL_SMALL_STACK
10226+
sig = (byte*)XMALLOC(sigLen + digestLen, key->heap, DYNAMIC_TYPE_ECC);
1022210227
if (sig == NULL)
1022310228
return MEMORY_E;
10229+
#endif
1022410230
digest = sig + sigLen;
1022510231

1022610232
if (rng == NULL) {
1022710233
dynRng = 1;
10228-
rng = wc_rng_new(NULL, 0, NULL);
10234+
rng = wc_rng_new(NULL, 0, key->heap);
1022910235
if (rng == NULL) {
10230-
XFREE(sig, NULL, DYNAMIC_TYPE_ECC);
10236+
#ifdef WOLFSSL_SMALL_STACK
10237+
XFREE(sig, key->heap, DYNAMIC_TYPE_ECC);
10238+
#endif
1023110239
return MEMORY_E;
1023210240
}
1023310241
}
@@ -10248,7 +10256,9 @@ static int _ecc_pairwise_consistency_test(ecc_key* key, WC_RNG* rng)
1024810256
wc_rng_free(rng);
1024910257
}
1025010258
ForceZero(sig, sigLen + digestLen);
10251-
XFREE(sig, NULL, DYNAMIC_TYPE_ECC);
10259+
#ifdef WOLFSSL_SMALL_STACK
10260+
XFREE(sig, key->heap, DYNAMIC_TYPE_ECC);
10261+
#endif
1025210262
}
1025310263
(void)rng;
1025410264

0 commit comments

Comments
 (0)