Botan 2.13.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,2017 Matthias Gierlings
7 *
8 * Botan is released under the Simplified BSD License (see license.txt)
9 **/
10
11 #include <botan/xmss_wots_privatekey.h>
12
13 namespace Botan {
14
15 wots_keysig_t
16 XMSS_WOTS_PrivateKey::generate(const secure_vector<uint8_t>& priv_seed,
17 XMSS_Hash& hash)
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 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 XMSS_Hash& hash)
45 {
46 BOTAN_ASSERT(wots_parameters() == pub_key.wots_parameters() &&
47 public_seed() == pub_key.public_seed(),
48 "Conflicting public key data.");
49
50 pub_key.set_key_data(std::move(in_key_data));
51 for(size_t i = 0; i < m_wots_params.len(); i++)
52 {
53 adrs.set_chain_address(static_cast<uint32_t>(i));
54 chain(pub_key[i], 0, m_wots_params.wots_parameter() - 1, adrs,
55 public_seed(), hash);
56 }
57 }
58
59 wots_keysig_t
60 XMSS_WOTS_PrivateKey::sign(const secure_vector<uint8_t>& msg,
61 XMSS_Address& adrs,
62 XMSS_Hash& hash)
63
64 {
65 secure_vector<uint8_t> msg_digest
66 {
67 m_wots_params.base_w(msg, m_wots_params.len_1())
68 };
69
70 m_wots_params.append_checksum(msg_digest);
71 wots_keysig_t sig(this->at(adrs, hash));
72
73 for(size_t i = 0; i < m_wots_params.len(); i++)
74 {
75 adrs.set_chain_address(static_cast<uint32_t>(i));
76 chain(sig[i], 0 , msg_digest[i], adrs, m_public_seed, hash);
77 }
78
79 return sig;
80 }
81
82 }
Botan::XMSS_Hash
Definition: xmss_hash.h:21
Botan::XMSS_WOTS_PrivateKey::sign
wots_keysig_t sign(const secure_vector< uint8_t > &msg, XMSS_Address &adrs)
Definition: xmss_wots_privatekey.h:236
Botan::XMSS_Address
Definition: xmss_address.h:21
Botan::XMSS_WOTS_PublicKey::m_public_seed
secure_vector< uint8_t > m_public_seed
Definition: xmss_wots_publickey.h:328
Botan::XMSS_WOTS_PrivateKey::at
wots_keysig_t at(size_t i, XMSS_Hash &hash)
Definition: xmss_wots_privatekey.h:124
Botan::XMSS_WOTS_PublicKey::public_seed
const secure_vector< uint8_t > & public_seed() const
Definition: xmss_wots_publickey.h:201
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, XMSS_Hash &hash)
Definition: xmss_wots_publickey.cpp:16
BOTAN_ASSERT
#define BOTAN_ASSERT(expr, assertion_made)
Definition: assert.h:55
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:90
Botan::secure_vector
std::vector< T, secure_allocator< T >> secure_vector
Definition: secmem.h:65
Botan::XMSS_WOTS_Parameters::len
size_t len() const
Definition: xmss_wots_parameters.h:89
Botan::XMSS_WOTS_Parameters::wots_parameter
size_t wots_parameter() const
Definition: xmss_wots_parameters.h:87
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:220
Botan::wots_keysig_t
std::vector< secure_vector< uint8_t > > wots_keysig_t
Definition: xmss_common_ops.h:21
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:123
Botan::XMSS_WOTS_PublicKey
Definition: xmss_wots_publickey.h:32
Botan::XMSS_WOTS_Parameters::len_1
size_t len_1() const
Definition: xmss_wots_parameters.h:91
Botan::XMSS_WOTS_Parameters::oid
ots_algorithm_t oid() const
Definition: xmss_wots_parameters.h:97
hash
MechanismType hash
Definition: p11_mechanism.cpp:64
Botan::XMSS_WOTS_PublicKey::m_wots_params
XMSS_WOTS_Parameters m_wots_params
Definition: xmss_wots_publickey.h:325