aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/pubkey/keypair/keypair.cpp
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/keypair.cpp
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/keypair.cpp')
-rw-r--r--src/lib/pubkey/keypair/keypair.cpp19
1 files changed, 11 insertions, 8 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;