9#ifndef BOTAN_SPHINCS_PLUS_ADDRESS_H_
10#define BOTAN_SPHINCS_PLUS_ADDRESS_H_
14#include <botan/hash.h>
15#include <botan/internal/loadstor.h>
16#include <botan/internal/sp_types.h>
37 static constexpr size_t layer_offset = 0;
38 static constexpr size_t tree_offset = 1;
39 static constexpr size_t type_offset = 4;
40 static constexpr size_t keypair_offset = 5;
41 static constexpr size_t chain_offset = 6;
42 static constexpr size_t hash_offset = 7;
43 static constexpr size_t tree_height_offset = chain_offset;
44 static constexpr size_t tree_index_offset = hash_offset;
52 std::copy(address.begin(), address.end(), m_address.begin());
58 m_address[layer_offset] = layer.
get();
63 m_address[tree_offset + 0] = 0;
64 m_address[tree_offset + 1] =
static_cast<uint32_t
>(tree.
get() >> 32);
65 m_address[tree_offset + 2] =
static_cast<uint32_t
>(tree.
get());
74 m_address[type_offset] =
static_cast<uint32_t
>(type);
79 m_address[keypair_offset] = keypair.
get();
84 m_address[chain_offset] = chain.
get();
89 m_address[tree_height_offset] = tree_height.
get();
94 m_address[hash_offset] = hash.
get();
99 m_address[tree_index_offset] = tree_index.
get();
106 m_address[layer_offset] = other.m_address[layer_offset];
107 m_address[tree_offset + 0] = other.m_address[tree_offset + 0];
108 m_address[tree_offset + 1] = other.m_address[tree_offset + 1];
109 m_address[tree_offset + 2] = other.m_address[tree_offset + 2];
116 result.copy_subtree_from(other);
121 m_address[layer_offset] = other.m_address[layer_offset];
122 m_address[tree_offset + 0] = other.m_address[tree_offset + 0];
123 m_address[tree_offset + 1] = other.m_address[tree_offset + 1];
124 m_address[tree_offset + 2] = other.m_address[tree_offset + 2];
125 m_address[keypair_offset] = other.m_address[keypair_offset];
132 result.copy_keypair_from(other);
139 std::array<uint8_t,
sizeof(m_address)> result{};
140 for(
unsigned int i = 0; i < m_address.size(); ++i) {
141 store_be(m_address[i], result.data() + (i * 4));
147 std::array<uint8_t, 22> result{};
149 result[0] =
static_cast<uint8_t
>(m_address[layer_offset]);
150 store_be(m_address[tree_offset + 1], &result[1]);
151 store_be(m_address[tree_offset + 2], &result[5]);
152 result[9] =
static_cast<uint8_t
>(m_address[type_offset]);
153 store_be(m_address[keypair_offset], &result[10]);
154 store_be(m_address[chain_offset], &result[14]);
155 store_be(m_address[hash_offset], &result[18]);
161 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)