aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/pubkey/keypair
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2016-11-04 10:51:30 -0400
committerJack Lloyd <[email protected]>2016-11-04 10:51:30 -0400
commit19ac22af33d8e185d30e6c84299b8b86d7b0fa3f (patch)
treef1721fbf17621315544f9f85360c24c7bd515650 /src/lib/pubkey/keypair
parent0b820c330a62aaa3a715b7b7d00276f886cd4a0f (diff)
Fix PKCS11 test error
Previously PKCS11_ECDSA_PrivateKey::check_key failed because no verification is possible using this key type (does not derive from public key). Split keypair consistency to allow two key arguments. ECDSA keypair consistency disabled in the tests still, because SoftHSMv2 gives mechanism invalid errors. I think this is a SoftHSMv2 issue with the signature mechanism. Remove no longer used Key_Type typedefs (need to be removed everywhere). GH #712
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);
+ }
+
}
}