Skip to content

Commit df6d27c

Browse files
andrea-caforioandreaskurth
authored andcommitted
[kat/rsa] Prevent stack smashing when copying RSA signature
Some tests provide overly large signatures (larger than the byte size of the modulus). The associated array should have the proper size in order to avoid writing beyond it during the copy. Signed-off-by: Andrea Caforio <[email protected]>
1 parent 78007c4 commit df6d27c

File tree

1 file changed

+2
-2
lines changed
  • sw/device/tests/crypto/cryptotest/firmware

1 file changed

+2
-2
lines changed

sw/device/tests/crypto/cryptotest/firmware/rsa.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,9 +466,9 @@ status_t handle_rsa_verify(ujson_t *uj) {
466466
TRY(otcrypto_rsa_public_key_construct(rsa_size, modulus, &public_key));
467467

468468
// Create the signature buffer.
469-
uint32_t sig_buf[rsa_num_words];
469+
uint32_t sig_buf[uj_input.sig_len >> 2];
470470
memset(sig_buf, 0, sizeof(sig_buf));
471-
memcpy(sig_buf, uj_input.sig, uj_input.sig_len);
471+
memcpy(sig_buf, uj_input.sig, sizeof(sig_buf));
472472

473473
otcrypto_const_word32_buf_t sig = {
474474
.data = sig_buf,

0 commit comments

Comments
 (0)