Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

xmss_publickey.cpp
Go to the documentation of this file.
1 /*
2 * XMSS Public Key
3 * An XMSS: Extended Hash-Based Siganture public key.
4 * The XMSS public key does not support the X509 standard. Instead the
5 * raw format described in [1] is used.
6 *
7 * [1] XMSS: Extended Hash-Based Signatures,
8 * draft-itrf-cfrg-xmss-hash-based-signatures-06
9 * Release: July 2016.
10 * https://datatracker.ietf.org/doc/
11 * draft-irtf-cfrg-xmss-hash-based-signatures/?include_text=1
12 *
13 * (C) 2016 Matthias Gierlings
14 *
15 * Botan is released under the Simplified BSD License (see license.txt)
16 **/
17
18 #include <botan/internal/xmss_verification_operation.h>
19 #include <botan/xmss_publickey.h>
20
21 namespace Botan {
22
23 XMSS_PublicKey::XMSS_PublicKey(const std::vector<uint8_t>& raw_key)
24 : m_xmss_params(XMSS_PublicKey::deserialize_xmss_oid(raw_key)),
25 m_wots_params(m_xmss_params.ots_oid())
26 {
27 if(raw_key.size() < size())
28 {
29 throw Integrity_Failure("Invalid XMSS public key size detected.");
30 }
31
32 // extract & copy root from raw key.
33 m_root.clear();
34 m_root.reserve(m_xmss_params.element_size());
35 auto begin = raw_key.begin() + sizeof(uint32_t);
36 auto end = begin + m_xmss_params.element_size();
37 std::copy(begin, end, std::back_inserter(m_root));
38
39 // extract & copy public seed from raw key.
40 begin = end;
41 end = begin + m_xmss_params.element_size();
42 m_public_seed.clear();
43 m_public_seed.reserve(m_xmss_params.element_size());
44 std::copy(begin, end, std::back_inserter(m_public_seed));
45 }
46
47 XMSS_Parameters::xmss_algorithm_t
48 XMSS_PublicKey::deserialize_xmss_oid(const std::vector<uint8_t>& raw_key)
49 {
50 if(raw_key.size() < 4)
51 {
52 throw Integrity_Failure("XMSS signature OID missing.");
53 }
54
55 // extract and convert algorithm id to enum type
56 uint32_t raw_id = 0;
57 for(size_t i = 0; i < 4; i++)
58 raw_id = ((raw_id << 8) | raw_key[i]);
59
60 return static_cast<XMSS_Parameters::xmss_algorithm_t>(raw_id);
61 }
62
63 std::unique_ptr<PK_Ops::Verification>
64 XMSS_PublicKey::create_verification_op(const std::string&,
65 const std::string& provider) const
66 {
67 if(provider == "base" || provider.empty())
68 {
69 return std::unique_ptr<PK_Ops::Verification>(
70 new XMSS_Verification_Operation(*this));
71 }
72 throw Provider_Not_Found(algo_name(), provider);
73 }
74
75 std::vector<uint8_t> XMSS_PublicKey::raw_public_key() const
76 {
77 std::vector<uint8_t> result
78 {
79 static_cast<uint8_t>(m_xmss_params.oid() >> 24),
80 static_cast<uint8_t>(m_xmss_params.oid() >> 16),
81 static_cast<uint8_t>(m_xmss_params.oid() >> 8),
82 static_cast<uint8_t>(m_xmss_params.oid())
83 };
84
85 std::copy(m_root.begin(), m_root.end(), std::back_inserter(result));
86 std::copy(m_public_seed.begin(),
87 m_public_seed.end(),
88 std::back_inserter(result));
89
90 return result;
91 }
92
93 }
Botan::XMSS_PublicKey::create_verification_op
virtual std::unique_ptr< PK_Ops::Verification > create_verification_op(const std::string &, const std::string &provider) const override
Definition: xmss_publickey.cpp:64
Botan::XMSS_PublicKey::m_public_seed
secure_vector< uint8_t > m_public_seed
Definition: xmss_publickey.h:253
Botan::XMSS_Verification_Operation
Definition: xmss_verification_operation.h:28
Botan::XMSS_Parameters::element_size
size_t element_size() const
Definition: xmss_parameters.h:72
Botan::XMSS_PublicKey::m_root
secure_vector< uint8_t > m_root
Definition: xmss_publickey.h:252
Botan::XMSS_PublicKey
Definition: xmss_publickey.h:43
Botan::Integrity_Failure
Definition: exceptn.h:198
Botan::XMSS_Parameters::oid
xmss_algorithm_t oid() const
Definition: xmss_parameters.h:89
Botan::XMSS_PublicKey::raw_public_key
virtual std::vector< uint8_t > raw_public_key() const
Definition: xmss_publickey.cpp:75
Botan::XMSS_PublicKey::size
virtual size_t size() const
Definition: xmss_publickey.h:235
Botan
Definition: alg_id.cpp:13
Botan::Provider_Not_Found
Definition: exceptn.h:161
Botan::XMSS_PublicKey::algo_name
std::string algo_name() const override
Definition: xmss_publickey.h:189
Botan::XMSS_PublicKey::XMSS_PublicKey
XMSS_PublicKey(XMSS_Parameters::xmss_algorithm_t xmss_oid, RandomNumberGenerator &rng)
Definition: xmss_publickey.h:55
Botan::XMSS_Parameters::xmss_algorithm_t
xmss_algorithm_t
Definition: xmss_parameters.h:31
Botan::XMSS_PublicKey::m_xmss_params
XMSS_Parameters m_xmss_params
Definition: xmss_publickey.h:250