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;
54 Sphincs_Address(std::array<uint32_t, 8> address) { std::copy(address.begin(), address.end(), m_address.begin()); }
59 m_address[layer_offset] = layer.
get();
64 m_address[tree_offset + 0] = 0;
65 m_address[tree_offset + 1] =
static_cast<uint32_t
>(tree.
get() >> 32);
66 m_address[tree_offset + 2] =
static_cast<uint32_t
>(tree.
get());
75 m_address[type_offset] =
static_cast<uint32_t
>(type);
80 m_address[keypair_offset] = keypair.
get();
85 m_address[chain_offset] = chain.
get();
90 m_address[tree_height_offset] = tree_height.
get();
95 m_address[hash_offset] = hash.
get();
100 m_address[tree_index_offset] = tree_index.
get();
107 m_address[layer_offset] = other.m_address[layer_offset];
108 m_address[tree_offset + 0] = other.m_address[tree_offset + 0];
109 m_address[tree_offset + 1] = other.m_address[tree_offset + 1];
110 m_address[tree_offset + 2] = other.m_address[tree_offset + 2];
122 m_address[layer_offset] = other.m_address[layer_offset];
123 m_address[tree_offset + 0] = other.m_address[tree_offset + 0];
124 m_address[tree_offset + 1] = other.m_address[tree_offset + 1];
125 m_address[tree_offset + 2] = other.m_address[tree_offset + 2];
126 m_address[keypair_offset] = other.m_address[keypair_offset];
140 std::array<uint8_t,
sizeof(m_address)> result;
141 for(
unsigned int i = 0; i < m_address.size(); ++i) {
142 store_be(m_address[i], result.data() + (i * 4));
148 std::array<uint8_t, 22> result;
150 result[0] =
static_cast<uint8_t
>(m_address[layer_offset]);
151 store_be(m_address[tree_offset + 1], &result[1]);
152 store_be(m_address[tree_offset + 2], &result[5]);
153 result[9] =
static_cast<uint8_t
>(m_address[type_offset]);
154 store_be(m_address[keypair_offset], &result[10]);
155 store_be(m_address[chain_offset], &result[14]);
156 store_be(m_address[hash_offset], &result[18]);
162 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
int(* final)(unsigned char *, CTX *)
@ ForsTreeRootsCompression
@ WotsPublicKeyCompression
constexpr auto store_be(ParamTs &&... params)