70 std::span<uint8_t> pks,
71 std::span<XMSS_Address> addrs,
72 std::span<const uint8_t> seed,
76 const size_t count = addrs.size();
77 const size_t n = element_size;
78 const size_t stride = wots_len * n;
87 const size_t adrs_len = addrs[0].size();
89 for(
auto& adrs : addrs) {
90 adrs.set_tree_height(0);
96 const size_t max_pairs = count * (wots_len / 2);
97 std::vector<uint8_t> adrs_buf(3 * max_pairs * adrs_len);
101 std::vector<std::span<uint8_t>> prf_outs(3 * max_pairs);
102 std::vector<std::span<const uint8_t>> prf_ins(3 * max_pairs);
103 std::vector<std::span<uint8_t>> h_outs(max_pairs);
104 std::vector<std::span<const uint8_t>> h_keys(max_pairs);
105 std::vector<std::span<const uint8_t>> h_ins(max_pairs);
107 const auto node = [&](
size_t k,
size_t i) {
return pks.subspan(k * stride + i * n, n); };
112 const size_t pairs = l >> 1;
113 const size_t total = count * pairs;
118 for(
size_t k = 0; k < count; k++) {
119 for(
size_t i = 0; i < pairs; i++) {
120 const size_t p = k * pairs + i;
121 addrs[k].set_tree_index(
static_cast<uint32_t
>(i));
123 addrs[k].set_key_mask_mode(mode);
124 const auto dest = std::span(adrs_buf).subspan(lane * adrs_len, adrs_len);
126 prf_ins[lane] = dest;
132 prf_outs[3 * p] = std::span(keys).subspan(p * n, n);
133 prf_outs[3 * p + 1] = std::span(
concat).subspan(p * 2 * n, n);
134 prf_outs[3 * p + 2] = std::span(
concat).subspan(p * 2 * n + n, n);
137 hash.
prf_batch(std::span(prf_outs).first(3 * total), seed, std::span(prf_ins).first(3 * total));
139 for(
size_t k = 0; k < count; k++) {
140 for(
size_t i = 0; i < pairs; i++) {
141 const size_t p = k * pairs + i;
142 xor_buf(std::span(
concat).subspan(p * 2 * n, n), node(k, 2 * i));
143 xor_buf(std::span(
concat).subspan(p * 2 * n + n, n), node(k, 2 * i + 1));
144 h_outs[p] = node(k, i);
145 h_keys[p] = std::span(keys).subspan(p * n, n);
146 h_ins[p] = std::span(
concat).subspan(p * 2 * n, 2 * n);
149 hash.
h_batch(std::span(h_outs).first(total), std::span(h_keys).first(total), std::span(h_ins).first(total));
151 if((l & 0x01) == 0x01) {
152 for(
size_t k = 0; k < count; k++) {
153 copy_mem(node(k, l >> 1), node(k, l - 1));
156 l = (l >> 1) + (l & 0x01);
157 for(
auto& adrs : addrs) {
158 adrs.set_tree_height(adrs.get_tree_height() + 1);
162 for(
size_t k = 0; k < count; k++) {
163 copy_mem(leaves.subspan(k * n, n), node(k, 0));
174 size_t tree_height) {
185 std::array<secure_vector<uint8_t>, 2> node;
191 for(
size_t k = 0; k < tree_height; k++) {
193 if(((idx_leaf / (
static_cast<size_t>(1) << k)) & 0x01) == 0) {
static void create_l_tree(secure_vector< uint8_t > &result, const wots_keysig_t &pk, XMSS_Address adrs, const secure_vector< uint8_t > &seed, XMSS_Hash &hash, size_t element_size, size_t wots_len)
static void create_l_trees(std::span< uint8_t > leaves, std::span< uint8_t > pks, std::span< XMSS_Address > addrs, std::span< const uint8_t > seed, XMSS_Hash &hash, size_t element_size, size_t wots_len)
static secure_vector< uint8_t > root_from_signature(uint32_t idx_leaf, const XMSS_TreeSignature &tree_sig, const secure_vector< uint8_t > &msg, XMSS_Address adrs, const secure_vector< uint8_t > &seed, XMSS_Hash &hash, const XMSS_WOTS_Parameters &wots_params, size_t tree_height)
static void randomize_tree_hash(secure_vector< uint8_t > &result, const secure_vector< uint8_t > &left, const secure_vector< uint8_t > &right, XMSS_Address adrs, const secure_vector< uint8_t > &seed, XMSS_Hash &hash, size_t element_size)