Botan 3.0.0-alpha0
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 const secure_vector<uint8_t>& raw_sig)
15 : m_leaf_idx(0), m_randomness(0, 0x00), m_tree_sig()
16 {
17 XMSS_Parameters xmss_params(oid);
18
19 if(raw_sig.size() != (xmss_params.len() + xmss_params.tree_height() + 1)
20 * xmss_params.element_size() + sizeof(uint32_t))
21 {
22 throw Decoding_Error("XMSS signature size invalid.");
23 }
24
25 for(size_t i = 0; i < 4; i++)
26 { m_leaf_idx = ((m_leaf_idx << 8) | raw_sig[i]); }
27
28 if(m_leaf_idx >= (1ull << xmss_params.tree_height()))
29 {
30 throw Decoding_Error("XMSS signature leaf index out of bounds.");
31 }
32
33 auto begin = raw_sig.begin() + sizeof(uint32_t);
34 auto end = begin + xmss_params.element_size();
35 std::copy(begin, end, std::back_inserter(m_randomness));
36
37 for(size_t i = 0; i < xmss_params.len(); i++)
38 {
39 begin = end;
40 end = begin + xmss_params.element_size();
41 m_tree_sig.ots_signature().push_back(secure_vector<uint8_t>(0));
42 m_tree_sig.ots_signature().back().reserve(
43 xmss_params.element_size());
44 std::copy(begin,
45 end,
46 std::back_inserter(m_tree_sig.ots_signature().back()));
47 }
48
49 for(size_t i = 0; i < xmss_params.tree_height(); i++)
50 {
51 begin = end;
52 end = begin + xmss_params.element_size();
53 m_tree_sig.authentication_path().push_back(secure_vector<uint8_t>(0));
54 m_tree_sig.authentication_path().back().reserve(
55 xmss_params.element_size());
56 std::copy(begin,
57 end,
58 std::back_inserter(m_tree_sig.authentication_path().back()));
59 }
60 }
61
63 {
65 {
66 static_cast<uint8_t>(m_leaf_idx >> 24U),
67 static_cast<uint8_t>(m_leaf_idx >> 16U),
68 static_cast<uint8_t>(m_leaf_idx >> 8U),
69 static_cast<uint8_t>(m_leaf_idx)
70 };
71
72 std::copy(m_randomness.begin(),
73 m_randomness.end(),
74 std::back_inserter(result));
75
76 for(const auto& sig : tree().ots_signature())
77 {
78 std::copy(sig.begin(),
79 sig.end(),
80 std::back_inserter(result));
81 }
82
83 for(const auto& auth : tree().authentication_path())
84 {
85 std::copy(auth.begin(),
86 auth.end(),
87 std::back_inserter(result));
88 }
89 return result;
90 }
91
92}
size_t tree_height() const
size_t element_size() const
secure_vector< uint8_t > bytes() const
const XMSS_WOTS_PublicKey::TreeSignature & tree() const
XMSS_Signature(XMSS_Parameters::xmss_algorithm_t oid, const secure_vector< uint8_t > &raw_sig)
const wots_keysig_t & ots_signature() const
Definition: xmss_wots.h:148
const wots_keysig_t & authentication_path() const
Definition: xmss_wots.h:158
Definition: alg_id.cpp:13
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:65