|
Botan
1.11.15
|
Functions | |
| bool | encryption_consistency_check (RandomNumberGenerator &rng, const Private_Key &key, const std::string &padding) |
| bool | signature_consistency_check (RandomNumberGenerator &rng, const Private_Key &key, const std::string &padding) |
| BOTAN_DLL bool Botan::KeyPair::encryption_consistency_check | ( | RandomNumberGenerator & | rng, |
| const Private_Key & | key, | ||
| const std::string & | padding | ||
| ) |
Tests whether the key is consistent for encryption; whether encrypting and then decrypting gives to the original plaintext.
| rng | the rng to use |
| key | the key to test |
| padding | the encryption padding method to use |
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().
{
PK_Encryptor_EME encryptor(key, padding);
PK_Decryptor_EME decryptor(key, padding);
/*
Weird corner case, if the key is too small to encrypt anything at
all. This can happen with very small RSA keys with PSS
*/
if(encryptor.maximum_input_size() == 0)
return true;
std::vector<byte> plaintext =
unlock(rng.random_vec(encryptor.maximum_input_size() - 1));
std::vector<byte> ciphertext = encryptor.encrypt(plaintext, rng);
if(ciphertext == plaintext)
return false;
std::vector<byte> decrypted = unlock(decryptor.decrypt(ciphertext));
return (plaintext == decrypted);
}
| BOTAN_DLL bool Botan::KeyPair::signature_consistency_check | ( | RandomNumberGenerator & | rng, |
| const Private_Key & | key, | ||
| const std::string & | padding | ||
| ) |
Tests whether the key is consistent for signatures; whether a signature can be created and then verified
| rng | the rng to use |
| key | the key to test |
| padding | the signature padding method to use |
Definition at line 47 of file keypair.cpp.
References Botan::RandomNumberGenerator::random_vec(), Botan::PK_Signer::sign_message(), Botan::unlock(), and Botan::PK_Verifier::verify_message().
Referenced by Botan::NR_PrivateKey::check_key(), Botan::RSA_PrivateKey::check_key(), Botan::DSA_PrivateKey::check_key(), Botan::RW_PrivateKey::check_key(), and Botan::ECDSA_PrivateKey::check_key().
{
PK_Signer signer(key, padding);
PK_Verifier verifier(key, padding);
std::vector<byte> message = unlock(rng.random_vec(16));
std::vector<byte> signature;
try
{
signature = signer.sign_message(message, rng);
}
catch(Encoding_Error)
{
return false;
}
if(!verifier.verify_message(message, signature))
return false;
// Now try to check a corrupt signature, ensure it does not succeed
++message[0];
if(verifier.verify_message(message, signature))
return false;
return true;
}
1.7.6.1