10#include <botan/internal/xmss_index_registry.h>
11#include <botan/hash.h>
16const std::string XMSS_Index_Registry::m_index_hash_function =
"SHA-256";
18uint64_t XMSS_Index_Registry::make_key_id(
19 const secure_vector<uint8_t>& private_seed,
20 const secure_vector<uint8_t>& prf)
const
22 std::unique_ptr<HashFunction>
hash =
25 hash->update(private_seed);
27 secure_vector<uint8_t> result =
hash->final();
29 for(
size_t i = 0; i <
sizeof(key_id); i++)
31 key_id = ((key_id << 8) | result[i]);
37std::shared_ptr<Atomic<size_t>>
41 size_t pos =
get(make_key_id(private_seed, prf));
43 if(pos < std::numeric_limits<size_t>::max())
45 return m_leaf_indices[pos];
49 return m_leaf_indices[add(make_key_id(private_seed, prf))];
55 for(
size_t i = 0; i < m_key_ids.size(); i++)
57 if(m_key_ids[i] ==
id)
63 return std::numeric_limits<size_t>::max();
66size_t XMSS_Index_Registry::add(uint64_t
id,
size_t last_unused)
68 lock_guard_type<mutex_type> lock(m_mutex);
70 if(pos < m_key_ids.size())
72 if(last_unused > *(m_leaf_indices[pos]))
74 m_leaf_indices[pos] = std::make_shared<Atomic<size_t>>(last_unused);
79 m_key_ids.push_back(
id);
80 m_leaf_indices.push_back(std::make_shared<Atomic<size_t>>(last_unused));
81 return m_key_ids.size() - 1;
#define BOTAN_ASSERT(expr, assertion_made)
static std::unique_ptr< HashFunction > create(const std::string &algo_spec, const std::string &provider="")
std::shared_ptr< Atomic< size_t > > get(const secure_vector< uint8_t > &private_seed, const secure_vector< uint8_t > &prf)
std::vector< T, secure_allocator< T > > secure_vector