aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/pubkey/keypair
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/pubkey/keypair')
-rw-r--r--src/lib/pubkey/keypair/keypair.cpp19
-rw-r--r--src/lib/pubkey/keypair/keypair.h44
2 files changed, 51 insertions, 12 deletions
diff --git a/src/lib/pubkey/keypair/keypair.cpp b/src/lib/pubkey/keypair/keypair.cpp
index 2efd40b6e..5667bde4a 100644
--- a/src/lib/pubkey/keypair/keypair.cpp
+++ b/src/lib/pubkey/keypair/keypair.cpp
@@ -16,11 +16,12 @@ namespace KeyPair {
* Check an encryption key pair for consistency
*/
bool encryption_consistency_check(RandomNumberGenerator& rng,
- const Private_Key& key,
+ const Private_Key& private_key,
+ const Public_Key& public_key,
const std::string& padding)
{
- PK_Encryptor_EME encryptor(key, rng, padding);
- PK_Decryptor_EME decryptor(key, rng, padding);
+ PK_Encryptor_EME encryptor(public_key, rng, padding);
+ PK_Decryptor_EME decryptor(private_key, rng, padding);
/*
Weird corner case, if the key is too small to encrypt anything at
@@ -45,13 +46,15 @@ bool encryption_consistency_check(RandomNumberGenerator& rng,
* Check a signature key pair for consistency
*/
bool signature_consistency_check(RandomNumberGenerator& rng,
- const Private_Key& key,
+ const Private_Key& private_key,
+ const Public_Key& public_key,
const std::string& padding)
{
- PK_Signer signer(key, rng, padding);
- PK_Verifier verifier(key, padding);
+ PK_Signer signer(private_key, rng, padding);
+ PK_Verifier verifier(public_key, padding);
- std::vector<byte> message = unlock(rng.random_vec(16));
+ std::vector<byte> message(32);
+ rng.randomize(message.data(), message.size());
std::vector<byte> signature;
@@ -68,7 +71,7 @@ bool signature_consistency_check(RandomNumberGenerator& rng,
return false;
// Now try to check a corrupt signature, ensure it does not succeed
- ++message[0];
+ ++signature[0];
if(verifier.verify_message(message, signature))
return false;
diff --git a/src/lib/pubkey/keypair/keypair.h b/src/lib/pubkey/keypair/keypair.h
index 7fcde3216..894749583 100644
--- a/src/lib/pubkey/keypair/keypair.h
+++ b/src/lib/pubkey/keypair/keypair.h
@@ -18,28 +18,64 @@ namespace KeyPair {
* Tests whether the key is consistent for encryption; whether
* encrypting and then decrypting gives to the original plaintext.
* @param rng the rng to use
-* @param key the key to test
+* @param private_key the key to test
+* @param public_key the key to test
* @param padding the encryption padding method to use
* @return true if consistent otherwise false
*/
BOTAN_DLL bool
encryption_consistency_check(RandomNumberGenerator& rng,
- const Private_Key& key,
+ 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
* @param rng the rng to use
-* @param key the key to test
+* @param private_key the key to test
+* @param public_key the key to test
* @param padding the signature padding method to use
* @return true if consistent otherwise false
*/
BOTAN_DLL bool
signature_consistency_check(RandomNumberGenerator& rng,
- const Private_Key& key,
+ 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.
+* @param rng the rng to use
+* @param key the key to test
+* @param padding the encryption padding method to use
+* @return true if consistent otherwise false
+*/
+inline bool
+encryption_consistency_check(RandomNumberGenerator& rng,
+ const Private_Key& key,
+ const std::string& padding)
+ {
+ return encryption_consistency_check(rng, key, key, padding);
+ }
+
+/**
+* Tests whether the key is consistent for signatures; whether a
+* signature can be created and then verified
+* @param rng the rng to use
+* @param key the key to test
+* @param padding the signature padding method to use
+* @return true if consistent otherwise false
+*/
+inline bool
+signature_consistency_check(RandomNumberGenerator& rng,
+ const Private_Key& key,
+ const std::string& padding)
+ {
+ return signature_consistency_check(rng, key, key, padding);
+ }
+
}
}