Botan  2.15.0
Crypto and TLS for C++11
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 <botan/secmem.h>
12 #include <botan/atomic.h>
13 #include <botan/mutex.h>
14 
15 //BOTAN_FUTURE_INTERNAL_HEADER(xmss_index_registry.h)
16 
17 namespace 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  {
25  public:
28 
29  /**
30  * Retrieves a handle to the process-wide unique XMSS index registry.
31  *
32  * @return Reference to unique XMSS index registry.
33  **/
35  {
36  static XMSS_Index_Registry self;
37  return self;
38  }
39 
40  /**
41  * Retrieves the last unused leaf index for the private key identified
42  * by private_seed and prf. The leaf index will be updated properly
43  * across independent copies of private_key.
44  *
45  * @param private_seed Part of the unique identifier for an
46  * XMSS_PrivateKey.
47  * @param prf Part of the unique identifier for an XMSS_PrivateKey.
48  *
49  * @return last unused leaf index for private_key.
50  **/
51  std::shared_ptr<Atomic<size_t>>
52  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  static const std::string m_index_hash_function;
59 
60  /**
61  * Creates a unique 64-bit id for an XMSS_Private key, by interpreting
62  * the first 64-bit of HASH(PRIVATE_SEED || PRF) as 64 bit integer
63  * value.
64  *
65  * @return unique integral identifier for an XMSS private key.
66  **/
67  uint64_t make_key_id(const secure_vector<uint8_t>& private_seed,
68  const secure_vector<uint8_t>& prf) const;
69 
70  /**
71  * Retrieves the index position of a key within the registry or
72  * max(size_t) if key has not been found.
73  *
74  * @param id unique id of the XMSS private key (see make_key_id()).
75  *
76  * @return index position of key or max(size_t) if key not found.
77  **/
78  size_t get(uint64_t id) const;
79 
80  /**
81  * If XMSS_PrivateKey identified by id is already registered, the
82  * position of the according registry entry is returned. If last_unused
83  * is bigger than the last unused index stored for the key identified by
84  * id the unused leaf index for this key is set to last_unused. If no key
85  * matching id is registed yet, an entry of id is added, with the last
86  * unused leaf index initialized to the value of last_unused.
87  *
88  * @last_unused Initial value for the last unused leaf index of the
89  * registered key.
90  *
91  * @return positon of leaf index registry entry for key identified
92  * by id.
93  **/
94  size_t add(uint64_t id, size_t last_unused = 0);
95 
96  std::vector<uint64_t> m_key_ids;
97  std::vector<std::shared_ptr<Atomic<size_t>>> m_leaf_indices;
98  mutex_type m_mutex;
99  };
100 
101 }
102 
103 #endif
int(* final)(unsigned char *, CTX *)
XMSS_Index_Registry & operator=(const XMSS_Index_Registry &)=delete
Definition: alg_id.cpp:13
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:65
static XMSS_Index_Registry & get_instance()