Botan 3.3.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 XMSS_Parameters xmss_params(oid);
16
17 if(raw_sig.size() !=
18 (xmss_params.len() + xmss_params.tree_height() + 1) * xmss_params.element_size() + sizeof(uint32_t)) {
19 throw Decoding_Error("XMSS signature size invalid.");
20 }
21
22 for(size_t i = 0; i < 4; i++) {
23 m_leaf_idx = ((m_leaf_idx << 8) | raw_sig[i]);
24 }
25
26 if(m_leaf_idx >= xmss_params.total_number_of_signatures()) {
27 throw Decoding_Error("XMSS signature leaf index out of bounds.");
28 }
29
30 auto begin = raw_sig.begin() + sizeof(uint32_t);
31 auto end = begin + xmss_params.element_size();
32 std::copy(begin, end, std::back_inserter(m_randomness));
33
34 for(size_t i = 0; i < xmss_params.len(); i++) {
35 begin = end;
36 end = begin + xmss_params.element_size();
37 m_tree_sig.ots_signature.push_back(secure_vector<uint8_t>(0));
38 m_tree_sig.ots_signature.back().reserve(xmss_params.element_size());
39 std::copy(begin, end, std::back_inserter(m_tree_sig.ots_signature.back()));
40 }
41
42 for(size_t i = 0; i < xmss_params.tree_height(); i++) {
43 begin = end;
44 end = begin + xmss_params.element_size();
45 m_tree_sig.authentication_path.push_back(secure_vector<uint8_t>(0));
46 m_tree_sig.authentication_path.back().reserve(xmss_params.element_size());
47 std::copy(begin, end, std::back_inserter(m_tree_sig.authentication_path.back()));
48 }
49}
50
52 secure_vector<uint8_t> result{static_cast<uint8_t>(m_leaf_idx >> 24U),
53 static_cast<uint8_t>(m_leaf_idx >> 16U),
54 static_cast<uint8_t>(m_leaf_idx >> 8U),
55 static_cast<uint8_t>(m_leaf_idx)};
56
57 std::copy(m_randomness.begin(), m_randomness.end(), std::back_inserter(result));
58
59 for(const auto& sig : tree().ots_signature) {
60 std::copy(sig.begin(), sig.end(), std::back_inserter(result));
61 }
62
63 for(const auto& auth : tree().authentication_path) {
64 std::copy(auth.begin(), auth.end(), std::back_inserter(result));
65 }
66 return result;
67}
68
69} // namespace Botan
size_t total_number_of_signatures() const
size_t element_size() const
const XMSS_Signature::TreeSignature & tree() const
secure_vector< uint8_t > bytes() const
XMSS_Signature(XMSS_Parameters::xmss_algorithm_t oid, const secure_vector< uint8_t > &raw_sig)
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:61