Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- Namespace List
- Namespace Members

Functions
Botan::KeyPair Namespace Reference

## Functions
bool | encryption_consistency_check (RandomNumberGenerator &rng, const Private_Key &private_key, const Public_Key &public_key, const std::string &padding)
bool | encryption_consistency_check (RandomNumberGenerator &rng, const Private_Key &key, const std::string &padding)
bool | signature_consistency_check (RandomNumberGenerator &rng, const Private_Key &private_key, const Public_Key &public_key, const std::string &padding)
bool | signature_consistency_check (RandomNumberGenerator &rng, const Private_Key &key, const std::string &padding)

## Function Documentation

BOTAN_DLL bool Botan::KeyPair::encryption_consistency_check | ( | RandomNumberGenerator & | rng,
|  | const Private_Key & | private_key,
|  | const Public_Key & | public_key,
|  | const std::string & | padding
| ) |  |

Tests whether the key is consistent for encryption; whether encrypting and then decrypting gives to the original plaintext.

Parameters

  rng | the rng to use
  private_key | the key to test
  public_key | the key to test
  padding | the encryption padding method to use

Returns
  true if consistent otherwise false

Definition at line 18 of file keypair.cpp.

References Botan::PK_Decryptor::decrypt(), Botan::PK_Encryptor::encrypt(), Botan::PK_Encryptor_EME::maximum_input_size(), Botan::RandomNumberGenerator::random_vec(), and Botan::unlock().

Referenced by Botan::ElGamal_PrivateKey::check_key(), and encryption_consistency_check().

22 {
23 PK_Encryptor_EME encryptor(public_key, rng, padding);
24 PK_Decryptor_EME decryptor(private_key, rng, padding);
25
26 /*
27 Weird corner case, if the key is too small to encrypt anything at
28 all. This can happen with very small RSA keys with PSS
29 */
30 if(encryptor.maximum_input_size() == 0)
31 return true;
32
33 std::vector<uint8_t> plaintext =
34 unlock(rng.random_vec(encryptor.maximum_input_size() - 1));
35
36 std::vector<uint8_t> ciphertext = encryptor.encrypt(plaintext, rng);
37 if(ciphertext == plaintext)
38 return false;
39
40 std::vector<uint8_t> decrypted = unlock(decryptor.decrypt(ciphertext));
41
42 return (plaintext == decrypted);
43 }
Botan::unlock
std::vector< T > unlock(const secure_vector< T > &in)
Definition: secmem.h:125

bool Botan::KeyPair::encryption_consistency_check | ( | RandomNumberGenerator & | rng,
|  | const Private_Key & | key,
|  | const std::string & | padding
| ) |  |
| inline

Tests whether the key is consistent for encryption; whether encrypting and then decrypting gives to the original plaintext.

Parameters

  rng | the rng to use
  key | the key to test
  padding | the encryption padding method to use

Returns
  true if consistent otherwise false

Definition at line 56 of file keypair.h.

References encryption_consistency_check().

59 {
60 return encryption_consistency_check(rng, key, key, padding);
61 }
Botan::KeyPair::encryption_consistency_check
bool encryption_consistency_check(RandomNumberGenerator &rng, const Private_Key &key, const std::string &padding)
Definition: keypair.h:56

BOTAN_DLL bool Botan::KeyPair::signature_consistency_check | ( | RandomNumberGenerator & | rng,
|  | const Private_Key & | private_key,
|  | const Public_Key & | public_key,
|  | const std::string & | padding
| ) |  |

Tests whether the key is consistent for signatures; whether a signature can be created and then verified

Parameters

  rng | the rng to use
  private_key | the key to test
  public_key | the key to test
  padding | the signature padding method to use

Returns
  true if consistent otherwise false

Definition at line 48 of file keypair.cpp.

References Botan::RandomNumberGenerator::randomize(), Botan::PK_Signer::sign_message(), and Botan::PK_Verifier::verify_message().

Referenced by Botan::DSA_PrivateKey::check_key(), Botan::ECKCDSA_PrivateKey::check_key(), Botan::ECGDSA_PrivateKey::check_key(), Botan::ECDSA_PrivateKey::check_key(), Botan::RSA_PrivateKey::check_key(), and signature_consistency_check().

52 {
53 PK_Signer signer(private_key, rng, padding);
54 PK_Verifier verifier(public_key, padding);
55
56 std::vector<uint8_t> message(32);
57 rng.randomize(message.data(), message.size());
58
59 std::vector<uint8_t> signature;
60
61 try
62 {
63 signature = signer.sign_message(message, rng);
64 }
65 catch(Encoding_Error&)
66 {
67 return false;
68 }
69
70 if(!verifier.verify_message(message, signature))
71 return false;
72
73 // Now try to check a corrupt signature, ensure it does not succeed
74 ++signature[0];
75
76 if(verifier.verify_message(message, signature))
77 return false;
78
79 return true;
80 }

bool Botan::KeyPair::signature_consistency_check | ( | RandomNumberGenerator & | rng,
|  | const Private_Key & | key,
|  | const std::string & | padding
| ) |  |
| inline

Tests whether the key is consistent for signatures; whether a signature can be created and then verified

Parameters

  rng | the rng to use
  key | the key to test
  padding | the signature padding method to use

Returns
  true if consistent otherwise false

Definition at line 72 of file keypair.h.

References signature_consistency_check().

75 {
76 return signature_consistency_check(rng, key, key, padding);
77 }
Botan::KeyPair::signature_consistency_check
bool signature_consistency_check(RandomNumberGenerator &rng, const Private_Key &key, const std::string &padding)
Definition: keypair.h:72