10#include <botan/internal/xmss_index_registry.h>
12#include <botan/hash.h>
17const std::string XMSS_Index_Registry::m_index_hash_function =
"SHA-256";
23 BOTAN_ASSERT(hash !=
nullptr,
"XMSS_Index_Registry requires SHA-256");
24 hash->update(private_seed);
28 for(
size_t i = 0; i <
sizeof(key_id); i++) {
29 key_id = ((key_id << 8) | result[i]);
37 size_t pos =
get(make_key_id(private_seed, prf));
39 if(pos < std::numeric_limits<size_t>::max()) {
40 return m_leaf_indices[pos];
42 return m_leaf_indices[add(make_key_id(private_seed, prf))];
47 for(
size_t i = 0; i < m_key_ids.size(); i++) {
48 if(m_key_ids[i] ==
id) {
53 return std::numeric_limits<size_t>::max();
56size_t XMSS_Index_Registry::add(uint64_t
id,
size_t last_unused) {
59 if(pos < m_key_ids.size()) {
60 if(last_unused > *(m_leaf_indices[pos])) {
61 m_leaf_indices[pos] = std::make_shared<Atomic<size_t>>(last_unused);
66 m_key_ids.push_back(
id);
67 m_leaf_indices.push_back(std::make_shared<Atomic<size_t>>(last_unused));
68 return m_key_ids.size() - 1;
#define BOTAN_ASSERT(expr, assertion_made)
static std::unique_ptr< HashFunction > create(std::string_view algo_spec, std::string_view provider="")
std::shared_ptr< Atomic< size_t > > get(const secure_vector< uint8_t > &private_seed, const secure_vector< uint8_t > &prf)
secure_vector< T > lock(const std::vector< T > &in)
std::vector< T, secure_allocator< T > > secure_vector
lock_guard< T > lock_guard_type