Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

xmss_signature.cpp
Go to the documentation of this file.
1 /*
2 * XMSS Signature
3 * (C) 2016 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
10 namespace Botan {
11
12 XMSS_Signature::XMSS_Signature(XMSS_Parameters::xmss_algorithm_t oid,
13 const secure_vector<uint8_t>& raw_sig)
14 : m_leaf_idx(0), m_randomness(0, 0x00), m_tree_sig()
15 {
16 BOTAN_ASSERT(sizeof(size_t) >= ceil(static_cast<float>(
17 (XMSS_Parameters(oid)).tree_height()) / 8.f),
18 "System type \"size_t\" not big enough to support"
19 " leaf index.");
20
21 XMSS_Parameters xmss_params(oid);
22 uint64_t leaf_idx = 0;
23 for(size_t i = 0; i < 8; i++)
24 leaf_idx = ((leaf_idx << 8) | raw_sig[i]);
25
26 if(leaf_idx >= (1ull << (xmss_params.tree_height() - 1)))
27 {
28 throw Integrity_Failure("XMSS signature leaf index out of "
29 "bounds.");
30 }
31 m_leaf_idx = static_cast<size_t>(leaf_idx);
32
33 auto begin = raw_sig.begin() + sizeof(uint64_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
62 secure_vector<uint8_t> XMSS_Signature::bytes() const
63 {
64 secure_vector<uint8_t> result
65 {
66 static_cast<uint8_t>(static_cast<uint64_t>(m_leaf_idx) >> 56U),
67 static_cast<uint8_t>(static_cast<uint64_t>(m_leaf_idx) >> 48U),
68 static_cast<uint8_t>(static_cast<uint64_t>(m_leaf_idx) >> 40U),
69 static_cast<uint8_t>(static_cast<uint64_t>(m_leaf_idx) >> 32U),
70 static_cast<uint8_t>(static_cast<uint64_t>(m_leaf_idx) >> 24U),
71 static_cast<uint8_t>(static_cast<uint64_t>(m_leaf_idx) >> 16U),
72 static_cast<uint8_t>(static_cast<uint64_t>(m_leaf_idx) >> 8U),
73 static_cast<uint8_t>(static_cast<uint64_t>(m_leaf_idx) )
74 };
75
76 std::copy(m_randomness.begin(),
77 m_randomness.end(),
78 std::back_inserter(result));
79
80 for(const auto& sig : tree().ots_signature())
81 {
82 std::copy(sig.begin(),
83 sig.end(),
84 std::back_inserter(result));
85 }
86
87 for(const auto& auth : tree().authentication_path())
88 {
89 std::copy(auth.begin(),
90 auth.end(),
91 std::back_inserter(result));
92 }
93 return result;
94 }
95
96 }
Botan::XMSS_Signature::XMSS_Signature
XMSS_Signature(XMSS_Parameters::xmss_algorithm_t oid, const secure_vector< uint8_t > &raw_sig)
Definition: xmss_signature.cpp:12
Botan::XMSS_Parameters::element_size
size_t element_size() const
Definition: xmss_parameters.h:72
Botan::XMSS_Parameters::tree_height
size_t tree_height() const
Definition: xmss_parameters.h:77
Botan::Integrity_Failure
Definition: exceptn.h:198
Botan::XMSS_Parameters
Definition: xmss_parameters.h:28
BOTAN_ASSERT
#define BOTAN_ASSERT(expr, assertion_made)
Definition: assert.h:27
Botan::secure_vector
std::vector< T, secure_allocator< T >> secure_vector
Definition: secmem.h:121
Botan::XMSS_WOTS_PublicKey::TreeSignature::ots_signature
const wots_keysig_t & ots_signature() const
Definition: xmss_wots_publickey.h:51
Botan
Definition: alg_id.cpp:13
Botan::XMSS_Signature::tree
const XMSS_WOTS_PublicKey::TreeSignature & tree() const
Definition: xmss_signature.h:86
Botan::XMSS_Parameters::len
size_t len() const
Definition: xmss_parameters.h:87
Botan::XMSS_Parameters::xmss_algorithm_t
xmss_algorithm_t
Definition: xmss_parameters.h:31
Botan::XMSS_Signature::bytes
secure_vector< uint8_t > bytes() const
Definition: xmss_signature.cpp:62
Botan::XMSS_WOTS_PublicKey::TreeSignature::authentication_path
const wots_keysig_t & authentication_path() const
Definition: xmss_wots_publickey.h:61