aboutsummaryrefslogtreecommitdiffstats
path: root/src/keypair.cpp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2006-05-18 18:33:19 +0000
committerlloyd <[email protected]>2006-05-18 18:33:19 +0000
commita2c99d3270eb73ef2db5704fc54356c6b75096f8 (patch)
treead3d6c4fcc8dd0f403f8105598943616246fe172 /src/keypair.cpp
Initial checkin1.5.6
Diffstat (limited to 'src/keypair.cpp')
-rw-r--r--src/keypair.cpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/keypair.cpp b/src/keypair.cpp
new file mode 100644
index 000000000..11ddbd811
--- /dev/null
+++ b/src/keypair.cpp
@@ -0,0 +1,58 @@
+/*************************************************
+* Keypair Checks Source File *
+* (C) 1999-2006 The Botan Project *
+*************************************************/
+
+#include <botan/keypair.h>
+#include <botan/look_pk.h>
+#include <botan/rng.h>
+#include <memory>
+
+namespace Botan {
+
+namespace KeyPair {
+
+/*************************************************
+* Check an encryption key pair for consistency *
+*************************************************/
+void check_key(PK_Encryptor* encryptor, PK_Decryptor* decryptor)
+ {
+ std::auto_ptr<PK_Encryptor> enc(encryptor);
+ std::auto_ptr<PK_Decryptor> dec(decryptor);
+
+ SecureVector<byte> message(enc->maximum_input_size() - 1);
+ Global_RNG::randomize(message, message.size());
+
+ SecureVector<byte> ciphertext = enc->encrypt(message);
+ if(ciphertext == message)
+ throw Self_Test_Failure("Encryption key pair consistency failure");
+
+ SecureVector<byte> message2 = dec->decrypt(ciphertext);
+ if(message != message2)
+ throw Self_Test_Failure("Encryption key pair consistency failure");
+ }
+
+/*************************************************
+* Check a signature key pair for consistency *
+*************************************************/
+void check_key(PK_Signer* signer, PK_Verifier* verifier)
+ {
+ std::auto_ptr<PK_Signer> sig(signer);
+ std::auto_ptr<PK_Verifier> ver(verifier);
+
+ SecureVector<byte> message(16);
+ Global_RNG::randomize(message, message.size());
+
+ SecureVector<byte> signature = sig->sign_message(message);
+
+ if(!ver->verify_message(message, signature))
+ throw Self_Test_Failure("Signature key pair consistency failure");
+
+ ++message[0];
+ if(ver->verify_message(message, signature))
+ throw Self_Test_Failure("Signature key pair consistency failure");
+ }
+
+}
+
+}