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>
36 static constexpr size_t layer_offset = 0;
37 static constexpr size_t tree_offset = 1;
38 static constexpr size_t type_offset = 4;
39 static constexpr size_t keypair_offset = 5;
40 static constexpr size_t chain_offset = 6;
41 static constexpr size_t hash_offset = 7;
42 static constexpr size_t tree_height_offset = chain_offset;
43 static constexpr size_t tree_index_offset = hash_offset;
53 Sphincs_Address(std::array<uint32_t, 8> address) { 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());
68 m_address[type_offset] =
static_cast<uint32_t
>(type);
75 m_address[keypair_offset] = keypair.
get();
80 m_address[chain_offset] = chain.
get();
85 m_address[hash_offset] = hash.
get();
92 m_address[tree_height_offset] = tree_height.
get();
97 m_address[tree_index_offset] = tree_index.
get();
102 m_address[layer_offset] = other.m_address[layer_offset];
103 m_address[tree_offset + 0] = other.m_address[tree_offset + 0];
104 m_address[tree_offset + 1] = other.m_address[tree_offset + 1];
105 m_address[tree_offset + 2] = other.m_address[tree_offset + 2];
117 m_address[layer_offset] = other.m_address[layer_offset];
118 m_address[tree_offset + 0] = other.m_address[tree_offset + 0];
119 m_address[tree_offset + 1] = other.m_address[tree_offset + 1];
120 m_address[tree_offset + 2] = other.m_address[tree_offset + 2];
121 m_address[keypair_offset] = other.m_address[keypair_offset];
135 std::array<uint8_t,
sizeof(m_address)> result;
136 for(
unsigned int i = 0; i < m_address.size(); ++i) {
137 store_be(m_address[i], result.data() + (i * 4));
143 std::array<uint8_t, 22> result;
145 result[0] =
static_cast<uint8_t
>(m_address[layer_offset]);
146 store_be(m_address[tree_offset + 1], &result[1]);
147 store_be(m_address[tree_offset + 2], &result[5]);
148 result[9] =
static_cast<uint8_t
>(m_address[type_offset]);
149 store_be(m_address[keypair_offset], &result[10]);
150 store_be(m_address[chain_offset], &result[14]);
151 store_be(m_address[hash_offset], &result[18]);
157 std::array<uint32_t, 8> m_address;
Sphincs_Address & set_chain(WotsChainIndex chain)
Sphincs_Address_Type get_type() const
Sphincs_Address & copy_subtree_from(const Sphincs_Address &other)
std::array< uint8_t, 22 > to_bytes_compressed() const
Sphincs_Address & set_layer(HypertreeLayerIndex layer)
Sphincs_Address & set_tree_height(TreeLayerIndex tree_height)
Sphincs_Address & set_keypair(TreeNodeIndex keypair)
Sphincs_Address & set_tree_index(TreeNodeIndex tree_index)
static Sphincs_Address as_subtree_from(const Sphincs_Address &other)
Sphincs_Address & set_hash(WotsHashIndex hash)
Sphincs_Address(Sphincs_Address_Type type)
Sphincs_Address & copy_keypair_from(const Sphincs_Address other)
Sphincs_Address & set_tree(XmssTreeIndexInLayer tree)
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
int(* final)(unsigned char *, CTX *)
@ ForsTreeRootsCompression
@ WotsPublicKeyCompression
constexpr auto store_be(ParamTs &&... params)