Added invalid ciphertext test in test_kem, and replaced invalid signature with random array vs modified first byte (code from PR787).

This commit is contained in:
Christian Paquin 2020-07-13 11:57:36 -04:00
parent e5f33fea7a
commit 0cba778097
2 changed files with 9 additions and 1 deletions

View File

@ -113,6 +113,14 @@ static OQS_STATUS kem_test_correctness(const char *method_name) {
goto err;
}
// test invalid encapsulation (call should either fail or result in invalid shared secret)
OQS_randombytes(ciphertext, kem->length_ciphertext);
rc = OQS_KEM_decaps(kem, shared_secret_d, ciphertext, secret_key);
if (rc == OQS_SUCCESS && memcmp(shared_secret_e, shared_secret_d, kem->length_shared_secret) == 0) {
fprintf(stderr, "ERROR: OQS_KEM_decaps succeeded on wrong input\n");
goto err;
}
ret = OQS_SUCCESS;
goto cleanup;

View File

@ -68,7 +68,7 @@ static OQS_STATUS sig_test_correctness(const char *method_name) {
}
/* modify the signature to invalidate it */
signature[0]++;
OQS_randombytes(signature, signature_len);
rc = OQS_SIG_verify(sig, message, message_len, signature, signature_len, public_key);
if (rc != OQS_ERROR) {
fprintf(stderr, "ERROR: OQS_SIG_verify should have failed!\n");