Botan 3.12.0
Crypto and TLS for C&
xmss_signature.cpp
Go to the documentation of this file.
1/*
2 * XMSS Signature
3 * (C) 2016,2017,2018 Matthias Gierlings
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 **/
7
8#include <botan/internal/xmss_signature.h>
9#include <iterator>
10
11namespace Botan {
12
14 m_leaf_idx(0), m_randomness(0, 0x00) {
15 const auto params = XMSS_Parameters::from_id(oid);
16
17 if(raw_sig.size() != (params.len() + params.tree_height() + 1) * params.element_size() + sizeof(uint32_t)) {
18 throw Decoding_Error("XMSS signature size invalid.");
19 }
20
21 for(size_t i = 0; i < 4; i++) {
22 m_leaf_idx = ((m_leaf_idx << 8) | raw_sig[i]);
23 }
24
25 if(m_leaf_idx >= params.total_number_of_signatures()) {
26 throw Decoding_Error("XMSS signature leaf index out of bounds.");
27 }
28
29 auto begin = raw_sig.begin() + sizeof(uint32_t);
30 auto end = begin + params.element_size();
31 std::copy(begin, end, std::back_inserter(m_randomness));
32
33 for(size_t i = 0; i < params.len(); i++) {
34 begin = end;
35 end = begin + params.element_size();
36 m_tree_sig.ots_signature.push_back(secure_vector<uint8_t>(0));
37 m_tree_sig.ots_signature.back().reserve(params.element_size());
38 std::copy(begin, end, std::back_inserter(m_tree_sig.ots_signature.back()));
39 }
40
41 for(size_t i = 0; i < params.tree_height(); i++) {
42 begin = end;
43 end = begin + params.element_size();
44 m_tree_sig.authentication_path.push_back(secure_vector<uint8_t>(0));
45 m_tree_sig.authentication_path.back().reserve(params.element_size());
46 std::copy(begin, end, std::back_inserter(m_tree_sig.authentication_path.back()));
47 }
48}
49
50std::vector<uint8_t> XMSS_Signature::bytes() const {
51 std::vector<uint8_t> result{static_cast<uint8_t>(m_leaf_idx >> 24U),
52 static_cast<uint8_t>(m_leaf_idx >> 16U),
53 static_cast<uint8_t>(m_leaf_idx >> 8U),
54 static_cast<uint8_t>(m_leaf_idx)};
55
56 std::copy(m_randomness.begin(), m_randomness.end(), std::back_inserter(result));
57
58 for(const auto& sig : tree().ots_signature) {
59 std::copy(sig.begin(), sig.end(), std::back_inserter(result));
60 }
61
62 for(const auto& auth : tree().authentication_path) {
63 std::copy(auth.begin(), auth.end(), std::back_inserter(result));
64 }
65 return result;
66}
67
68} // namespace Botan
static XMSS_Parameters from_id(xmss_algorithm_t id)
const XMSS_Signature::TreeSignature & tree() const
XMSS_Signature(XMSS_Parameters::xmss_algorithm_t oid, std::span< const uint8_t > raw_sig)
std::vector< uint8_t > bytes() const
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:68