From eb949db1a01e9f6fd71e25c89c7f015021af12e0 Mon Sep 17 00:00:00 2001 From: Matthias Gierlings Date: Fri, 11 Nov 2016 13:02:58 +0100 Subject: Implements changes from XMSS review - Removes custom XMSS_Hash assignment operator. - Changes mutex type used in XMSS_Index_Registryfrom std::mutex to Botan::mutex_type, changes lock_guard accordingly. - Removes singleton and endianess detection from XMSS_Tools, changes XMSS_Tools::concat() to be a static method. - XMSS/XMSS_WOTS check_key() now always returns true. --- src/lib/pubkey/xmss/info.txt | 1 - src/lib/pubkey/xmss/xmss_hash.cpp | 9 ------ src/lib/pubkey/xmss/xmss_hash.h | 1 - src/lib/pubkey/xmss/xmss_index_registry.cpp | 2 +- src/lib/pubkey/xmss/xmss_index_registry.h | 4 +-- src/lib/pubkey/xmss/xmss_publickey.h | 14 ++-------- src/lib/pubkey/xmss/xmss_signature_operation.cpp | 4 +-- src/lib/pubkey/xmss/xmss_tools.cpp | 32 ---------------------- src/lib/pubkey/xmss/xmss_tools.h | 25 +++++------------ .../pubkey/xmss/xmss_verification_operation.cpp | 2 +- src/lib/pubkey/xmss/xmss_wots_parameters.cpp | 2 +- src/lib/pubkey/xmss/xmss_wots_privatekey.cpp | 2 +- src/lib/pubkey/xmss/xmss_wots_privatekey.h | 2 +- 13 files changed, 18 insertions(+), 82 deletions(-) delete mode 100644 src/lib/pubkey/xmss/xmss_tools.cpp diff --git a/src/lib/pubkey/xmss/info.txt b/src/lib/pubkey/xmss/info.txt index a92b06beb..bab541625 100644 --- a/src/lib/pubkey/xmss/info.txt +++ b/src/lib/pubkey/xmss/info.txt @@ -9,7 +9,6 @@ xmss_privatekey.cpp xmss_publickey.cpp xmss_signature.cpp xmss_signature_operation.cpp -xmss_tools.cpp xmss_verification_operation.cpp xmss_wots_parameters.cpp xmss_wots_privatekey.cpp diff --git a/src/lib/pubkey/xmss/xmss_hash.cpp b/src/lib/pubkey/xmss/xmss_hash.cpp index 15cdab509..2dfcabbbc 100644 --- a/src/lib/pubkey/xmss/xmss_hash.cpp +++ b/src/lib/pubkey/xmss/xmss_hash.cpp @@ -76,13 +76,4 @@ XMSS_Hash::h_msg(const secure_vector& randomness, return m_msg_hash->final(); } -XMSS_Hash& XMSS_Hash::operator=(XMSS_Hash hash) - { - std::swap(m_hash, hash.m_hash); - std::swap(m_msg_hash, hash.m_msg_hash); - std::swap(m_output_length, hash.m_output_length); - std::swap(m_zero_padding, hash.m_zero_padding); - return *this; - } - } diff --git a/src/lib/pubkey/xmss/xmss_hash.h b/src/lib/pubkey/xmss/xmss_hash.h index da059fb7b..1af9feb25 100644 --- a/src/lib/pubkey/xmss/xmss_hash.h +++ b/src/lib/pubkey/xmss/xmss_hash.h @@ -26,7 +26,6 @@ class XMSS_Hash public: XMSS_Hash(const std::string& h_func_name); XMSS_Hash(const XMSS_Hash& hash); - XMSS_Hash& operator=(XMSS_Hash hash); /** * Pseudoranom function creating a hash out of a key and data using diff --git a/src/lib/pubkey/xmss/xmss_index_registry.cpp b/src/lib/pubkey/xmss/xmss_index_registry.cpp index f7f4ec470..a85bc7c9f 100644 --- a/src/lib/pubkey/xmss/xmss_index_registry.cpp +++ b/src/lib/pubkey/xmss/xmss_index_registry.cpp @@ -63,7 +63,7 @@ size_t XMSS_Index_Registry::get(uint64_t id) const size_t XMSS_Index_Registry::add(uint64_t id, size_t last_unused) { - std::lock_guard lock(m_mutex); + lock_guard_type lock(m_mutex); size_t pos = get(id); if(pos < m_key_ids.size()) { diff --git a/src/lib/pubkey/xmss/xmss_index_registry.h b/src/lib/pubkey/xmss/xmss_index_registry.h index 5dcb6d31b..8759ca03b 100644 --- a/src/lib/pubkey/xmss/xmss_index_registry.h +++ b/src/lib/pubkey/xmss/xmss_index_registry.h @@ -12,12 +12,12 @@ #include #include #include -#include #include #include #include #include #include +#include namespace Botan { @@ -101,7 +101,7 @@ class XMSS_Index_Registry std::vector m_key_ids; std::vector>> m_leaf_indices; - std::mutex m_mutex; + mutex_type m_mutex; }; } diff --git a/src/lib/pubkey/xmss/xmss_publickey.h b/src/lib/pubkey/xmss/xmss_publickey.h index faa35d80a..a18c70836 100644 --- a/src/lib/pubkey/xmss/xmss_publickey.h +++ b/src/lib/pubkey/xmss/xmss_publickey.h @@ -198,7 +198,7 @@ class BOTAN_DLL XMSS_PublicKey : public virtual Public_Key virtual bool check_key(RandomNumberGenerator&, bool) const override { - BOTAN_ASSERT(false, "No key strength check implemented for XMSS."); + return true; } virtual std::unique_ptr @@ -212,17 +212,7 @@ class BOTAN_DLL XMSS_PublicKey : public virtual Public_Key virtual size_t max_input_bits() const override { - return std::numeric_limits::infinity(); - } - - virtual size_t message_part_size() const override - { - return std::numeric_limits::infinity(); - } - - virtual size_t message_parts() const override - { - return std::numeric_limits::infinity(); + throw Not_Implemented("XMSS doesn't support max_input_bits()."); } /** diff --git a/src/lib/pubkey/xmss/xmss_signature_operation.cpp b/src/lib/pubkey/xmss/xmss_signature_operation.cpp index d223ddef0..07121db14 100644 --- a/src/lib/pubkey/xmss/xmss_signature_operation.cpp +++ b/src/lib/pubkey/xmss/xmss_signature_operation.cpp @@ -97,10 +97,10 @@ void XMSS_Signature_Operation::initialize() m_leaf_idx = m_priv_key.reserve_unused_leaf_index(); // write prefix for message hashing into buffer. - XMSS_Tools::get().concat(index_bytes, m_leaf_idx, 32); + XMSS_Tools::concat(index_bytes, m_leaf_idx, 32); m_randomness = m_hash.prf(m_priv_key.prf(), index_bytes); index_bytes.clear(); - XMSS_Tools::get().concat(index_bytes, m_leaf_idx, + XMSS_Tools::concat(index_bytes, m_leaf_idx, m_priv_key.xmss_parameters().element_size()); m_hash.h_msg_init(m_randomness, m_priv_key.root(), diff --git a/src/lib/pubkey/xmss/xmss_tools.cpp b/src/lib/pubkey/xmss/xmss_tools.cpp deleted file mode 100644 index 13e66759c..000000000 --- a/src/lib/pubkey/xmss/xmss_tools.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/** - * XMSS Tools - * Contains some helper functions. - * (C) 2016 Matthias Gierlings - * - * Botan is released under the Simplified BSD License (see license.txt) - **/ -#include - -namespace Botan { - -XMSS_Tools::XMSS_Tools() - { -#if defined(BOTAN_TARGET_CPU_HAS_KNOWN_ENDIANESS) -#if defined(BOTAN_TARGET_CPU_IS_LITTLE_ENDIAN) - m_is_little_endian = true; -#else - m_is_little_endian = false; -#endif -#else - uint16_t data = 0x01; - m_is_little_endian = reinterpret_cast(&data)[0] == 0x01; -#endif - } - -const XMSS_Tools& XMSS_Tools::get() - { - static const XMSS_Tools self; - return self; - } - -} diff --git a/src/lib/pubkey/xmss/xmss_tools.h b/src/lib/pubkey/xmss/xmss_tools.h index 07e36ea71..773953fae 100644 --- a/src/lib/pubkey/xmss/xmss_tools.h +++ b/src/lib/pubkey/xmss/xmss_tools.h @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -26,16 +27,6 @@ namespace Botan { XMSS_Tools(const XMSS_Tools&) = delete; void operator=(const XMSS_Tools&) = delete; - static const XMSS_Tools& get(); - - /** - * Retrieves information about endianess - * - * @return true if machine uses little-endian byte order, false - * otherwise. - **/ - inline bool is_little_endian() const { return m_is_little_endian; } - /** * Concatenates the byte representation in big-endian order of any * integral value to a secure_vector. @@ -47,7 +38,7 @@ namespace Botan { template::value, void>::type> - void concat(secure_vector& target, const T& src) const; + static void concat(secure_vector& target, const T& src); /** * Concatenates the last n bytes of the byte representation in big-endian @@ -62,19 +53,17 @@ namespace Botan { template ::value, void>::type> - void concat(secure_vector& target, const T& src, size_t len) const; + static void concat(secure_vector& target, const T& src, size_t len); private: XMSS_Tools(); - - bool m_is_little_endian; }; template -void XMSS_Tools::concat(secure_vector& target, const T& src) const +void XMSS_Tools::concat(secure_vector& target, const T& src) { const byte* src_bytes = reinterpret_cast(&src); - if(is_little_endian()) + if(CPUID::is_little_endian()) std::reverse_copy(src_bytes, src_bytes + sizeof(src), std::back_inserter(target)); @@ -88,7 +77,7 @@ void XMSS_Tools::concat(secure_vector& target, const T& src) const template void XMSS_Tools::concat(secure_vector& target, const T& src, - size_t len) const + size_t len) { size_t c = static_cast(std::min(len, sizeof(src))); if(len > sizeof(src)) @@ -97,7 +86,7 @@ void XMSS_Tools::concat(secure_vector& target, } const byte* src_bytes = reinterpret_cast(&src); - if(is_little_endian()) + if(CPUID::is_little_endian()) std::reverse_copy(src_bytes, src_bytes + c, std::back_inserter(target)); diff --git a/src/lib/pubkey/xmss/xmss_verification_operation.cpp b/src/lib/pubkey/xmss/xmss_verification_operation.cpp index 20945e8ca..79bd61d17 100644 --- a/src/lib/pubkey/xmss/xmss_verification_operation.cpp +++ b/src/lib/pubkey/xmss/xmss_verification_operation.cpp @@ -77,7 +77,7 @@ XMSS_Verification_Operation::verify(const XMSS_Signature& sig, { XMSS_Address adrs; secure_vector index_bytes; - XMSS_Tools::get().concat(index_bytes, + XMSS_Tools::concat(index_bytes, sig.unused_leaf_index(), m_xmss_params.element_size()); secure_vector msg_digest = diff --git a/src/lib/pubkey/xmss/xmss_wots_parameters.cpp b/src/lib/pubkey/xmss/xmss_wots_parameters.cpp index b908afeb4..903885d72 100644 --- a/src/lib/pubkey/xmss/xmss_wots_parameters.cpp +++ b/src/lib/pubkey/xmss/xmss_wots_parameters.cpp @@ -109,7 +109,7 @@ XMSS_WOTS_Parameters::base_w(size_t value) const size_t len_2_bytes = static_cast( ceil(static_cast(m_len_2 * m_lg_w) / 8.f)); secure_vector result; - XMSS_Tools::get().concat(result, value, len_2_bytes); + XMSS_Tools::concat(result, value, len_2_bytes); return base_w(result, m_len_2); } diff --git a/src/lib/pubkey/xmss/xmss_wots_privatekey.cpp b/src/lib/pubkey/xmss/xmss_wots_privatekey.cpp index f94ba3612..1a68b187d 100644 --- a/src/lib/pubkey/xmss/xmss_wots_privatekey.cpp +++ b/src/lib/pubkey/xmss/xmss_wots_privatekey.cpp @@ -20,7 +20,7 @@ XMSS_WOTS_PrivateKey::generate(const secure_vector& priv_seed) for(size_t i = 0; i < m_wots_params.len(); i++) { - XMSS_Tools::get().concat(priv_key[i], i, 32); + XMSS_Tools::concat(priv_key[i], i, 32); m_hash.prf(priv_key[i], priv_seed, priv_key[i]); } return priv_key; diff --git a/src/lib/pubkey/xmss/xmss_wots_privatekey.h b/src/lib/pubkey/xmss/xmss_wots_privatekey.h index 422d014f4..2c38faad6 100644 --- a/src/lib/pubkey/xmss/xmss_wots_privatekey.h +++ b/src/lib/pubkey/xmss/xmss_wots_privatekey.h @@ -118,7 +118,7 @@ class BOTAN_DLL XMSS_WOTS_PrivateKey : public virtual XMSS_WOTS_PublicKey, wots_keysig_t operator[](size_t i) { secure_vector idx_bytes; - XMSS_Tools::get().concat(idx_bytes, i, m_wots_params.element_size()); + XMSS_Tools::concat(idx_bytes, i, m_wots_params.element_size()); m_hash.h(idx_bytes, m_private_seed, idx_bytes); return generate(idx_bytes); } -- cgit v1.2.3