diff options
author | René Korthaus <[email protected]> | 2016-04-13 19:07:33 +0200 |
---|---|---|
committer | René Korthaus <[email protected]> | 2016-06-14 17:33:50 +0200 |
commit | e14d6a0489ee290d289cf276fa3ff94044191af7 (patch) | |
tree | d3961328c1b6ba592a2114d3f231cd49c6c2a9a2 /src/lib/pubkey/pk_ops.cpp | |
parent | 6816c9e71e01432792a997ad9a5d561b9cd94a48 (diff) |
Add ECKCDSA signature algorithm
Diffstat (limited to 'src/lib/pubkey/pk_ops.cpp')
-rw-r--r-- | src/lib/pubkey/pk_ops.cpp | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/src/lib/pubkey/pk_ops.cpp b/src/lib/pubkey/pk_ops.cpp index 654b68255..1017518a7 100644 --- a/src/lib/pubkey/pk_ops.cpp +++ b/src/lib/pubkey/pk_ops.cpp @@ -76,9 +76,12 @@ secure_vector<byte> PK_Ops::Key_Agreement_with_KDF::agree(size_t key_len, return z; } -PK_Ops::Signature_with_EMSA::Signature_with_EMSA(const std::string& emsa) +PK_Ops::Signature_with_EMSA::Signature_with_EMSA(const std::string& emsa) : + Signature(), + m_emsa(get_emsa(emsa)), + m_hash(hash_for_emsa(emsa)), + m_prefix_used(false) { - m_emsa.reset(get_emsa(emsa)); if(!m_emsa) throw Algorithm_Not_Found(emsa); } @@ -87,19 +90,29 @@ PK_Ops::Signature_with_EMSA::~Signature_with_EMSA() {} void PK_Ops::Signature_with_EMSA::update(const byte msg[], size_t msg_len) { + if(has_prefix() && !m_prefix_used) + { + m_prefix_used = true; + secure_vector<byte> prefix = message_prefix(); + m_emsa->update(prefix.data(), prefix.size()); + } m_emsa->update(msg, msg_len); } secure_vector<byte> PK_Ops::Signature_with_EMSA::sign(RandomNumberGenerator& rng) { + m_prefix_used = false; const secure_vector<byte> msg = m_emsa->raw_data(); const auto padded = m_emsa->encoding_of(msg, this->max_input_bits(), rng); return raw_sign(padded.data(), padded.size(), rng); } -PK_Ops::Verification_with_EMSA::Verification_with_EMSA(const std::string& emsa) +PK_Ops::Verification_with_EMSA::Verification_with_EMSA(const std::string& emsa) : + Verification(), + m_emsa(get_emsa(emsa)), + m_hash(hash_for_emsa(emsa)), + m_prefix_used(false) { - m_emsa.reset(get_emsa(emsa)); if(!m_emsa) throw Algorithm_Not_Found(emsa); } @@ -108,11 +121,18 @@ PK_Ops::Verification_with_EMSA::~Verification_with_EMSA() {} void PK_Ops::Verification_with_EMSA::update(const byte msg[], size_t msg_len) { + if(has_prefix() && !m_prefix_used) + { + m_prefix_used = true; + secure_vector<byte> prefix = message_prefix(); + m_emsa->update(prefix.data(), prefix.size()); + } m_emsa->update(msg, msg_len); } bool PK_Ops::Verification_with_EMSA::is_valid_signature(const byte sig[], size_t sig_len) { + m_prefix_used = false; const secure_vector<byte> msg = m_emsa->raw_data(); if(with_recovery()) |