+2021-05-06 Niels Möller <nisse@lysator.liu.se>
+
+ Bug fixes merged from from 3.7.3 release (starting from 2021-05-06).
+ * pkcs1-sec-decrypt.c (_pkcs1_sec_decrypt): Check that message
+ length is valid, for given key size.
+ * testsuite/rsa-sec-decrypt-test.c (test_main): Add test cases for
+ calls to rsa_sec_decrypt specifying a too large message length.
+
2021-05-23 Niels Möller <nisse@lysator.liu.se>
From Nicolas Mora: Implement aes key wrap and key unwrap (RFC 3394).
#endif
#define PAYLOAD_SIZE 50
+#define DECRYPTED_SIZE 256
void
test_main(void)
{
struct knuth_lfib_ctx random_ctx;
uint8_t plaintext[PAYLOAD_SIZE];
- uint8_t decrypted[PAYLOAD_SIZE];
+ uint8_t decrypted[DECRYPTED_SIZE];
uint8_t verifybad[PAYLOAD_SIZE];
unsigned n_size = 1024;
mpz_t gibberish;
PAYLOAD_SIZE, decrypted, gibberish) == 1);
ASSERT (MEMEQ (PAYLOAD_SIZE, plaintext, decrypted));
+ ASSERT (pub.size > 10);
+ ASSERT (pub.size <= DECRYPTED_SIZE);
+
+ /* Check that too large message length is rejected, largest
+ valid size is pub.size - 11. */
+ ASSERT (!rsa_decrypt_for_test (&pub, &key, &random_ctx,
+ (nettle_random_func *) knuth_lfib_random,
+ pub.size - 10, decrypted, gibberish));
+
+ /* This case used to result in arithmetic underflow and a crash. */
+ ASSERT (!rsa_decrypt_for_test (&pub, &key, &random_ctx,
+ (nettle_random_func *) knuth_lfib_random,
+ pub.size, decrypted, gibberish));
+
/* bad one */
memcpy(decrypted, verifybad, PAYLOAD_SIZE);
nettle_mpz_random_size(garbage, &random_ctx,