"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "testsuite/rsa-sec-decrypt-test.c" between
nettle-3.7.2.tar.gz and nettle-3.7.3.tar.gz

About: Nettle is a low-level cryptographic library.

rsa-sec-decrypt-test.c  (nettle-3.7.2):rsa-sec-decrypt-test.c  (nettle-3.7.3)
skipping to change at line 58 skipping to change at line 58
MARK_MPZ_LIMBS_DEFINED(key->p); MARK_MPZ_LIMBS_DEFINED(key->p);
MARK_MPZ_LIMBS_DEFINED(key->q); MARK_MPZ_LIMBS_DEFINED(key->q);
return ret; return ret;
} }
#else #else
#define rsa_decrypt_for_test rsa_sec_decrypt #define rsa_decrypt_for_test rsa_sec_decrypt
#endif #endif
#define PAYLOAD_SIZE 50 #define PAYLOAD_SIZE 50
#define DECRYPTED_SIZE 256
void void
test_main(void) test_main(void)
{ {
struct rsa_public_key pub; struct rsa_public_key pub;
struct rsa_private_key key; struct rsa_private_key key;
struct knuth_lfib_ctx random_ctx; struct knuth_lfib_ctx random_ctx;
uint8_t plaintext[PAYLOAD_SIZE]; uint8_t plaintext[PAYLOAD_SIZE];
uint8_t decrypted[PAYLOAD_SIZE]; uint8_t decrypted[DECRYPTED_SIZE];
uint8_t verifybad[PAYLOAD_SIZE]; uint8_t verifybad[PAYLOAD_SIZE];
unsigned n_size = 1024; unsigned n_size = 1024;
mpz_t gibberish; mpz_t gibberish;
mpz_t garbage; mpz_t garbage;
size_t size; size_t size;
rsa_private_key_init(&key); rsa_private_key_init(&key);
rsa_public_key_init(&pub); rsa_public_key_init(&pub);
mpz_init(gibberish); mpz_init(gibberish);
mpz_init(garbage); mpz_init(garbage);
skipping to change at line 102 skipping to change at line 103
ASSERT(rsa_encrypt(&pub, &random_ctx, ASSERT(rsa_encrypt(&pub, &random_ctx,
(nettle_random_func *) knuth_lfib_random, (nettle_random_func *) knuth_lfib_random,
PAYLOAD_SIZE, plaintext, gibberish)); PAYLOAD_SIZE, plaintext, gibberish));
/* good decryption */ /* good decryption */
ASSERT (rsa_decrypt_for_test (&pub, &key, &random_ctx, ASSERT (rsa_decrypt_for_test (&pub, &key, &random_ctx,
(nettle_random_func *) knuth_lfib_random, (nettle_random_func *) knuth_lfib_random,
PAYLOAD_SIZE, decrypted, gibberish) == 1); PAYLOAD_SIZE, decrypted, gibberish) == 1);
ASSERT (MEMEQ (PAYLOAD_SIZE, plaintext, decrypted)); 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 */ /* bad one */
memcpy(decrypted, verifybad, PAYLOAD_SIZE); memcpy(decrypted, verifybad, PAYLOAD_SIZE);
nettle_mpz_random_size(garbage, &random_ctx, nettle_mpz_random_size(garbage, &random_ctx,
(nettle_random_func *) knuth_lfib_random, (nettle_random_func *) knuth_lfib_random,
mpz_sizeinbase(gibberish, 2)); mpz_sizeinbase(gibberish, 2));
ASSERT (rsa_decrypt_for_test (&pub, &key, &random_ctx, ASSERT (rsa_decrypt_for_test (&pub, &key, &random_ctx,
(nettle_random_func *) knuth_lfib_random, (nettle_random_func *) knuth_lfib_random,
PAYLOAD_SIZE, decrypted, garbage) == 0); PAYLOAD_SIZE, decrypted, garbage) == 0);
ASSERT (MEMEQ (PAYLOAD_SIZE, verifybad, decrypted)); ASSERT (MEMEQ (PAYLOAD_SIZE, verifybad, decrypted));
 End of changes. 3 change blocks. 
1 lines changed or deleted 16 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)