From b8966d0f89e520cecf3e822241aef38ed9a6d876 Mon Sep 17 00:00:00 2001 From: Jack Lloyd Date: Sat, 19 Mar 2016 22:52:48 -0400 Subject: Clean up PK decryption encoding. Previously RSA and ElGamal stripped off leading zeros which were then assumed by the padding decoders. Instead have them produce ciphertexts with leading zeros. Changes EME_Raw to strip leading zeros to match existing behavior. --- src/tests/test_pubkey.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'src/tests/test_pubkey.cpp') diff --git a/src/tests/test_pubkey.cpp b/src/tests/test_pubkey.cpp index 025628636..4d795ae1d 100644 --- a/src/tests/test_pubkey.cpp +++ b/src/tests/test_pubkey.cpp @@ -37,7 +37,7 @@ void check_invalid_signatures(Test::Result& result, std::vector bad_sig = signature; - for(size_t i = 0; i <= Test::soak_level(); ++i) + for(size_t i = 0; i < Test::soak_level(); ++i) { while(bad_sig == signature) bad_sig = Test::mutate_vec(bad_sig, true); @@ -59,7 +59,7 @@ void check_invalid_ciphertexts(Test::Result& result, size_t ciphertext_accepted = 0, ciphertext_rejected = 0; - for(size_t i = 0; i <= Test::soak_level(); ++i) + for(size_t i = 0; i < Test::soak_level(); ++i) { while(bad_ctext == ciphertext) bad_ctext = Test::mutate_vec(bad_ctext, true); @@ -222,7 +222,8 @@ PK_Encryption_Decryption_Test::run_one_test(const std::string&, const VarMap& va if(enc_provider == "base") { - result.test_eq("generated ciphertext matches KAT", generated_ciphertext, ciphertext); + result.test_eq(enc_provider, "generated ciphertext matches KAT", + generated_ciphertext, ciphertext); } for(auto&& dec_provider : possible_pk_providers()) @@ -239,10 +240,14 @@ PK_Encryption_Decryption_Test::run_one_test(const std::string&, const VarMap& va continue; } - result.test_eq("decryption of KAT", decryptor->decrypt(ciphertext), plaintext); + result.test_eq(dec_provider, "decryption of KAT", decryptor->decrypt(ciphertext), plaintext); check_invalid_ciphertexts(result, *decryptor, plaintext, ciphertext); - result.test_eq("decryption of generated ciphertext", - decryptor->decrypt(generated_ciphertext), plaintext); + + if(generated_ciphertext != ciphertext) + { + result.test_eq(dec_provider, "decryption of generated ciphertext", + decryptor->decrypt(generated_ciphertext), plaintext); + } } } -- cgit v1.2.3