Skip to content

Commit 44a0b23

Browse files
andrea-caforioandreaskurth
authored andcommitted
[kat/rsa] Prevent stack smashing when copying RSA ciphertext
Some tests provide overly large ciphertexts (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 c8325aa commit 44a0b23

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
@@ -314,9 +314,9 @@ status_t handle_rsa_decrypt(ujson_t *uj) {
314314
TRY(otcrypto_rsa_private_key_from_exponents(rsa_size, modulus, d_share0,
315315
d_share1, &private_key));
316316

317-
uint32_t ciphertext_buf[rsa_num_words];
317+
uint32_t ciphertext_buf[uj_input.ciphertext_len >> 2];
318318
memset(ciphertext_buf, 0, sizeof(ciphertext_buf));
319-
memcpy(ciphertext_buf, uj_input.ciphertext, uj_input.ciphertext_len);
319+
memcpy(ciphertext_buf, uj_input.ciphertext, sizeof(ciphertext_buf));
320320

321321
otcrypto_const_word32_buf_t ciphertext = {
322322
.len = rsa_num_words,

0 commit comments

Comments
 (0)