diff options
author | lloyd <[email protected]> | 2008-10-01 14:36:27 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2008-10-01 14:36:27 +0000 |
commit | 06e35ed5375028f246f57b99ccf639e8ed317b35 (patch) | |
tree | 32021a79d1617a147f7fa7ac29c1eae60f9024ce /src/pubkey/keypair | |
parent | 9320b5e5c1b64894a6ff8797f392b57dfd72dea3 (diff) |
Rename pk dir to pubkey, avoids tab-completion collision with pk_pad
Diffstat (limited to 'src/pubkey/keypair')
-rw-r--r-- | src/pubkey/keypair/info.txt | 14 | ||||
-rw-r--r-- | src/pubkey/keypair/keypair.cpp | 71 | ||||
-rw-r--r-- | src/pubkey/keypair/keypair.h | 25 |
3 files changed, 110 insertions, 0 deletions
diff --git a/src/pubkey/keypair/info.txt b/src/pubkey/keypair/info.txt new file mode 100644 index 000000000..c6fa4af5d --- /dev/null +++ b/src/pubkey/keypair/info.txt @@ -0,0 +1,14 @@ +realname "Keypair Testing" + +define KEYPAIR_TESTING + +load_on auto + +<add> +keypair.cpp +keypair.h +</add> + +<requires> +pubkey +</requires> diff --git a/src/pubkey/keypair/keypair.cpp b/src/pubkey/keypair/keypair.cpp new file mode 100644 index 000000000..940f0c028 --- /dev/null +++ b/src/pubkey/keypair/keypair.cpp @@ -0,0 +1,71 @@ +/************************************************* +* Keypair Checks Source File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#include <botan/keypair.h> +#include <botan/look_pk.h> +#include <memory> + +namespace Botan { + +namespace KeyPair { + +/************************************************* +* Check an encryption key pair for consistency * +*************************************************/ +void check_key(RandomNumberGenerator& rng, + PK_Encryptor* encryptor, PK_Decryptor* decryptor) + { + if(encryptor->maximum_input_size() == 0) + return; + + std::auto_ptr<PK_Encryptor> enc(encryptor); + std::auto_ptr<PK_Decryptor> dec(decryptor); + + SecureVector<byte> message(enc->maximum_input_size() - 1); + rng.randomize(message, message.size()); + + SecureVector<byte> ciphertext = enc->encrypt(message, rng); + 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(RandomNumberGenerator& rng, + PK_Signer* signer, PK_Verifier* verifier) + { + std::auto_ptr<PK_Signer> sig(signer); + std::auto_ptr<PK_Verifier> ver(verifier); + + SecureVector<byte> message(16); + rng.randomize(message, message.size()); + + SecureVector<byte> signature; + + try + { + signature = sig->sign_message(message, rng); + } + catch(Encoding_Error) + { + return; + } + + 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"); + } + +} + +} diff --git a/src/pubkey/keypair/keypair.h b/src/pubkey/keypair/keypair.h new file mode 100644 index 000000000..da322c075 --- /dev/null +++ b/src/pubkey/keypair/keypair.h @@ -0,0 +1,25 @@ +/************************************************* +* Keypair Checks Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_KEYPAIR_H__ +#define BOTAN_KEYPAIR_H__ + +#include <botan/look_pk.h> + +namespace Botan { + +namespace KeyPair { + +/************************************************* +* Check key pair consistency * +*************************************************/ +BOTAN_DLL void check_key(RandomNumberGenerator&, PK_Encryptor*, PK_Decryptor*); +BOTAN_DLL void check_key(RandomNumberGenerator&, PK_Signer*, PK_Verifier*); + +} + +} + +#endif |