diff options
author | Jack Lloyd <[email protected]> | 2016-11-25 17:07:12 -0500 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2016-11-25 17:07:12 -0500 |
commit | 4a849b7ebb329630ef03d5b3961d57c5f76cfa0b (patch) | |
tree | 88fb27dc826dfe9fdd3b40a5b23dc4b32539aa18 /src/lib/pubkey | |
parent | e8568ba5a45c7383709b27e2fa0443b938bf6ea9 (diff) |
Correct XMSS crash when a hash was disabled
Require SHA-256 in XMSS since that is mandatory for the index registry.
Diffstat (limited to 'src/lib/pubkey')
-rw-r--r-- | src/lib/pubkey/xmss/info.txt | 1 | ||||
-rw-r--r-- | src/lib/pubkey/xmss/xmss_hash.cpp | 18 | ||||
-rw-r--r-- | src/lib/pubkey/xmss/xmss_hash.h | 11 | ||||
-rw-r--r-- | src/lib/pubkey/xmss/xmss_parameters.cpp | 2 |
4 files changed, 20 insertions, 12 deletions
diff --git a/src/lib/pubkey/xmss/info.txt b/src/lib/pubkey/xmss/info.txt index bab541625..862ff68f9 100644 --- a/src/lib/pubkey/xmss/info.txt +++ b/src/lib/pubkey/xmss/info.txt @@ -42,4 +42,5 @@ xmss_verification_operation.h asn1 rng hash +sha2_32 </requires> diff --git a/src/lib/pubkey/xmss/xmss_hash.cpp b/src/lib/pubkey/xmss/xmss_hash.cpp index d6ae2bb3b..3731f7751 100644 --- a/src/lib/pubkey/xmss/xmss_hash.cpp +++ b/src/lib/pubkey/xmss/xmss_hash.cpp @@ -8,6 +8,7 @@ **/ #include <botan/xmss_hash.h> +#include <botan/exceptn.h> namespace Botan { @@ -16,14 +17,19 @@ XMSS_Hash::XMSS_Hash(const XMSS_Hash& hash) { } -XMSS_Hash::XMSS_Hash(const std::string& h_func_name) - : m_hash(HashFunction::create(h_func_name)), - m_msg_hash(HashFunction::create(h_func_name)), - m_output_length(m_hash->output_length()), - m_zero_padding(m_output_length - 1, 0x00), - m_hash_func_name(h_func_name) +XMSS_Hash::XMSS_Hash(const std::string& h_func_name) : + m_hash_func_name(h_func_name), + m_hash(HashFunction::create(h_func_name)) { + if(!m_hash) + throw Lookup_Error("XMSS cannot use hash " + h_func_name + + " because it is unavailable"); + + m_output_length = m_hash->output_length(); BOTAN_ASSERT(m_output_length > 0, "Hash output length of zero is invalid."); + + m_zero_padding.resize(m_output_length - 1); + m_msg_hash.reset(m_hash->clone()); } void diff --git a/src/lib/pubkey/xmss/xmss_hash.h b/src/lib/pubkey/xmss/xmss_hash.h index cf42f8d91..2cca26658 100644 --- a/src/lib/pubkey/xmss/xmss_hash.h +++ b/src/lib/pubkey/xmss/xmss_hash.h @@ -147,17 +147,18 @@ class XMSS_Hash size_t output_length() const { return m_output_length; }; private: + static const byte m_id_f = 0x00; + static const byte m_id_h = 0x01; + static const byte m_id_hmsg = 0x02; + static const byte m_id_prf = 0x03; + + const std::string m_hash_func_name; std::unique_ptr<HashFunction> m_hash; std::unique_ptr<HashFunction> m_msg_hash; size_t m_output_length; //32 byte id prefixes prepended to the hash input. std::vector<byte> m_zero_padding; - static const byte m_id_f = 0x00; - static const byte m_id_h = 0x01; - static const byte m_id_hmsg = 0x02; - static const byte m_id_prf = 0x03; - const std::string m_hash_func_name; }; } diff --git a/src/lib/pubkey/xmss/xmss_parameters.cpp b/src/lib/pubkey/xmss/xmss_parameters.cpp index c55b25a27..cc4d923dd 100644 --- a/src/lib/pubkey/xmss/xmss_parameters.cpp +++ b/src/lib/pubkey/xmss/xmss_parameters.cpp @@ -43,7 +43,7 @@ XMSS_Parameters::xmss_algorithm_t XMSS_Parameters::xmss_id_from_string(const std return XMSS_SHAKE256_W16_H16; if(param_set == "XMSS_SHAKE256_W16_H20") return XMSS_SHAKE256_W16_H20; - throw Invalid_Argument("Unknown XMSS algorithm param '" + param_set + "'"); + throw Lookup_Error("Unknown XMSS algorithm param '" + param_set + "'"); } XMSS_Parameters::XMSS_Parameters(const std::string& param_set) |