9#ifndef BOTAN_SPHINCS_PLUS_ADDRESS_H_
10#define BOTAN_SPHINCS_PLUS_ADDRESS_H_
12#include <botan/internal/loadstor.h>
13#include <botan/internal/sp_types.h>
35 static constexpr size_t layer_offset = 0;
36 static constexpr size_t tree_offset = 1;
37 static constexpr size_t type_offset = 4;
38 static constexpr size_t keypair_offset = 5;
39 static constexpr size_t chain_offset = 6;
40 static constexpr size_t hash_offset = 7;
41 static constexpr size_t tree_height_offset = chain_offset;
42 static constexpr size_t tree_index_offset = hash_offset;
50 std::copy(address.begin(), address.end(), m_address.begin());
56 m_address[layer_offset] = layer.
get();
61 m_address[tree_offset + 0] = 0;
62 m_address[tree_offset + 1] =
static_cast<uint32_t
>(tree.
get() >> 32);
63 m_address[tree_offset + 2] =
static_cast<uint32_t
>(tree.
get());
72 m_address[type_offset] =
static_cast<uint32_t
>(type);
77 m_address[keypair_offset] = keypair.
get();
82 m_address[chain_offset] = chain.
get();
87 m_address[tree_height_offset] = tree_height.
get();
92 m_address[hash_offset] = hash.
get();
97 m_address[tree_index_offset] = tree_index.
get();
104 m_address[layer_offset] = other.m_address[layer_offset];
105 m_address[tree_offset + 0] = other.m_address[tree_offset + 0];
106 m_address[tree_offset + 1] = other.m_address[tree_offset + 1];
107 m_address[tree_offset + 2] = other.m_address[tree_offset + 2];
114 result.copy_subtree_from(other);
119 m_address[layer_offset] = other.m_address[layer_offset];
120 m_address[tree_offset + 0] = other.m_address[tree_offset + 0];
121 m_address[tree_offset + 1] = other.m_address[tree_offset + 1];
122 m_address[tree_offset + 2] = other.m_address[tree_offset + 2];
123 m_address[keypair_offset] = other.m_address[keypair_offset];
130 result.copy_keypair_from(other);
137 std::array<uint8_t,
sizeof(m_address)> result{};
138 for(
unsigned int i = 0; i < m_address.size(); ++i) {
139 store_be(m_address[i], result.data() + (i * 4));
145 std::array<uint8_t, 22> result{};
147 result[0] =
static_cast<uint8_t
>(m_address[layer_offset]);
148 store_be(m_address[tree_offset + 1], &result[1]);
149 store_be(m_address[tree_offset + 2], &result[5]);
150 result[9] =
static_cast<uint8_t
>(m_address[type_offset]);
151 store_be(m_address[keypair_offset], &result[10]);
152 store_be(m_address[chain_offset], &result[14]);
153 store_be(m_address[hash_offset], &result[18]);
159 std::array<uint32_t, 8> m_address;
Sphincs_Address_Type get_type() const
Sphincs_Address & set_layer_address(HypertreeLayerIndex layer)
Sphincs_Address & set_tree_address(XmssTreeIndexInLayer tree)
Sphincs_Address & set_chain_address(WotsChainIndex chain)
Sphincs_Address & copy_subtree_from(const Sphincs_Address &other)
std::array< uint8_t, 22 > to_bytes_compressed() const
Sphincs_Address & set_hash_address(WotsHashIndex hash)
Sphincs_Address & set_tree_height(TreeLayerIndex tree_height)
Sphincs_Address & set_tree_index(TreeNodeIndex tree_index)
static Sphincs_Address as_subtree_from(const Sphincs_Address &other)
Sphincs_Address & set_keypair_address(TreeNodeIndex keypair)
Sphincs_Address(Sphincs_Address_Type type)
Sphincs_Address & copy_keypair_from(const Sphincs_Address other)
Sphincs_Address(std::array< uint32_t, 8 > address)
Sphincs_Address & set_type(Sphincs_Address_Type type)
static Sphincs_Address as_keypair_from(const Sphincs_Address &other)
std::array< uint8_t, 32 > to_bytes() const
@ ForsTreeRootsCompression
@ WotsPublicKeyCompression
Strong< uint64_t, struct XmssTreeIndexInLayer_, EnableArithmeticWithPlainNumber > XmssTreeIndexInLayer
Index of an XMSS tree (unique for just the local hyper-tree layer).
Strong< uint8_t, struct WotsHashIndex_, EnableArithmeticWithPlainNumber > WotsHashIndex
Index of a hash application inside a single WOTS chain (integers in "base_w").
Strong< uint32_t, struct WotsChainIndex_ > WotsChainIndex
Index of a WOTS chain within a single usage of WOTS.
Strong< uint32_t, struct TreeNodeIndex_, EnableArithmeticWithPlainNumber > TreeNodeIndex
Index of an individual node inside an XMSS or FORS tree.
Strong< uint32_t, struct TreeLayerIndex_, EnableArithmeticWithPlainNumber > TreeLayerIndex
Index of the layer within a FORS/XMSS tree.
Strong< uint32_t, struct HypertreeLayerIndex_ > HypertreeLayerIndex
Index of a layer in the XMSS hyper-tree.
constexpr auto store_be(ParamTs &&... params)