Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

xmss_wots_privatekey.cpp
Go to the documentation of this file.
1 /*
2 * XMSS WOTS Private Key
3 * A Winternitz One Time Signature private key for use with Extended Hash-Based
4 * Signatures.
5 *
6 * (C) 2016 Matthias Gierlings
7 *
8 * Botan is released under the Simplified BSD License (see license.txt)
9 **/
10
11 #include <botan/internal/xmss_wots_signature_operation.h>
12 #include <botan/xmss_wots_privatekey.h>
13
14 namespace Botan {
15
16 wots_keysig_t
17 XMSS_WOTS_PrivateKey::generate(const secure_vector<uint8_t>& priv_seed)
18 {
19 wots_keysig_t priv_key(m_wots_params.len(),
20 secure_vector<uint8_t>(0));
21
22 for(size_t i = 0; i < m_wots_params.len(); i++)
23 {
24 XMSS_Tools::concat<size_t>(priv_key[i], i, 32);
25 m_hash.prf(priv_key[i], priv_seed, priv_key[i]);
26 }
27 return priv_key;
28 }
29
30
31 XMSS_WOTS_PublicKey
32 XMSS_WOTS_PrivateKey::generate_public_key(XMSS_Address& adrs)
33 {
34 XMSS_WOTS_PublicKey pub_key(m_wots_params.oid(),
35 public_seed());
36 generate_public_key(pub_key, wots_keysig_t((*this)[adrs]), adrs);
37 return pub_key;
38 }
39
40 void
41 XMSS_WOTS_PrivateKey::generate_public_key(XMSS_WOTS_PublicKey& pub_key,
42 wots_keysig_t&& in_key_data,
43 XMSS_Address& adrs)
44 {
45 BOTAN_ASSERT(wots_parameters() == pub_key.wots_parameters() &&
46 public_seed() == pub_key.public_seed(),
47 "Conflicting public key data.");
48
49 pub_key.set_key_data(std::move(in_key_data));
50 for(size_t i = 0; i < m_wots_params.len(); i++)
51 {
52 adrs.set_chain_address(i);
53 chain(pub_key[i], 0, m_wots_params.wots_parameter() - 1, adrs,
54 public_seed());
55 }
56 }
57
58 wots_keysig_t
59 XMSS_WOTS_PrivateKey::sign(
60 const secure_vector<uint8_t>& msg,
61 XMSS_Address& adrs)
62
63 {
64 secure_vector<uint8_t> msg_digest
65 {
66 m_wots_params.base_w(msg, m_wots_params.len_1())
67 };
68
69 m_wots_params.append_checksum(msg_digest);
70 wots_keysig_t sig((*this)[adrs]);
71
72 for(size_t i = 0; i < m_wots_params.len(); i++)
73 {
74 adrs.set_chain_address(i);
75 chain(sig[i], 0 , msg_digest[i], adrs, m_public_seed);
76 }
77
78 return sig;
79 }
80
81 std::unique_ptr<PK_Ops::Signature>
82 XMSS_WOTS_PrivateKey::create_signature_op(RandomNumberGenerator&,
83 const std::string&,
84 const std::string& provider) const
85 {
86 if(provider == "base" || provider.empty())
87 return std::unique_ptr<PK_Ops::Signature>(
88 new XMSS_WOTS_Signature_Operation(*this));
89
90 throw Provider_Not_Found(algo_name(), provider);
91 }
92
93 }
Botan::RandomNumberGenerator
Definition: rng.h:25
Botan::XMSS_WOTS_PrivateKey::sign
wots_keysig_t sign(const secure_vector< uint8_t > &msg, XMSS_Address &adrs)
Definition: xmss_wots_privatekey.cpp:59
Botan::XMSS_Address
Definition: xmss_address.h:23
Botan::XMSS_WOTS_PublicKey::m_public_seed
secure_vector< uint8_t > m_public_seed
Definition: xmss_wots_publickey.h:305
Botan::XMSS_WOTS_PublicKey::public_seed
const secure_vector< uint8_t > & public_seed() const
Definition: xmss_wots_publickey.h:201
BOTAN_ASSERT
#define BOTAN_ASSERT(expr, assertion_made)
Definition: assert.h:27
Botan::XMSS_WOTS_Parameters::base_w
secure_vector< uint8_t > base_w(const secure_vector< uint8_t > &msg, size_t out_size) const
Definition: xmss_wots_parameters.cpp:91
Botan::secure_vector
std::vector< T, secure_allocator< T >> secure_vector
Definition: secmem.h:121
Botan::XMSS_WOTS_Parameters::len
size_t len() const
Definition: xmss_wots_parameters.h:97
Botan::XMSS_Hash::prf
void prf(secure_vector< uint8_t > &result, const secure_vector< uint8_t > &key, const secure_vector< uint8_t > &data)
Definition: xmss_hash.h:38
Botan::XMSS_WOTS_Parameters::wots_parameter
size_t wots_parameter() const
Definition: xmss_wots_parameters.h:95
Botan::XMSS_WOTS_PublicKey::algo_name
virtual std::string algo_name() const override
Definition: xmss_wots_publickey.h:234
Botan::XMSS_WOTS_PublicKey::m_hash
XMSS_Hash m_hash
Definition: xmss_wots_publickey.h:302
Botan::XMSS_WOTS_PrivateKey::generate_public_key
XMSS_WOTS_PublicKey generate_public_key(XMSS_Address &adrs)
Definition: xmss_wots_privatekey.cpp:32
Botan
Definition: alg_id.cpp:13
Botan::XMSS_Address::set_chain_address
void set_chain_address(uint32_t value)
Definition: xmss_address.h:224
Botan::wots_keysig_t
std::vector< secure_vector< uint8_t > > wots_keysig_t
Definition: xmss_common_ops.h:20
Botan::XMSS_WOTS_Signature_Operation
Definition: xmss_wots_signature_operation.h:28
Botan::Provider_Not_Found
Definition: exceptn.h:161
Botan::XMSS_WOTS_PublicKey::set_key_data
void set_key_data(const wots_keysig_t &key_data)
Definition: xmss_wots_publickey.h:219
Botan::XMSS_WOTS_PublicKey::wots_parameters
const XMSS_WOTS_Parameters & wots_parameters() const
Definition: xmss_wots_publickey.h:229
Botan::XMSS_WOTS_Parameters::append_checksum
void append_checksum(secure_vector< uint8_t > &data)
Definition: xmss_wots_parameters.cpp:124
Botan::XMSS_WOTS_PublicKey
Definition: xmss_wots_publickey.h:32
Botan::XMSS_WOTS_PublicKey::chain
void chain(secure_vector< uint8_t > &x, size_t start_idx, size_t steps, XMSS_Address &adrs, const secure_vector< uint8_t > &public_seed)
Definition: xmss_wots_publickey.cpp:17
Botan::XMSS_WOTS_PrivateKey::create_signature_op
virtual std::unique_ptr< PK_Ops::Signature > create_signature_op(RandomNumberGenerator &, const std::string &, const std::string &provider) const override
Definition: xmss_wots_privatekey.cpp:82
Botan::XMSS_WOTS_Parameters::len_1
size_t len_1() const
Definition: xmss_wots_parameters.h:99
Botan::XMSS_WOTS_Parameters::oid
ots_algorithm_t oid() const
Definition: xmss_wots_parameters.h:105
Botan::XMSS_WOTS_PublicKey::m_wots_params
XMSS_WOTS_Parameters m_wots_params
Definition: xmss_wots_publickey.h:301