Botan 3.9.0
Crypto and TLS for C&
xmss_index_registry.h
Go to the documentation of this file.
1/*
2 * XMSS Index Registry
3 * (C) 2016 Matthias Gierlings
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 **/
7
8#ifndef BOTAN_XMSS_INDEX_REGISTRY_H_
9#define BOTAN_XMSS_INDEX_REGISTRY_H_
10
11#include <string>
12
13#include <botan/mutex.h>
14#include <botan/secmem.h>
15#include <botan/internal/atomic.h>
16
17namespace Botan {
18
19/**
20 * A registry for XMSS private keys, keeps track of the leaf index for
21 * independend copies of the same key.
22 **/
24 public:
30
31 /**
32 * Retrieves a handle to the process-wide unique XMSS index registry.
33 *
34 * @return Reference to unique XMSS index registry.
35 **/
37 static XMSS_Index_Registry self;
38 return self;
39 }
40
41 /**
42 * Retrieves the last unused leaf index for the private key identified
43 * by private_seed and prf. The leaf index will be updated properly
44 * across independent copies of private_key.
45 *
46 * @param private_seed Part of the unique identifier for an
47 * XMSS_PrivateKey.
48 * @param prf Part of the unique identifier for an XMSS_PrivateKey.
49 *
50 * @return last unused leaf index for private_key.
51 **/
52 std::shared_ptr<Atomic<size_t>> get(const secure_vector<uint8_t>& private_seed,
53 const secure_vector<uint8_t>& prf);
54
55 private:
56 XMSS_Index_Registry() = default;
57
58 /**
59 * Creates a unique 64-bit id for an XMSS_Private key, by interpreting
60 * the first 64-bit of HASH(PRIVATE_SEED || PRF) as 64 bit integer
61 * value.
62 *
63 * @return unique integral identifier for an XMSS private key.
64 **/
65 static uint64_t make_key_id(const secure_vector<uint8_t>& private_seed, const secure_vector<uint8_t>& prf);
66
67 /**
68 * Retrieves the index position of a key within the registry or
69 * max(size_t) if key has not been found.
70 *
71 * @param id unique id of the XMSS private key (see make_key_id()).
72 *
73 * @return index position of key or max(size_t) if key not found.
74 **/
75 size_t get(uint64_t id) const;
76
77 /**
78 * If XMSS_PrivateKey identified by id is already registered, the
79 * position of the according registry entry is returned. If last_unused
80 * is bigger than the last unused index stored for the key identified by
81 * id the unused leaf index for this key is set to last_unused. If no key
82 * matching id is registed yet, an entry of id is added, with the last
83 * unused leaf index initialized to the value of last_unused.
84 *
85 * @last_unused Initial value for the last unused leaf index of the
86 * registered key.
87 *
88 * @return positon of leaf index registry entry for key identified
89 * by id.
90 **/
91 size_t add(uint64_t id, size_t last_unused = 0);
92
93 std::vector<uint64_t> m_key_ids;
94 std::vector<std::shared_ptr<Atomic<size_t>>> m_leaf_indices;
95 mutex_type m_mutex;
96};
97
98} // namespace Botan
99
100#endif
XMSS_Index_Registry(XMSS_Index_Registry &&)=delete
std::shared_ptr< Atomic< size_t > > get(const secure_vector< uint8_t > &private_seed, const secure_vector< uint8_t > &prf)
static XMSS_Index_Registry & get_instance()
XMSS_Index_Registry & operator=(XMSS_Index_Registry &&)=delete
XMSS_Index_Registry(const XMSS_Index_Registry &)=delete
XMSS_Index_Registry & operator=(const XMSS_Index_Registry &)=delete
noop_mutex mutex_type
Definition mutex.h:37
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:69