diff options
author | Jack Lloyd <[email protected]> | 2019-03-03 19:09:02 -0500 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2019-03-03 19:09:02 -0500 |
commit | e44f4b5d06a3b10c5cfd380cd3917f94bdb03fef (patch) | |
tree | af26040ba69f79161e2fe1b4a71923845b84c43e /src/lib | |
parent | ff9174588a7ab7c1f7c2c88f24cb9a01dc6381f8 (diff) |
Handle invalid public key length in Ed25519
Closes #1850
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/pubkey/ed25519/ed25519.h | 15 | ||||
-rw-r--r-- | src/lib/pubkey/ed25519/ed25519_key.cpp | 19 |
2 files changed, 20 insertions, 14 deletions
diff --git a/src/lib/pubkey/ed25519/ed25519.h b/src/lib/pubkey/ed25519/ed25519.h index f563115dd..51c75e641 100644 --- a/src/lib/pubkey/ed25519/ed25519.h +++ b/src/lib/pubkey/ed25519/ed25519.h @@ -38,18 +38,11 @@ class BOTAN_PUBLIC_API(2,2) Ed25519_PublicKey : public virtual Public_Key Ed25519_PublicKey(const AlgorithmIdentifier& alg_id, const std::vector<uint8_t>& key_bits); - /** - * Create a Ed25519 Public Key. - * @param pub 32-byte raw public key - */ - explicit Ed25519_PublicKey(const std::vector<uint8_t>& pub) : m_public(pub) {} + template<typename Alloc> + Ed25519_PublicKey(const std::vector<uint8_t, Alloc>& pub) : + Ed25519_PublicKey(pub.data(), pub.size()) {} - /** - * Create a Ed25519 Public Key. - * @param pub 32-byte raw public key - */ - explicit Ed25519_PublicKey(const secure_vector<uint8_t>& pub) : - m_public(pub.begin(), pub.end()) {} + Ed25519_PublicKey(const uint8_t pub_key[], size_t len); std::unique_ptr<PK_Ops::Verification> create_verification_op(const std::string& params, diff --git a/src/lib/pubkey/ed25519/ed25519_key.cpp b/src/lib/pubkey/ed25519/ed25519_key.cpp index ee1d19edb..1de24aa26 100644 --- a/src/lib/pubkey/ed25519/ed25519_key.cpp +++ b/src/lib/pubkey/ed25519/ed25519_key.cpp @@ -28,8 +28,15 @@ bool Ed25519_PublicKey::check_key(RandomNumberGenerator&, bool) const // TODO could check cofactor } +Ed25519_PublicKey::Ed25519_PublicKey(const uint8_t pub_key[], size_t pub_len) + { + if(pub_len != 32) + throw Decoding_Error("Invalid length for Ed25519 key"); + m_public.assign(pub_key, pub_key + pub_len); + } + Ed25519_PublicKey::Ed25519_PublicKey(const AlgorithmIdentifier&, - const std::vector<uint8_t>& key_bits) + const std::vector<uint8_t>& key_bits) { m_public = key_bits; @@ -112,7 +119,10 @@ class Ed25519_Pure_Verify_Operation final : public PK_Ops::Verification { if(sig_len != 64) return false; - const bool ok = ed25519_verify(m_msg.data(), m_msg.size(), sig, m_key.get_public_key().data()); + + const std::vector<uint8_t>& pub_key = m_key.get_public_key(); + BOTAN_ASSERT_EQUAL(pub_key.size(), 32, "Expected size"); + const bool ok = ed25519_verify(m_msg.data(), m_msg.size(), sig, pub_key.data()); m_msg.clear(); return ok; } @@ -144,7 +154,10 @@ class Ed25519_Hashed_Verify_Operation final : public PK_Ops::Verification return false; std::vector<uint8_t> msg_hash(m_hash->output_length()); m_hash->final(msg_hash.data()); - return ed25519_verify(msg_hash.data(), msg_hash.size(), sig, m_key.get_public_key().data()); + + const std::vector<uint8_t>& pub_key = m_key.get_public_key(); + BOTAN_ASSERT_EQUAL(pub_key.size(), 32, "Expected size"); + return ed25519_verify(msg_hash.data(), msg_hash.size(), sig, pub_key.data()); } private: |