aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/pubkey/xmss
diff options
context:
space:
mode:
authorMatthias Gierlings <[email protected]>2016-11-11 13:02:58 +0100
committerMatthias Gierlings <[email protected]>2016-11-11 15:56:33 +0100
commiteb949db1a01e9f6fd71e25c89c7f015021af12e0 (patch)
treea83347201260d59347f8740ca9ef02f449ee2797 /src/lib/pubkey/xmss
parent8b06b4fe5fbe189c7d5250becb189bf2b87b9013 (diff)
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.
Diffstat (limited to 'src/lib/pubkey/xmss')
-rw-r--r--src/lib/pubkey/xmss/info.txt1
-rw-r--r--src/lib/pubkey/xmss/xmss_hash.cpp9
-rw-r--r--src/lib/pubkey/xmss/xmss_hash.h1
-rw-r--r--src/lib/pubkey/xmss/xmss_index_registry.cpp2
-rw-r--r--src/lib/pubkey/xmss/xmss_index_registry.h4
-rw-r--r--src/lib/pubkey/xmss/xmss_publickey.h14
-rw-r--r--src/lib/pubkey/xmss/xmss_signature_operation.cpp4
-rw-r--r--src/lib/pubkey/xmss/xmss_tools.cpp32
-rw-r--r--src/lib/pubkey/xmss/xmss_tools.h25
-rw-r--r--src/lib/pubkey/xmss/xmss_verification_operation.cpp2
-rw-r--r--src/lib/pubkey/xmss/xmss_wots_parameters.cpp2
-rw-r--r--src/lib/pubkey/xmss/xmss_wots_privatekey.cpp2
-rw-r--r--src/lib/pubkey/xmss/xmss_wots_privatekey.h2
13 files changed, 18 insertions, 82 deletions
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<byte>& 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<std::mutex> lock(m_mutex);
+ lock_guard_type<mutex_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 <cstddef>
#include <limits>
#include <memory>
-#include <mutex>
#include <string>
#include <botan/hash.h>
#include <botan/secmem.h>
#include <botan/types.h>
#include <botan/atomic.h>
+#include <botan/mutex.h>
namespace Botan {
@@ -101,7 +101,7 @@ class XMSS_Index_Registry
std::vector<uint64_t> m_key_ids;
std::vector<std::shared_ptr<Atomic<size_t>>> 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<PK_Ops::Verification>
@@ -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<size_t>::infinity();
- }
-
- virtual size_t message_part_size() const override
- {
- return std::numeric_limits<size_t>::infinity();
- }
-
- virtual size_t message_parts() const override
- {
- return std::numeric_limits<size_t>::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 <botan/xmss_tools.h>
-
-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<const byte*>(&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 <stdint.h>
#include <iterator>
#include <type_traits>
+#include <botan/cpuid.h>
#include <botan/types.h>
#include <botan/secmem.h>
@@ -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<typename T,
typename U = typename std::enable_if<std::is_integral<T>::value,
void>::type>
- void concat(secure_vector<byte>& target, const T& src) const;
+ static void concat(secure_vector<byte>& target, const T& src);
/**
* Concatenates the last n bytes of the byte representation in big-endian
@@ -62,19 +53,17 @@ namespace Botan {
template <typename T,
typename U = typename std::enable_if<std::is_integral<T>::value,
void>::type>
- void concat(secure_vector<byte>& target, const T& src, size_t len) const;
+ static void concat(secure_vector<byte>& target, const T& src, size_t len);
private:
XMSS_Tools();
-
- bool m_is_little_endian;
};
template <typename T, typename U>
-void XMSS_Tools::concat(secure_vector<byte>& target, const T& src) const
+void XMSS_Tools::concat(secure_vector<byte>& target, const T& src)
{
const byte* src_bytes = reinterpret_cast<const byte*>(&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<byte>& target, const T& src) const
template <typename T, typename U>
void XMSS_Tools::concat(secure_vector<byte>& target,
const T& src,
- size_t len) const
+ size_t len)
{
size_t c = static_cast<size_t>(std::min(len, sizeof(src)));
if(len > sizeof(src))
@@ -97,7 +86,7 @@ void XMSS_Tools::concat(secure_vector<byte>& target,
}
const byte* src_bytes = reinterpret_cast<const byte*>(&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<byte> index_bytes;
- XMSS_Tools::get().concat(index_bytes,
+ XMSS_Tools::concat(index_bytes,
sig.unused_leaf_index(),
m_xmss_params.element_size());
secure_vector<byte> 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<size_t>(
ceil(static_cast<float>(m_len_2 * m_lg_w) / 8.f));
secure_vector<byte> 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<byte>& priv_seed)
for(size_t i = 0; i < m_wots_params.len(); i++)
{
- XMSS_Tools::get().concat<size_t>(priv_key[i], i, 32);
+ XMSS_Tools::concat<size_t>(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<byte> 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);
}