mirror of
https://github.com/henrydcase/pqc.git
synced 2024-11-30 03:11:43 +00:00
Merge branch 'randomciphertext' into newhope
This commit is contained in:
commit
de30a2bdcd
@ -176,20 +176,17 @@ static int test_invalid_ciphertext(void) {
|
|||||||
uint8_t pk[CRYPTO_PUBLICKEYBYTES];
|
uint8_t pk[CRYPTO_PUBLICKEYBYTES];
|
||||||
uint8_t sendb[CRYPTO_CIPHERTEXTBYTES];
|
uint8_t sendb[CRYPTO_CIPHERTEXTBYTES];
|
||||||
int i;
|
int i;
|
||||||
size_t pos;
|
|
||||||
int returncode;
|
int returncode;
|
||||||
|
|
||||||
for (i = 0; i < NTESTS; i++) {
|
for (i = 0; i < NTESTS; i++) {
|
||||||
randombytes((uint8_t *)&pos, sizeof(size_t));
|
|
||||||
|
|
||||||
// Alice generates a public key
|
// Alice generates a public key
|
||||||
RETURNS_ZERO(crypto_kem_keypair(pk, sk_a));
|
RETURNS_ZERO(crypto_kem_keypair(pk, sk_a));
|
||||||
|
|
||||||
// Bob derives a secret key and creates a response
|
// Bob derives a secret key and creates a response
|
||||||
RETURNS_ZERO(crypto_kem_enc(sendb, key_b, pk));
|
RETURNS_ZERO(crypto_kem_enc(sendb, key_b, pk));
|
||||||
|
|
||||||
// Change some byte in the ciphertext (i.e., encapsulated key)
|
// Change ciphertext to random value
|
||||||
sendb[pos % CRYPTO_CIPHERTEXTBYTES] ^= 23;
|
randombytes(sendb, sizeof(sendb));
|
||||||
|
|
||||||
// Alice uses Bobs response to get her secret key
|
// Alice uses Bobs response to get her secret key
|
||||||
if ((returncode = crypto_kem_dec(key_a, sendb, sk_a)) > 0) {
|
if ((returncode = crypto_kem_dec(key_a, sendb, sk_a)) > 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user