monotone

monotone Mtn Source Tree

Root/botan/keypair.cpp

1/*************************************************
2* Keypair Checks Source File *
3* (C) 1999-2005 The Botan Project *
4*************************************************/
5
6#include <botan/keypair.h>
7#include <botan/look_pk.h>
8#include <botan/rng.h>
9#include <memory>
10
11namespace Botan {
12
13namespace KeyPair {
14
15/*************************************************
16* Check an encryption key pair for consistency *
17*************************************************/
18void check_key(PK_Encryptor* encryptor, PK_Decryptor* decryptor)
19 {
20 std::auto_ptr<PK_Encryptor> enc(encryptor);
21 std::auto_ptr<PK_Decryptor> dec(decryptor);
22
23 SecureVector<byte> message(enc->maximum_input_size() - 1);
24 Global_RNG::randomize(message, message.size(), Nonce);
25
26 SecureVector<byte> ciphertext = enc->encrypt(message);
27 if(ciphertext == message)
28 throw Self_Test_Failure("Encryption key pair consistency failure");
29
30 SecureVector<byte> message2 = dec->decrypt(ciphertext);
31 if(message != message2)
32 throw Self_Test_Failure("Encryption key pair consistency failure");
33 }
34
35/*************************************************
36* Check a signature key pair for consistency *
37*************************************************/
38void check_key(PK_Signer* signer, PK_Verifier* verifier)
39 {
40 std::auto_ptr<PK_Signer> sig(signer);
41 std::auto_ptr<PK_Verifier> ver(verifier);
42
43 SecureVector<byte> message(16);
44 Global_RNG::randomize(message, message.size(), Nonce);
45
46 SecureVector<byte> signature = sig->sign_message(message);
47
48 if(!ver->verify_message(message, signature))
49 throw Self_Test_Failure("Signature key pair consistency failure");
50
51 message[0]++;
52 if(ver->verify_message(message, signature))
53 throw Self_Test_Failure("Signature key pair consistency failure");
54 }
55
56}
57
58}

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status