diff options
Diffstat (limited to 'src/lib/pubkey/xmss/xmss_publickey.cpp')
-rw-r--r-- | src/lib/pubkey/xmss/xmss_publickey.cpp | 35 |
1 files changed, 28 insertions, 7 deletions
diff --git a/src/lib/pubkey/xmss/xmss_publickey.cpp b/src/lib/pubkey/xmss/xmss_publickey.cpp index 7c7c19fc1..4db7a2232 100644 --- a/src/lib/pubkey/xmss/xmss_publickey.cpp +++ b/src/lib/pubkey/xmss/xmss_publickey.cpp @@ -16,26 +16,47 @@ #include <botan/internal/xmss_verification_operation.h> #include <botan/xmss_publickey.h> +#include <botan/der_enc.h> +#include <botan/ber_dec.h> namespace Botan { -XMSS_PublicKey::XMSS_PublicKey(const std::vector<uint8_t>& raw_key) - : m_xmss_params(XMSS_PublicKey::deserialize_xmss_oid(raw_key)), +namespace { + +std::vector<uint8_t> extract_raw_key(const std::vector<uint8_t>& key_bits) +{ + std::vector<uint8_t> raw_key; + try + { + BER_Decoder(key_bits).decode(raw_key, OCTET_STRING); + } + catch(Decoding_Error& e) + { + raw_key = key_bits; + } + return raw_key; +} + +} + +XMSS_PublicKey::XMSS_PublicKey(const std::vector<uint8_t>& key_bits) + : m_raw_key(extract_raw_key(key_bits)), + m_xmss_params(XMSS_PublicKey::deserialize_xmss_oid(m_raw_key)), m_wots_params(m_xmss_params.ots_oid()) { - if(raw_key.size() < XMSS_PublicKey::size()) + if(m_raw_key.size() < XMSS_PublicKey::size()) { - throw Decoding_Error("Invalid XMSS public key size detected."); + throw Decoding_Error("Invalid XMSS public key size detected"); } - // extract & copy root from raw key. + // extract & copy root from raw key m_root.clear(); m_root.reserve(m_xmss_params.element_size()); - auto begin = raw_key.begin() + sizeof(uint32_t); + auto begin = m_raw_key.begin() + sizeof(uint32_t); auto end = begin + m_xmss_params.element_size(); std::copy(begin, end, std::back_inserter(m_root)); - // extract & copy public seed from raw key. + // extract & copy public seed from raw key begin = end; end = begin + m_xmss_params.element_size(); m_public_seed.clear(); |