"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "testsuite/rsa-encrypt-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-encrypt-test.c  (nettle-3.7.2):rsa-encrypt-test.c  (nettle-3.7.3)
skipping to change at line 22 skipping to change at line 22
/* FIXME: How is this spelled? */ /* FIXME: How is this spelled? */
const unsigned char msg[] = "Squemish ossifrage"; const unsigned char msg[] = "Squemish ossifrage";
size_t msg_length = LLENGTH(msg); size_t msg_length = LLENGTH(msg);
uint8_t *decrypted; uint8_t *decrypted;
size_t decrypted_length; size_t decrypted_length;
uint8_t after; uint8_t after;
mpz_t gibberish; mpz_t gibberish;
mpz_t bad_input;
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(bad_input);
knuth_lfib_init(&lfib, 17); knuth_lfib_init(&lfib, 17);
test_rsa_set_key_1(&pub, &key); test_rsa_set_key_1(&pub, &key);
if (verbose) if (verbose)
fprintf(stderr, "msg: `%s', length = %d\n", msg, (int) msg_length); fprintf(stderr, "msg: `%s', length = %d\n", msg, (int) msg_length);
ASSERT(msg_length <= key.size); ASSERT(msg_length <= key.size);
skipping to change at line 104 skipping to change at line 106
decrypted_length = msg_length - 1; decrypted_length = msg_length - 1;
after = decrypted[decrypted_length] = 'X'; after = decrypted[decrypted_length] = 'X';
decrypted[0] = 'A'; decrypted[0] = 'A';
ASSERT(!rsa_sec_decrypt(&pub, &key, ASSERT(!rsa_sec_decrypt(&pub, &key,
&lfib, (nettle_random_func *) knuth_lfib_random, &lfib, (nettle_random_func *) knuth_lfib_random,
decrypted_length, decrypted, gibberish)); decrypted_length, decrypted, gibberish));
ASSERT(decrypted[decrypted_length] == after); ASSERT(decrypted[decrypted_length] == after);
ASSERT(decrypted[0] == 'A'); ASSERT(decrypted[0] == 'A');
/* Test zero input. */
mpz_set_ui (bad_input, 0);
decrypted_length = msg_length;
ASSERT(!rsa_decrypt(&key, &decrypted_length, decrypted, bad_input));
ASSERT(!rsa_decrypt_tr(&pub, &key,
&lfib, (nettle_random_func *) knuth_lfib_random,
&decrypted_length, decrypted, bad_input));
ASSERT(!rsa_sec_decrypt(&pub, &key,
&lfib, (nettle_random_func *) knuth_lfib_random,
decrypted_length, decrypted, bad_input));
ASSERT(decrypted_length == msg_length);
/* Test input that is slightly larger than n */
mpz_add(bad_input, gibberish, pub.n);
decrypted_length = msg_length;
ASSERT(!rsa_decrypt(&key, &decrypted_length, decrypted, bad_input));
ASSERT(!rsa_decrypt_tr(&pub, &key,
&lfib, (nettle_random_func *) knuth_lfib_random,
&decrypted_length, decrypted, bad_input));
ASSERT(!rsa_sec_decrypt(&pub, &key,
&lfib, (nettle_random_func *) knuth_lfib_random,
decrypted_length, decrypted, bad_input));
ASSERT(decrypted_length == msg_length);
/* Test input that is considerably larger than n */
mpz_mul_2exp (bad_input, pub.n, 100);
mpz_add (bad_input, bad_input, gibberish);
decrypted_length = msg_length;
ASSERT(!rsa_decrypt(&key, &decrypted_length, decrypted, bad_input));
ASSERT(!rsa_decrypt_tr(&pub, &key,
&lfib, (nettle_random_func *) knuth_lfib_random,
&decrypted_length, decrypted, bad_input));
ASSERT(!rsa_sec_decrypt(&pub, &key,
&lfib, (nettle_random_func *) knuth_lfib_random,
decrypted_length, decrypted, bad_input));
ASSERT(decrypted_length == msg_length);
/* Test invalid key. */ /* Test invalid key. */
mpz_add_ui (key.q, key.q, 2); mpz_add_ui (key.q, key.q, 2);
decrypted_length = key.size; decrypted_length = key.size;
ASSERT(!rsa_decrypt_tr(&pub, &key, ASSERT(!rsa_decrypt_tr(&pub, &key,
&lfib, (nettle_random_func *) knuth_lfib_random, &lfib, (nettle_random_func *) knuth_lfib_random,
&decrypted_length, decrypted, gibberish)); &decrypted_length, decrypted, gibberish));
rsa_private_key_clear(&key); rsa_private_key_clear(&key);
rsa_public_key_clear(&pub); rsa_public_key_clear(&pub);
mpz_clear(gibberish); mpz_clear(gibberish);
mpz_clear(bad_input);
free(decrypted); free(decrypted);
} }
 End of changes. 4 change blocks. 
0 lines changed or deleted 40 lines changed or added

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