Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Botan::XMSS_PrivateKey Class Reference

`#include <xmss_privatekey.h>`

Inheritance diagram for Botan::XMSS_PrivateKey:

## Public Member Functions
std::string | algo_name () const override
virtual AlgorithmIdentifier | algorithm_identifier () const override
virtual bool | check_key (RandomNumberGenerator &, bool) const override
virtual std::unique_ptr< PK_Ops::Decryption > | create_decryption_op (RandomNumberGenerator &rng, const std::string &params, const std::string &provider) const
virtual std::unique_ptr< PK_Ops::Encryption > | create_encryption_op (RandomNumberGenerator &rng, const std::string &params, const std::string &provider) const
virtual std::unique_ptr< PK_Ops::KEM_Decryption > | create_kem_decryption_op (RandomNumberGenerator &rng, const std::string &params, const std::string &provider) const
virtual std::unique_ptr< PK_Ops::KEM_Encryption > | create_kem_encryption_op (RandomNumberGenerator &rng, const std::string &params, const std::string &provider) const
virtual std::unique_ptr< PK_Ops::Key_Agreement > | create_key_agreement_op (RandomNumberGenerator &rng, const std::string &params, const std::string &provider) const
virtual std::unique_ptr< PK_Ops::Signature > | create_signature_op (RandomNumberGenerator &, const std::string &, const std::string &provider) const override
virtual std::unique_ptr< PK_Ops::Verification > | create_verification_op (const std::string &, const std::string &provider) const override
virtual size_t | estimated_strength () const override
std::string | fingerprint (const std::string &alg="SHA") const
virtual OID | get_oid () const
virtual size_t | key_length () const override
virtual size_t | message_part_size () const
virtual size_t | message_parts () const
virtual AlgorithmIdentifier | pkcs8_algorithm_identifier () const
const secure_vector< uint8_t > & | prf () const
secure_vector< uint8_t > & | prf ()
virtual secure_vector< uint8_t > | private_key_bits () const override
secure_vector< uint8_t > | private_key_info () const
virtual std::vector< uint8_t > | public_key_bits () const override
virtual secure_vector< uint8_t > & | public_seed ()
virtual const secure_vector< uint8_t > & | public_seed () const override
virtual secure_vector< uint8_t > | raw_private_key () const
virtual std::vector< uint8_t > | raw_public_key () const
size_t | reserve_unused_leaf_index ()
secure_vector< uint8_t > & | root ()
const secure_vector< uint8_t > & | root () const
virtual void | set_public_seed (const secure_vector< uint8_t > &public_seed) override
virtual void | set_public_seed (secure_vector< uint8_t > &&public_seed) override
void | set_root (const secure_vector< uint8_t > &root)
void | set_root (secure_vector< uint8_t > &&root)
void | set_unused_leaf_index (size_t idx)
void | set_xmss_oid (XMSS_Parameters::xmss_algorithm_t xmss_oid)
virtual size_t | size () const override
std::vector< uint8_t > | subject_public_key () const
secure_vector< uint8_t > | tree_hash (size_t start_idx, size_t target_node_height, XMSS_Address &adrs)
size_t | unused_leaf_index () const
XMSS_WOTS_Parameters::ots_algorithm_t | wots_oid () const
const XMSS_WOTS_Parameters & | wots_parameters () const
const XMSS_WOTS_PrivateKey & | wots_private_key () const
XMSS_WOTS_PrivateKey & | wots_private_key ()
XMSS_Parameters::xmss_algorithm_t | xmss_oid () const
const XMSS_Parameters & | xmss_parameters () const
| XMSS_PrivateKey (XMSS_Parameters::xmss_algorithm_t xmss_algo_id, RandomNumberGenerator &rng)
| XMSS_PrivateKey (const secure_vector< uint8_t > &raw_key)
| XMSS_PrivateKey (XMSS_Parameters::xmss_algorithm_t xmss_algo_id, size_t idx_leaf, const secure_vector< uint8_t > &wots_priv_seed, const secure_vector< uint8_t > &prf, const secure_vector< uint8_t > &root, const secure_vector< uint8_t > &public_seed)

## Protected Member Functions
void | create_l_tree (secure_vector< uint8_t > &result, wots_keysig_t pk, XMSS_Address &adrs, const secure_vector< uint8_t > &seed)
void | randomize_tree_hash (secure_vector< uint8_t > &result, const secure_vector< uint8_t > &left, const secure_vector< uint8_t > &right, XMSS_Address &adrs, const secure_vector< uint8_t > &seed)

## Protected Attributes
XMSS_Hash | m_hash
secure_vector< uint8_t > | m_public_seed
secure_vector< uint8_t > | m_root
XMSS_WOTS_Parameters | m_wots_params
XMSS_Parameters | m_xmss_params
XMSS_Parameters | m_xmss_params

## Detailed Description

An XMSS: Extended Hash-Based Signature private key. The XMSS private key does not support the X509 and PKCS7 standard. Instead the raw format described in [1] is used.

[1] XMSS: Extended Hash-Based Signatures, draft-itrf-cfrg-xmss-hash-based-signatures-06 Release: July 2016. https://datatracker.ietf.org/doc/ draft-irtf-cfrg-xmss-hash-based-signatures/?include_text=1

Definition at line 40 of file xmss_privatekey.h.

## Constructor & Destructor Documentation

Botan::XMSS_PrivateKey::XMSS_PrivateKey | ( | XMSS_Parameters::xmss_algorithm_t | xmss_algo_id,
|  | RandomNumberGenerator & | rng
| ) |  |

Creates a new XMSS private key for the chosen XMSS signature method. New seeds for public/private key and pseudo random function input are generated using the provided RNG. The appropriate WOTS signature method will be automatically set based on the chosen XMSS signature method.

Parameters

  xmss_algo_id | Identifier for the selected XMSS signature method.
  rng | A random number generator to use for key generation.

Definition at line 65 of file xmss_privatekey.cpp.

References Botan::XMSS_PublicKey::m_xmss_params, Botan::XMSS_PublicKey::set_root(), and tree_hash().

68 : XMSS_PublicKey(xmss_algo_id, rng),
69 XMSS_Common_Ops(xmss_algo_id),
70 m_wots_priv_key(XMSS_PublicKey::m_xmss_params.ots_oid(),
71 public_seed(),
72 rng),
73 m_prf(rng.random_vec(XMSS_PublicKey::m_xmss_params.element_size())),
74 m_index_reg(XMSS_Index_Registry::get_instance())
75 {
76 XMSS_Address adrs;
77 set_root(tree_hash(0,
78 XMSS_PublicKey::m_xmss_params.tree_height(),
79 adrs));
80 }
Botan::XMSS_Common_Ops::XMSS_Common_Ops
XMSS_Common_Ops(XMSS_Parameters::xmss_algorithm_t oid)
Definition: xmss_common_ops.h:28
Botan::XMSS_PrivateKey::tree_hash
secure_vector< uint8_t > tree_hash(size_t start_idx, size_t target_node_height, XMSS_Address &adrs)
Definition: xmss_privatekey.cpp:83
Botan::XMSS_Parameters::element_size
size_t element_size() const
Definition: xmss_parameters.h:72
Botan::XMSS_PrivateKey::public_seed
virtual const secure_vector< uint8_t > & public_seed() const override
Definition: xmss_privatekey.h:196
Botan::XMSS_PublicKey::set_root
void set_root(const secure_vector< uint8_t > &root)
Definition: xmss_publickey.h:154
Botan::XMSS_PublicKey::XMSS_PublicKey
XMSS_PublicKey(XMSS_Parameters::xmss_algorithm_t xmss_oid, RandomNumberGenerator &rng)
Definition: xmss_publickey.h:55
Botan::XMSS_PublicKey::m_xmss_params
XMSS_Parameters m_xmss_params
Definition: xmss_publickey.h:250
Botan::XMSS_Index_Registry::get_instance
static XMSS_Index_Registry & get_instance()
Definition: xmss_index_registry.h:39

Botan::XMSS_PrivateKey::XMSS_PrivateKey | ( | const secure_vector< uint8_t > & | raw_key | ) |

Creates an XMSS_PrivateKey from a byte sequence produced by raw_private_key().

Parameters

  raw_key | An XMSS private key serialized using raw_private_key().

Definition at line 23 of file xmss_privatekey.cpp.

References BOTAN_ASSERT, Botan::XMSS_Parameters::element_size(), Botan::XMSS_WOTS_Parameters::element_size(), Botan::XMSS_PublicKey::m_wots_params, Botan::XMSS_PublicKey::m_xmss_params, Botan::XMSS_WOTS_PrivateKey::set_private_seed(), set_unused_leaf_index(), size(), and Botan::XMSS_PublicKey::size().

24 : XMSS_PublicKey(unlock(raw_key)),
25 XMSS_Common_Ops(XMSS_PublicKey::m_xmss_params.oid()),
26 m_wots_priv_key(m_wots_params.oid(), m_public_seed),
27 m_index_reg(XMSS_Index_Registry::get_instance())
28 {
29 BOTAN_ASSERT(sizeof(size_t) >= ceil(
30 static_cast<float>(XMSS_PublicKey::m_xmss_params.tree_height()) / 8.f),
31 "System type \"size_t\" not big enough to support"
32 " leaf index.");
33
34 if(raw_key.size() != size())
35 {
36 throw Integrity_Failure("Invalid XMSS private key size detected.");
37 }
38
39 // extract & copy unused leaf index from raw_key.
40 uint64_t unused_leaf = 0;
41 auto begin = (raw_key.begin() + XMSS_PublicKey::size());
42 auto end = raw_key.begin() + XMSS_PublicKey::size() + sizeof(uint64_t);
43
44 for(auto& i = begin; i != end; i++)
45 unused_leaf = ((unused_leaf << 8) | *i);
46
47 if(unused_leaf >= (1ull << (XMSS_PublicKey::m_xmss_params.tree_height() - 1)))
48 {
49 throw Integrity_Failure("XMSS private key leaf index out of "
50 "bounds.");
51 }
52
53 begin = end;
54 end = begin + XMSS_PublicKey::m_xmss_params.element_size();
55 m_prf.clear();
56 m_prf.reserve(XMSS_PublicKey::m_xmss_params.element_size());
57 std::copy(begin, end, std::back_inserter(m_prf));
58
59 begin = end;
60 end = begin + m_wots_params.element_size();
61 m_wots_priv_key.set_private_seed(secure_vector<uint8_t>(begin, end));
62 set_unused_leaf_index(static_cast<size_t>(unused_leaf));
63 }
Botan::XMSS_PublicKey::m_public_seed
secure_vector< uint8_t > m_public_seed
Definition: xmss_publickey.h:253
Botan::XMSS_Common_Ops::XMSS_Common_Ops
XMSS_Common_Ops(XMSS_Parameters::xmss_algorithm_t oid)
Definition: xmss_common_ops.h:28
Botan::XMSS_Parameters::element_size
size_t element_size() const
Definition: xmss_parameters.h:72
Botan::XMSS_PrivateKey::set_unused_leaf_index
void set_unused_leaf_index(size_t idx)
Definition: xmss_privatekey.h:116
Botan::XMSS_WOTS_Parameters::element_size
size_t element_size() const
Definition: xmss_wots_parameters.h:87
BOTAN_ASSERT
#define BOTAN_ASSERT(expr, assertion_made)
Definition: assert.h:27
Botan::XMSS_PublicKey::size
virtual size_t size() const
Definition: xmss_publickey.h:235
Botan::XMSS_PrivateKey::size
virtual size_t size() const override
Definition: xmss_privatekey.h:211
Botan::unlock
std::vector< T > unlock(const secure_vector< T > &in)
Definition: secmem.h:125
Botan::XMSS_PublicKey::XMSS_PublicKey
XMSS_PublicKey(XMSS_Parameters::xmss_algorithm_t xmss_oid, RandomNumberGenerator &rng)
Definition: xmss_publickey.h:55
Botan::XMSS_PublicKey::m_wots_params
XMSS_WOTS_Parameters m_wots_params
Definition: xmss_publickey.h:251
Botan::XMSS_WOTS_PrivateKey::set_private_seed
void set_private_seed(const secure_vector< uint8_t > &private_seed)
Definition: xmss_wots_privatekey.h:202
Botan::XMSS_PublicKey::m_xmss_params
XMSS_Parameters m_xmss_params
Definition: xmss_publickey.h:250
Botan::XMSS_Index_Registry::get_instance
static XMSS_Index_Registry & get_instance()
Definition: xmss_index_registry.h:39
Botan::XMSS_WOTS_Parameters::oid
ots_algorithm_t oid() const
Definition: xmss_wots_parameters.h:105

Botan::XMSS_PrivateKey::XMSS_PrivateKey | ( | XMSS_Parameters::xmss_algorithm_t | xmss_algo_id,
|  | size_t | idx_leaf,
|  | const secure_vector< uint8_t > & | wots_priv_seed,
|  | const secure_vector< uint8_t > & | prf,
|  | const secure_vector< uint8_t > & | root,
|  | const secure_vector< uint8_t > & | public_seed
| ) |  |
| inline

Creates a new XMSS private key for the chosen XMSS signature method using precomputed seeds for public/private keys and pseudo random function input. The appropriate WOTS signature method will be automatically set, based on the chosen XMSS signature method.

Parameters

  xmss_algo_id | Identifier for the selected XMSS signature method.
  idx_leaf | Index of the next unused leaf.
  wots_priv_seed | A seed to generate a Winternitz-One-Time- Signature private key from.
  prf | a secret n-byte key sourced from a secure source of uniformly random data.
  root | Root node of the binary hash tree.
  public_seed | The public seed.

Definition at line 80 of file xmss_privatekey.h.

86 : XMSS_PublicKey(xmss_algo_id, root, public_seed),
87 XMSS_Common_Ops(xmss_algo_id),
88 m_wots_priv_key(XMSS_PublicKey::m_xmss_params.ots_oid(),
89 public_seed,
90 wots_priv_seed),
91 m_prf(prf),
92 m_index_reg(XMSS_Index_Registry::get_instance())
93 {
94 set_unused_leaf_index(idx_leaf);
95 }
Botan::XMSS_Common_Ops::XMSS_Common_Ops
XMSS_Common_Ops(XMSS_Parameters::xmss_algorithm_t oid)
Definition: xmss_common_ops.h:28
Botan::XMSS_PrivateKey::public_seed
virtual const secure_vector< uint8_t > & public_seed() const override
Definition: xmss_privatekey.h:196
Botan::XMSS_PrivateKey::set_unused_leaf_index
void set_unused_leaf_index(size_t idx)
Definition: xmss_privatekey.h:116
Botan::XMSS_PublicKey::root
secure_vector< uint8_t > & root()
Definition: xmss_publickey.h:149
Botan::XMSS_PrivateKey::prf
const secure_vector< uint8_t > & prf() const
Definition: xmss_privatekey.h:173
Botan::XMSS_PublicKey::XMSS_PublicKey
XMSS_PublicKey(XMSS_Parameters::xmss_algorithm_t xmss_oid, RandomNumberGenerator &rng)
Definition: xmss_publickey.h:55
Botan::XMSS_PublicKey::m_xmss_params
XMSS_Parameters m_xmss_params
Definition: xmss_publickey.h:250
Botan::XMSS_Index_Registry::get_instance
static XMSS_Index_Registry & get_instance()
Definition: xmss_index_registry.h:39

## Member Function Documentation

std::string Botan::XMSS_PublicKey::algo_name | ( |  | ) | const
| inline override virtual inherited

Get the name of the underlying public key scheme.

Returns
  name of the public key scheme

Implements Botan::Public_Key.

Definition at line 189 of file xmss_publickey.h.

Referenced by create_signature_op(), and Botan::XMSS_PublicKey::create_verification_op().

190 {
191 return "XMSS";
192 }

virtual AlgorithmIdentifier Botan::XMSS_PublicKey::algorithm_identifier | ( |  | ) | const
| inline override virtual inherited

Returns
  X.509 AlgorithmIdentifier for this key

Implements Botan::Public_Key.

Definition at line 194 of file xmss_publickey.h.

References Botan::AlgorithmIdentifier::USE_NULL_PARAM.

195 {
196 return AlgorithmIdentifier(get_oid(), AlgorithmIdentifier::USE_NULL_PARAM);
197 }
Botan::Public_Key::get_oid
virtual OID get_oid() const
Definition: pk_keys.cpp:30
Botan::AlgorithmIdentifier::USE_NULL_PARAM
Definition: alg_id.h:23

virtual bool Botan::XMSS_PublicKey::check_key | ( | RandomNumberGenerator & | rng,
|  | bool | strong
| ) |  | const
| inline override virtual inherited

Test the key values for consistency.

Parameters

  rng | rng to use
  strong | whether to perform strong and lengthy version of the test

Returns
  true if the test is passed

Implements Botan::Public_Key.

Definition at line 199 of file xmss_publickey.h.

200 {
201 return true;
202 }

std::unique_ptr< PK_Ops::Decryption > Botan::Private_Key::create_decryption_op | ( | RandomNumberGenerator & | rng,
|  | const std::string & | params,
|  | const std::string & | provider
| ) |  | const
| virtual inherited

This is an internal library function exposed on key types. In almost all cases applications should use wrappers in pubkey.h

Return an decryption operation for this key/params or throw

Parameters

  rng | a random number generator. The PK_Op may maintain a reference to the RNG and use it many times. The rng must outlive any operations which reference it.
  params | additional parameters
  provider | the provider to use

Reimplemented in Botan::RSA_PrivateKey, and Botan::ElGamal_PrivateKey.

Definition at line 102 of file pk_keys.cpp.

References Botan::Public_Key::algo_name().

Referenced by Botan::PK_Decryptor_EME::PK_Decryptor_EME().

105 {
106 throw Lookup_Error(algo_name() + " does not support decryption");
107 }
Botan::Public_Key::algo_name
virtual std::string algo_name() const =0

std::unique_ptr< PK_Ops::Encryption > Botan::Public_Key::create_encryption_op | ( | RandomNumberGenerator & | rng,
|  | const std::string & | params,
|  | const std::string & | provider
| ) |  | const
| virtual inherited

This is an internal library function exposed on key types. In almost all cases applications should use wrappers in pubkey.h

Return an encryption operation for this key/params or throw

Parameters

  rng | a random number generator. The PK_Op may maintain a reference to the RNG and use it many times. The rng must outlive any operations which reference it.
  params | additional parameters
  provider | the provider to use

Reimplemented in Botan::RSA_PublicKey, and Botan::ElGamal_PublicKey.

Definition at line 79 of file pk_keys.cpp.

References Botan::Public_Key::algo_name().

Referenced by Botan::PK_Encryptor_EME::PK_Encryptor_EME().

82 {
83 throw Lookup_Error(algo_name() + " does not support encryption");
84 }
Botan::Public_Key::algo_name
virtual std::string algo_name() const =0

std::unique_ptr< PK_Ops::KEM_Decryption > Botan::Private_Key::create_kem_decryption_op | ( | RandomNumberGenerator & | rng,
|  | const std::string & | params,
|  | const std::string & | provider
| ) |  | const
| virtual inherited

This is an internal library function exposed on key types. In almost all cases applications should use wrappers in pubkey.h

Return a KEM decryption operation for this key/params or throw

Parameters

  rng | a random number generator. The PK_Op may maintain a reference to the RNG and use it many times. The rng must outlive any operations which reference it.
  params | additional parameters
  provider | the provider to use

Reimplemented in Botan::RSA_PrivateKey, and Botan::McEliece_PrivateKey.

Definition at line 110 of file pk_keys.cpp.

References Botan::Public_Key::algo_name().

Referenced by Botan::PK_KEM_Decryptor::PK_KEM_Decryptor().

113 {
114 throw Lookup_Error(algo_name() + " does not support KEM decryption");
115 }
Botan::Public_Key::algo_name
virtual std::string algo_name() const =0

std::unique_ptr< PK_Ops::KEM_Encryption > Botan::Public_Key::create_kem_encryption_op | ( | RandomNumberGenerator & | rng,
|  | const std::string & | params,
|  | const std::string & | provider
| ) |  | const
| virtual inherited

This is an internal library function exposed on key types. In almost all cases applications should use wrappers in pubkey.h

Return a KEM encryption operation for this key/params or throw

Parameters

  rng | a random number generator. The PK_Op may maintain a reference to the RNG and use it many times. The rng must outlive any operations which reference it.
  params | additional parameters
  provider | the provider to use

Reimplemented in Botan::RSA_PublicKey, and Botan::McEliece_PublicKey.

Definition at line 87 of file pk_keys.cpp.

References Botan::Public_Key::algo_name().

Referenced by Botan::PK_KEM_Encryptor::PK_KEM_Encryptor().

90 {
91 throw Lookup_Error(algo_name() + " does not support KEM encryption");
92 }
Botan::Public_Key::algo_name
virtual std::string algo_name() const =0

std::unique_ptr< PK_Ops::Key_Agreement > Botan::Private_Key::create_key_agreement_op | ( | RandomNumberGenerator & | rng,
|  | const std::string & | params,
|  | const std::string & | provider
| ) |  | const
| virtual inherited

This is an internal library function exposed on key types. In almost all cases applications should use wrappers in pubkey.h

Return a key agreement operation for this key/params or throw

Parameters

  rng | a random number generator. The PK_Op may maintain a reference to the RNG and use it many times. The rng must outlive any operations which reference it.
  params | additional parameters
  provider | the provider to use

Reimplemented in Botan::ECDH_PrivateKey, Botan::Curve25519_PrivateKey, and Botan::DH_PrivateKey.

Definition at line 126 of file pk_keys.cpp.

References Botan::Public_Key::algo_name().

Referenced by Botan::PK_Key_Agreement::PK_Key_Agreement().

129 {
130 throw Lookup_Error(algo_name() + " does not support key agreement");
131 }
Botan::Public_Key::algo_name
virtual std::string algo_name() const =0

void Botan::XMSS_Common_Ops::create_l_tree | ( | secure_vector< uint8_t > & | result,
|  | wots_keysig_t | pk,
|  | XMSS_Address & | adrs,
|  | const secure_vector< uint8_t > & | seed
| ) |  |
| protected inherited

Algorithm 8: "ltree" Create an L-tree used to compute the leaves of the binary hash tree. Takes a WOTS+ public key and compresses it to a single n-byte value.

Parameters

  [out] | result | Public key compressed to a single n-byte value pk[0].
  [in] | pk | Winternitz One Time Signatures+ public key.
  [in] | adrs | Address encoding the address of the L-Tree
  [in] | seed | The seed generated during the public key generation.

Definition at line 45 of file xmss_common_ops.cpp.

References Botan::XMSS_Address::get_tree_height(), Botan::XMSS_Parameters::len(), Botan::XMSS_Common_Ops::m_xmss_params, Botan::XMSS_Common_Ops::randomize_tree_hash(), Botan::XMSS_Address::set_tree_height(), and Botan::XMSS_Address::set_tree_index().

Referenced by tree_hash().

49 {
50 size_t l = m_xmss_params.len();
51 adrs.set_tree_height(0);
52
53 while(l > 1)
54 {
55 for(size_t i = 0; i < l >> 1; i++)
56 {
57 adrs.set_tree_index(i);
58 randomize_tree_hash(pk[i], pk[2 * i], pk[2 * i + 1], adrs, seed);
59 }
60 if(l & 0x01)
61 {
62 pk[l >> 1] = pk[l - 1];
63 }
64 l = (l >> 1) + (l & 0x01);
65 adrs.set_tree_height(adrs.get_tree_height() + 1);
66 }
67 result = pk[0];
68 }
Botan::XMSS_Common_Ops::m_xmss_params
XMSS_Parameters m_xmss_params
Definition: xmss_common_ops.h:68
Botan::XMSS_Common_Ops::randomize_tree_hash
void randomize_tree_hash(secure_vector< uint8_t > &result, const secure_vector< uint8_t > &left, const secure_vector< uint8_t > &right, XMSS_Address &adrs, const secure_vector< uint8_t > &seed)
Definition: xmss_common_ops.cpp:14
Botan::XMSS_Parameters::len
size_t len() const
Definition: xmss_parameters.h:87

std::unique_ptr< PK_Ops::Signature > Botan::XMSS_PrivateKey::create_signature_op | ( | RandomNumberGenerator & | rng,
|  | const std::string & | params,
|  | const std::string & | provider
| ) |  | const
| override virtual

This is an internal library function exposed on key types. In almost all cases applications should use wrappers in pubkey.h

Return a signature operation for this key/params or throw

Parameters

  rng | a random number generator. The PK_Op may maintain a reference to the RNG and use it many times. The rng must outlive any operations which reference it.
  params | additional parameters
  provider | the provider to use

Reimplemented from Botan::Private_Key.

Definition at line 177 of file xmss_privatekey.cpp.

References Botan::XMSS_PublicKey::algo_name().

180 {
181 if(provider == "base" || provider.empty())
182 return std::unique_ptr<PK_Ops::Signature>(
183 new XMSS_Signature_Operation(*this));
184
185 throw Provider_Not_Found(algo_name(), provider);
186 }
Botan::XMSS_PublicKey::algo_name
std::string algo_name() const override
Definition: xmss_publickey.h:189

std::unique_ptr< PK_Ops::Verification > Botan::XMSS_PublicKey::create_verification_op | ( | const std::string & | params,
|  | const std::string & | provider
| ) |  | const
| override virtual inherited

This is an internal library function exposed on key types. In almost all cases applications should use wrappers in pubkey.h

Return a verification operation for this key/params or throw

Parameters

  params | additional parameters
  provider | the provider to use

Reimplemented from Botan::Public_Key.

Definition at line 64 of file xmss_publickey.cpp.

References Botan::XMSS_PublicKey::algo_name().

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 }
Botan::XMSS_PublicKey::algo_name
std::string algo_name() const override
Definition: xmss_publickey.h:189

virtual size_t Botan::XMSS_PublicKey::estimated_strength | ( |  | ) | const
| inline override virtual inherited

Return the estimated strength of the underlying key against the best currently known attack. Note that this ignores anything but pure attacks against the key itself and do not take into account padding schemes, usage mistakes, etc which might reduce the strength. However it does suffice to provide an upper bound.

Returns
  estimated strength in bits

Implements Botan::Public_Key.

Definition at line 208 of file xmss_publickey.h.

209 {
210 return m_xmss_params.estimated_strength();
211 }
Botan::XMSS_Parameters::estimated_strength
size_t estimated_strength() const
Definition: xmss_parameters.h:100
Botan::XMSS_PublicKey::m_xmss_params
XMSS_Parameters m_xmss_params
Definition: xmss_publickey.h:250

std::string Botan::Private_Key::fingerprint | ( | const std::string & | alg = `"SHA"` | ) | const
| inherited

Returns
  Hash of the PKCS #8 encoding for this key object

Definition at line 57 of file pk_keys.cpp.

References Botan::HashFunction::create(), hash, Botan::hex_encode(), and Botan::Private_Key::private_key_bits().

Referenced by Botan::Certificate_Store_In_SQL::find_certs_for_key(), Botan::Certificate_Store_In_SQL::insert_key(), and Botan::Certificate_Store_In_SQL::remove_key().

58 {
59 secure_vector<uint8_t> buf = private_key_bits();
60 std::unique_ptr<HashFunction> hash(HashFunction::create(alg));
61 hash->update(buf);
62 const auto hex_print = hex_encode(hash->final());
63
64 std::string formatted_print;
65
66 for(size_t i = 0; i != hex_print.size(); i += 2)
67 {
68 formatted_print.push_back(hex_print[i]);
69 formatted_print.push_back(hex_print[i+1]);
70
71 if(i != hex_print.size() - 2)
72 formatted_print.push_back(':');
73 }
74
75 return formatted_print;
76 }
Botan::Private_Key::private_key_bits
virtual secure_vector< uint8_t > private_key_bits() const =0
Botan::HashFunction::create
static std::unique_ptr< HashFunction > create(const std::string &algo_spec, const std::string &provider="")
Definition: hash.cpp:93
Botan::hex_encode
void hex_encode(char output[], const uint8_t input[], size_t input_length, bool uppercase)
Definition: hex.cpp:14
hash
MechanismType hash
Definition: p11_mechanism.cpp:63

OID Botan::Public_Key::get_oid | ( |  | ) | const
| virtual inherited

Get the OID of the underlying public key scheme.

Returns
  OID of the public key scheme

Reimplemented in Botan::XMSS_WOTS_Addressed_PublicKey.

Definition at line 30 of file pk_keys.cpp.

References Botan::Public_Key::algo_name(), and Botan::OIDS::lookup().

Referenced by Botan::DL_Scheme_PublicKey::algorithm_identifier(), Botan::Curve25519_PublicKey::algorithm_identifier(), Botan::McEliece_PublicKey::algorithm_identifier(), Botan::RSA_PublicKey::algorithm_identifier(), Botan::GOST_3410_PublicKey::algorithm_identifier(), Botan::EC_PublicKey::algorithm_identifier(), Botan::TPM_PrivateKey::algorithm_identifier(), and Botan::XMSS_WOTS_Addressed_PublicKey::get_oid().

31 {
32 try {
33 return OIDS::lookup(algo_name());
34 }
35 catch(Lookup_Error&)
36 {
37 throw Lookup_Error("PK algo " + algo_name() + " has no defined OIDs");
38 }
39 }
Botan::Public_Key::algo_name
virtual std::string algo_name() const =0
Botan::OIDS::lookup
std::string lookup(const OID &oid)
Definition: oids.cpp:18

virtual size_t Botan::XMSS_PublicKey::key_length | ( |  | ) | const
| inline override virtual inherited

Return an integer value best approximating the length of the primary security parameter. For example for RSA this will be the size of the modulus, for ECDSA the size of the ECC group, and for McEliece the size of the code will be returned.

Implements Botan::Public_Key.

Definition at line 213 of file xmss_publickey.h.

214 {
215 return m_xmss_params.estimated_strength();
216 }
Botan::XMSS_Parameters::estimated_strength
size_t estimated_strength() const
Definition: xmss_parameters.h:100
Botan::XMSS_PublicKey::m_xmss_params
XMSS_Parameters m_xmss_params
Definition: xmss_publickey.h:250

virtual size_t Botan::Public_Key::message_part_size | ( |  | ) | const
| inline virtual inherited

Returns how large each of the message parts refered to by message_parts() is

This function is public but applications should have few reasons to ever call this.

Returns
  size of the message parts in bits

Reimplemented in Botan::GOST_3410_PublicKey, Botan::ECDSA_PublicKey, Botan::ECGDSA_PublicKey, Botan::ECKCDSA_PublicKey, and Botan::DSA_PublicKey.

Definition at line 114 of file pk_keys.h.

Referenced by Botan::PK_Signer::PK_Signer(), and Botan::PK_Verifier::PK_Verifier().

114 { return 0; }

virtual size_t Botan::Public_Key::message_parts | ( |  | ) | const
| inline virtual inherited

Returns more than 1 if the output of this algorithm (ciphertext, signature) should be treated as more than one value. This is used for algorithms like DSA and ECDSA, where the (r,s) output pair can be encoded as either a plain binary list or a TLV tagged DER encoding depending on the protocol.

This function is public but applications should have few reasons to ever call this.

Returns
  number of message parts

Reimplemented in Botan::GOST_3410_PublicKey, Botan::ECDSA_PublicKey, Botan::ECGDSA_PublicKey, Botan::ECKCDSA_PublicKey, and Botan::DSA_PublicKey.

Definition at line 103 of file pk_keys.h.

Referenced by Botan::X509_Object::check_signature(), Botan::choose_sig_format(), Botan::PK_Signer::PK_Signer(), and Botan::PK_Verifier::PK_Verifier().

103 { return 1; }

virtual AlgorithmIdentifier Botan::Private_Key::pkcs8_algorithm_identifier | ( |  | ) | const
| inline virtual inherited

Returns
  PKCS #8 AlgorithmIdentifier for this key Might be different from the X.509 identifier, but normally is not

Reimplemented in Botan::XMSS_WOTS_PrivateKey, Botan::GOST_3410_PrivateKey, and Botan::XMSS_WOTS_Addressed_PrivateKey.

Definition at line 188 of file pk_keys.h.

Referenced by Botan::Private_Key::private_key_info().

189 { return algorithm_identifier(); }
Botan::Public_Key::algorithm_identifier
virtual AlgorithmIdentifier algorithm_identifier() const =0

const secure_vector<uint8_t>& Botan::XMSS_PrivateKey::prf | ( |  | ) | const
| inline

Definition at line 173 of file xmss_privatekey.h.

174 {
175 return m_prf;
176 }

secure_vector<uint8_t>& Botan::XMSS_PrivateKey::prf | ( |  | ) |
| inline

Definition at line 178 of file xmss_privatekey.h.

179 {
180 return m_prf;
181 }

virtual secure_vector<uint8_t> Botan::XMSS_PrivateKey::private_key_bits | ( |  | ) | const
| inline override virtual

Returns
  BER encoded private key bits

Implements Botan::Private_Key.

Definition at line 206 of file xmss_privatekey.h.

207 {
208 return raw_private_key();
209 }
Botan::XMSS_PrivateKey::raw_private_key
virtual secure_vector< uint8_t > raw_private_key() const
Definition: xmss_privatekey.cpp:155

secure_vector< uint8_t > Botan::Private_Key::private_key_info | ( |  | ) | const
| inherited

Returns
  PKCS #8 private key encoding for this key object

Definition at line 41 of file pk_keys.cpp.

References Botan::DER_Encoder::encode(), Botan::DER_Encoder::end_cons(), Botan::DER_Encoder::get_contents(), Botan::OCTET_STRING, Botan::Private_Key::pkcs8_algorithm_identifier(), Botan::Private_Key::private_key_bits(), Botan::SEQUENCE, and Botan::DER_Encoder::start_cons().

Referenced by Botan::PKCS8::BER_encode(), Botan::PKCS8::BER_encode_encrypted_pbkdf_iter(), and Botan::PKCS8::BER_encode_encrypted_pbkdf_msec().

42 {
43 const size_t PKCS8_VERSION = 0;
44
45 return DER_Encoder()
46 .start_cons(SEQUENCE)
47 .encode(PKCS8_VERSION)
48 .encode(pkcs8_algorithm_identifier())
49 .encode(private_key_bits(), OCTET_STRING)
50 .end_cons()
51 .get_contents();
52 }
Botan::Private_Key::private_key_bits
virtual secure_vector< uint8_t > private_key_bits() const =0
Botan::OCTET_STRING
Definition: asn1_obj.h:35
Botan::Private_Key::pkcs8_algorithm_identifier
virtual AlgorithmIdentifier pkcs8_algorithm_identifier() const
Definition: pk_keys.h:188
Botan::SEQUENCE
Definition: asn1_obj.h:39

virtual std::vector<uint8_t> Botan::XMSS_PublicKey::public_key_bits | ( |  | ) | const
| inline override virtual inherited

Returns a raw byte sequence as defined in [1]. This method acts as an alias for raw_public_key().

Returns
  raw public key bits.

Implements Botan::Public_Key.

Definition at line 224 of file xmss_publickey.h.

225 {
226 return raw_public_key();
227 }
Botan::XMSS_PublicKey::raw_public_key
virtual std::vector< uint8_t > raw_public_key() const
Definition: xmss_publickey.cpp:75

virtual secure_vector<uint8_t>& Botan::XMSS_PublicKey::public_seed | ( |  | ) |
| inline virtual inherited

Definition at line 169 of file xmss_publickey.h.

170 {
171 return m_public_seed;
172 }
Botan::XMSS_PublicKey::m_public_seed
secure_vector< uint8_t > m_public_seed
Definition: xmss_publickey.h:253

virtual const secure_vector<uint8_t>& Botan::XMSS_PrivateKey::public_seed | ( |  | ) | const
| inline override virtual

Reimplemented from Botan::XMSS_PublicKey.

Definition at line 196 of file xmss_privatekey.h.

Referenced by tree_hash().

197 {
198 return m_public_seed;
199 }
Botan::XMSS_PublicKey::m_public_seed
secure_vector< uint8_t > m_public_seed
Definition: xmss_publickey.h:253

void Botan::XMSS_Common_Ops::randomize_tree_hash | ( | secure_vector< uint8_t > & | result,
|  | const secure_vector< uint8_t > & | left,
|  | const secure_vector< uint8_t > & | right,
|  | XMSS_Address & | adrs,
|  | const secure_vector< uint8_t > & | seed
| ) |  |
| protected inherited

Algorithm 7: "RAND_HASH"

Generates a randomized hash.

Parameters

  [out] | result | The resulting randomized hash.
  [in] | left | Left half of the hash function input.
  [in] | right | Right half of the hash function input.
  [in] | adrs | Adress of the hash function call.
  [in] | seed | The seed for G.

Definition at line 14 of file xmss_common_ops.cpp.

References BOTAN_ASSERT, Botan::XMSS_Address::bytes(), Botan::XMSS_Parameters::element_size(), Botan::XMSS_Hash::h(), Botan::XMSS_Address::Key_Mode, Botan::XMSS_Common_Ops::m_hash, Botan::XMSS_Common_Ops::m_xmss_params, Botan::XMSS_Address::Mask_LSB_Mode, Botan::XMSS_Address::Mask_MSB_Mode, Botan::XMSS_Hash::prf(), and Botan::XMSS_Address::set_key_mask_mode().

Referenced by Botan::XMSS_Common_Ops::create_l_tree(), and tree_hash().

19 {
20 adrs.set_key_mask_mode(XMSS_Address::Key_Mask::Key_Mode);
21 secure_vector<uint8_t> key { m_hash.prf(seed, adrs.bytes()) };
22
23 adrs.set_key_mask_mode(XMSS_Address::Key_Mask::Mask_MSB_Mode);
24 secure_vector<uint8_t> bitmask_l { m_hash.prf(seed, adrs.bytes()) };
25
26 adrs.set_key_mask_mode(XMSS_Address::Key_Mask::Mask_LSB_Mode);
27 secure_vector<uint8_t> bitmask_r { m_hash.prf(seed, adrs.bytes()) };
28
29 BOTAN_ASSERT(bitmask_l.size() == left.size() &&
30 bitmask_r.size() == right.size(),
31 "Bitmask size doesn't match node size.");
32
33 secure_vector<uint8_t> concat_xor(m_xmss_params.element_size() * 2);
34 for(size_t i = 0; i < left.size(); i++)
35 {
36 concat_xor[i] = left[i] ^ bitmask_l[i];
37 concat_xor[i + left.size()] = right[i] ^ bitmask_r[i];
38 }
39
40 m_hash.h(result, key, concat_xor);
41 }
Botan::XMSS_Address::Key_Mask::Mask_MSB_Mode
Botan::XMSS_Parameters::element_size
size_t element_size() const
Definition: xmss_parameters.h:72
Botan::XMSS_Hash::h
void h(secure_vector< uint8_t > &result, const secure_vector< uint8_t > &key, const secure_vector< uint8_t > &data)
Definition: xmss_hash.cpp:36
BOTAN_ASSERT
#define BOTAN_ASSERT(expr, assertion_made)
Definition: assert.h:27
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_Common_Ops::m_xmss_params
XMSS_Parameters m_xmss_params
Definition: xmss_common_ops.h:68
Botan::XMSS_Common_Ops::m_hash
XMSS_Hash m_hash
Definition: xmss_common_ops.h:69
Botan::XMSS_Address::Key_Mask::Mask_LSB_Mode
Botan::XMSS_Address::Key_Mask::Key_Mode

secure_vector< uint8_t > Botan::XMSS_PrivateKey::raw_private_key | ( |  | ) | const
| virtual

Generates a non standartized byte sequence representing the XMSS private key.

Returns
  byte sequence consisting of the following elements in order: 4-byte OID, n-byte root node, n-byte public seed, 8-byte unused leaf index, n-byte prf seed, n-byte private seed.

Definition at line 155 of file xmss_privatekey.cpp.

References Botan::XMSS_WOTS_PrivateKey::private_seed(), Botan::XMSS_PublicKey::raw_public_key(), size(), and unused_leaf_index().

156 {
157 std::vector<uint8_t> pk { raw_public_key() };
158 secure_vector<uint8_t> result(pk.begin(), pk.end());
159 result.reserve(size());
160
161 for(int i = 7; i >= 0; i--)
162 {
163 result.push_back(
164 static_cast<uint8_t>(
165 static_cast<uint64_t>(unused_leaf_index()) >> 8 * i));
166 }
167
168 std::copy(m_prf.begin(), m_prf.end(), std::back_inserter(result));
169 std::copy(m_wots_priv_key.private_seed().begin(),
170 m_wots_priv_key.private_seed().end(),
171 std::back_inserter(result));
172
173 return result;
174 }
Botan::XMSS_WOTS_PrivateKey::private_seed
const secure_vector< uint8_t > & private_seed() const
Definition: xmss_wots_privatekey.h:191
Botan::XMSS_PublicKey::raw_public_key
virtual std::vector< uint8_t > raw_public_key() const
Definition: xmss_publickey.cpp:75
Botan::XMSS_PrivateKey::size
virtual size_t size() const override
Definition: xmss_privatekey.h:211
Botan::XMSS_PrivateKey::unused_leaf_index
size_t unused_leaf_index() const
Definition: xmss_privatekey.h:104

std::vector< uint8_t > Botan::XMSS_PublicKey::raw_public_key | ( |  | ) | const
| virtual inherited

Generates a non standardized byte sequence representing the XMSS public key, as defined in 1

Returns
  4-byte OID, followed by n-byte root node, followed by public seed.

Definition at line 75 of file xmss_publickey.cpp.

References Botan::XMSS_PublicKey::m_public_seed, Botan::XMSS_PublicKey::m_root, Botan::XMSS_PublicKey::m_xmss_params, and Botan::XMSS_Parameters::oid().

Referenced by raw_private_key().

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 }
Botan::XMSS_PublicKey::m_public_seed
secure_vector< uint8_t > m_public_seed
Definition: xmss_publickey.h:253
Botan::XMSS_PublicKey::m_root
secure_vector< uint8_t > m_root
Definition: xmss_publickey.h:252
Botan::XMSS_Parameters::oid
xmss_algorithm_t oid() const
Definition: xmss_parameters.h:89
Botan::XMSS_PublicKey::m_xmss_params
XMSS_Parameters m_xmss_params
Definition: xmss_publickey.h:250

size_t Botan::XMSS_PrivateKey::reserve_unused_leaf_index | ( |  | ) |
| inline

Definition at line 139 of file xmss_privatekey.h.

References Botan::XMSS_PublicKey::m_xmss_params.

140 {
141 size_t idx = (static_cast<std::atomic<size_t>&>(
142 *recover_global_leaf_index())).fetch_add(1);
143 if(idx >= (1ull << (XMSS_PublicKey::m_xmss_params.tree_height() - 1)))
144 {
145 throw Integrity_Failure("XMSS private key, one time signatures "
146 "exhausted.");
147 }
148 return idx;
149 }
Botan::XMSS_PublicKey::m_xmss_params
XMSS_Parameters m_xmss_params
Definition: xmss_publickey.h:250

secure_vector<uint8_t>& Botan::XMSS_PublicKey::root | ( |  | ) |
| inline inherited

Definition at line 149 of file xmss_publickey.h.

150 {
151 return m_root;
152 }
Botan::XMSS_PublicKey::m_root
secure_vector< uint8_t > m_root
Definition: xmss_publickey.h:252

const secure_vector<uint8_t>& Botan::XMSS_PublicKey::root | ( |  | ) | const
| inline inherited

Definition at line 164 of file xmss_publickey.h.

165 {
166 return m_root;
167 }
Botan::XMSS_PublicKey::m_root
secure_vector< uint8_t > m_root
Definition: xmss_publickey.h:252

virtual void Botan::XMSS_PrivateKey::set_public_seed | ( | const secure_vector< uint8_t > & | public_seed | ) |
| inline override virtual

Reimplemented from Botan::XMSS_PublicKey.

Definition at line 183 of file xmss_privatekey.h.

185 {
186 m_public_seed = public_seed;
187 m_wots_priv_key.set_public_seed(public_seed);
188 }
Botan::XMSS_PublicKey::m_public_seed
secure_vector< uint8_t > m_public_seed
Definition: xmss_publickey.h:253
Botan::XMSS_PrivateKey::public_seed
virtual const secure_vector< uint8_t > & public_seed() const override
Definition: xmss_privatekey.h:196
Botan::XMSS_WOTS_PublicKey::set_public_seed
void set_public_seed(const secure_vector< uint8_t > &public_seed)
Definition: xmss_wots_publickey.h:205

virtual void Botan::XMSS_PrivateKey::set_public_seed | ( | secure_vector< uint8_t > && | public_seed | ) |
| inline override virtual

Reimplemented from Botan::XMSS_PublicKey.

Definition at line 190 of file xmss_privatekey.h.

191 {
192 m_public_seed = std::move(public_seed);
193 m_wots_priv_key.set_public_seed(m_public_seed);
194 }
Botan::XMSS_PublicKey::m_public_seed
secure_vector< uint8_t > m_public_seed
Definition: xmss_publickey.h:253
Botan::XMSS_PrivateKey::public_seed
virtual const secure_vector< uint8_t > & public_seed() const override
Definition: xmss_privatekey.h:196
Botan::XMSS_WOTS_PublicKey::set_public_seed
void set_public_seed(const secure_vector< uint8_t > &public_seed)
Definition: xmss_wots_publickey.h:205

void Botan::XMSS_PublicKey::set_root | ( | const secure_vector< uint8_t > & | root | ) |
| inline inherited

Definition at line 154 of file xmss_publickey.h.

Referenced by XMSS_PrivateKey().

155 {
156 m_root = root;
157 }
Botan::XMSS_PublicKey::m_root
secure_vector< uint8_t > m_root
Definition: xmss_publickey.h:252
Botan::XMSS_PublicKey::root
secure_vector< uint8_t > & root()
Definition: xmss_publickey.h:149

void Botan::XMSS_PublicKey::set_root | ( | secure_vector< uint8_t > && | root | ) |
| inline inherited

Definition at line 159 of file xmss_publickey.h.

160 {
161 m_root = std::move(root);
162 }
Botan::XMSS_PublicKey::m_root
secure_vector< uint8_t > m_root
Definition: xmss_publickey.h:252
Botan::XMSS_PublicKey::root
secure_vector< uint8_t > & root()
Definition: xmss_publickey.h:149

void Botan::XMSS_PrivateKey::set_unused_leaf_index | ( | size_t | idx | ) |
| inline

Sets the last unused leaf index of the private key. The leaf index will be updated automatically during every signing operation, and should not be set manually.

Parameters

  idx | Index of the last unused leaf.

Definition at line 116 of file xmss_privatekey.h.

References Botan::XMSS_PublicKey::m_xmss_params.

Referenced by XMSS_PrivateKey().

117 {
118 if(idx >= (1ull << (XMSS_PublicKey::m_xmss_params.tree_height() - 1)))
119 {
120 throw Integrity_Failure("XMSS private key leaf index out of "
121 "bounds.");
122 }
123 else
124 {
125 std::atomic<size_t>& index =
126 static_cast<std::atomic<size_t>&>(*recover_global_leaf_index());
127 size_t current = 0;
128
129 do
130 {
131 current = index.load();
132 if(current > idx)
133 return;
134 }
135 while(!index.compare_exchange_strong(current, idx));
136 }
137 }
Botan::XMSS_PublicKey::m_xmss_params
XMSS_Parameters m_xmss_params
Definition: xmss_publickey.h:250

void Botan::XMSS_PublicKey::set_xmss_oid | ( | XMSS_Parameters::xmss_algorithm_t | xmss_oid | ) |
| inline inherited

Sets the chosen XMSS signature method

Returns
  XMSS signature method identifier.

Definition at line 110 of file xmss_publickey.h.

111 {
112 m_xmss_params = XMSS_Parameters(xmss_oid);
113 m_wots_params = XMSS_WOTS_Parameters(m_xmss_params.ots_oid());
114 }
Botan::XMSS_Parameters::ots_oid
XMSS_WOTS_Parameters::ots_algorithm_t ots_oid() const
Definition: xmss_parameters.h:91
Botan::XMSS_PublicKey::xmss_oid
XMSS_Parameters::xmss_algorithm_t xmss_oid() const
Definition: xmss_publickey.h:100
Botan::XMSS_PublicKey::m_wots_params
XMSS_WOTS_Parameters m_wots_params
Definition: xmss_publickey.h:251
Botan::XMSS_PublicKey::m_xmss_params
XMSS_Parameters m_xmss_params
Definition: xmss_publickey.h:250

virtual size_t Botan::XMSS_PrivateKey::size | ( |  | ) | const
| inline override virtual

Size in bytes of the serialized XMSS public key produced by raw_public_key().

Returns
  size in bytes of serialized Public Key.

Reimplemented from Botan::XMSS_PublicKey.

Definition at line 211 of file xmss_privatekey.h.

References Botan::XMSS_PublicKey::m_xmss_params, and Botan::XMSS_PublicKey::size().

Referenced by raw_private_key(), and XMSS_PrivateKey().

212 {
213 return XMSS_PublicKey::size() +
214 sizeof(uint64_t) +
215 2 * XMSS_PublicKey::m_xmss_params.element_size();
216 }
Botan::XMSS_PublicKey::size
virtual size_t size() const
Definition: xmss_publickey.h:235
Botan::XMSS_PublicKey::m_xmss_params
XMSS_Parameters m_xmss_params
Definition: xmss_publickey.h:250

std::vector< uint8_t > Botan::Public_Key::subject_public_key | ( |  | ) | const
| inherited

Returns
  X.509 subject key encoding for this key object

Definition at line 17 of file pk_keys.cpp.

References Botan::Public_Key::algorithm_identifier(), Botan::BIT_STRING, Botan::DER_Encoder::encode(), Botan::DER_Encoder::end_cons(), Botan::DER_Encoder::get_contents_unlocked(), Botan::Public_Key::public_key_bits(), Botan::SEQUENCE, and Botan::DER_Encoder::start_cons().

Referenced by Botan::X509::BER_encode(), and Botan::X509::PEM_encode().

18 {
19 return DER_Encoder()
20 .start_cons(SEQUENCE)
21 .encode(algorithm_identifier())
22 .encode(public_key_bits(), BIT_STRING)
23 .end_cons()
24 .get_contents_unlocked();
25 }
Botan::Public_Key::public_key_bits
virtual std::vector< uint8_t > public_key_bits() const =0
Botan::Public_Key::algorithm_identifier
virtual AlgorithmIdentifier algorithm_identifier() const =0
Botan::SEQUENCE
Definition: asn1_obj.h:39
Botan::BIT_STRING
Definition: asn1_obj.h:34

secure_vector< uint8_t > Botan::XMSS_PrivateKey::tree_hash | ( | size_t | start_idx,
|  | size_t | target_node_height,
|  | XMSS_Address & | adrs
| ) |  |

Algorithm 9: "treeHash" Computes the internal n-byte nodes of a Merkle tree.

Parameters

  start_idx | The start index.
  target_node_height | Height of the target node.
  adrs | Address of the tree containing the target node.

Returns
  The root node of a tree of height target_node height with the leftmost leaf being the hash of the WOTS+ pk with index start_idx.

Definition at line 83 of file xmss_privatekey.cpp.

References BOTAN_ASSERT, Botan::XMSS_Common_Ops::create_l_tree(), Botan::XMSS_WOTS_PrivateKey::generate_public_key(), Botan::XMSS_Address::get_tree_height(), Botan::XMSS_Address::get_tree_index(), Botan::XMSS_Address::Hash_Tree_Address, Botan::XMSS_Address::LTree_Address, Botan::XMSS_PublicKey::m_xmss_params, Botan::XMSS_WOTS_Parameters::oid(), Botan::XMSS_Address::OTS_Hash_Address, public_seed(), Botan::XMSS_Common_Ops::randomize_tree_hash(), Botan::XMSS_Address::set_ltree_address(), Botan::XMSS_Address::set_ots_address(), Botan::XMSS_Address::set_tree_height(), Botan::XMSS_Address::set_tree_index(), Botan::XMSS_Address::set_type(), Botan::XMSS_WOTS_PublicKey::wots_parameters(), and wots_private_key().

Referenced by XMSS_PrivateKey().

86 {
87 const secure_vector<uint8_t>& seed = this->public_seed();
88
89 BOTAN_ASSERT((start_idx % (1 << target_node_height)) == 0,
90 "Start index must be divisible by 2^{target node height}.");
91
92 std::vector<secure_vector<uint8_t>> nodes(
93 XMSS_PublicKey::m_xmss_params.tree_height() + 1,
94 secure_vector<uint8_t>(XMSS_PublicKey::m_xmss_params.element_size()));
95
96 // node stack, holds all nodes on stack and one extra "pending" node. This
97 // temporary node referred to as "node" in the XMSS standard document stays
98 // a pending element, meaning it is not regarded as element on the stack
99 // until level is increased.
100 std::vector<uint8_t> node_levels(XMSS_PublicKey::m_xmss_params.tree_height() + 1);
101
102 uint8_t level = 0;
103 XMSS_WOTS_PublicKey pk(m_wots_priv_key.wots_parameters().oid(), seed);
104
105 size_t last_idx = static_cast<size_t>(1 << target_node_height) + start_idx;
106 for(size_t i = start_idx; i < last_idx; i++)
107 {
108 adrs.set_type(XMSS_Address::Type::OTS_Hash_Address);
109 adrs.set_ots_address(i);
110 this->wots_private_key().generate_public_key(
111 pk,
112 // getWOTS_SK(SK, s + i), reference implementation uses adrs
113 // instead of zero padded index s + i.
114 this->wots_private_key()[adrs],
115 adrs);
116 adrs.set_type(XMSS_Address::Type::LTree_Address);
117 adrs.set_ltree_address(i);
118 create_l_tree(nodes[level], pk, adrs, seed);
119 node_levels[level] = 0;
120
121 adrs.set_type(XMSS_Address::Type::Hash_Tree_Address);
122 adrs.set_tree_height(0);
123 adrs.set_tree_index(i);
124
125 while(level > 0 && node_levels[level] ==
126 node_levels[level - 1])
127 {
128 adrs.set_tree_index(((adrs.get_tree_index() - 1) >> 1));
129 randomize_tree_hash(nodes[level - 1],
130 nodes[level - 1],
131 nodes[level],
132 adrs,
133 seed);
134 node_levels[level - 1]++;
135 level--; //Pop stack top element
136 adrs.set_tree_height(adrs.get_tree_height() + 1);
137 }
138 level++; //push temporary node to stack
139 }
140 return nodes[level - 1];
141 }
Botan::XMSS_Address::Type::LTree_Address
Botan::XMSS_Common_Ops::create_l_tree
void create_l_tree(secure_vector< uint8_t > &result, wots_keysig_t pk, XMSS_Address &adrs, const secure_vector< uint8_t > &seed)
Definition: xmss_common_ops.cpp:45
Botan::XMSS_PrivateKey::public_seed
virtual const secure_vector< uint8_t > & public_seed() const override
Definition: xmss_privatekey.h:196
Botan::XMSS_Address::Type::OTS_Hash_Address
BOTAN_ASSERT
#define BOTAN_ASSERT(expr, assertion_made)
Definition: assert.h:27
Botan::XMSS_Common_Ops::randomize_tree_hash
void randomize_tree_hash(secure_vector< uint8_t > &result, const secure_vector< uint8_t > &left, const secure_vector< uint8_t > &right, XMSS_Address &adrs, const secure_vector< uint8_t > &seed)
Definition: xmss_common_ops.cpp:14
Botan::XMSS_WOTS_PrivateKey::generate_public_key
XMSS_WOTS_PublicKey generate_public_key(XMSS_Address &adrs)
Definition: xmss_wots_privatekey.cpp:32
Botan::XMSS_WOTS_PublicKey::wots_parameters
const XMSS_WOTS_Parameters & wots_parameters() const
Definition: xmss_wots_publickey.h:229
Botan::XMSS_Address::Type::Hash_Tree_Address
Botan::XMSS_PublicKey::m_xmss_params
XMSS_Parameters m_xmss_params
Definition: xmss_publickey.h:250
Botan::XMSS_PrivateKey::wots_private_key
const XMSS_WOTS_PrivateKey & wots_private_key() const
Definition: xmss_privatekey.h:157
Botan::XMSS_WOTS_Parameters::oid
ots_algorithm_t oid() const
Definition: xmss_wots_parameters.h:105

size_t Botan::XMSS_PrivateKey::unused_leaf_index | ( |  | ) | const
| inline

Retrieves the last unused leaf index of the private key. Reusing a leaf by utilizing leaf indices lower than the last unused leaf index will compromise security.

Returns
  Index of the last unused leaf.

Definition at line 104 of file xmss_privatekey.h.

Referenced by raw_private_key().

105 {
106 return *recover_global_leaf_index();
107 }

XMSS_WOTS_Parameters::ots_algorithm_t Botan::XMSS_PublicKey::wots_oid | ( |  | ) | const
| inline inherited

Retrieves the Winternitz One Time Signature (WOTS) method, corrseponding to the chosen XMSS signature method.

Returns
  XMSS WOTS signature method identifier.

Definition at line 133 of file xmss_publickey.h.

134 {
135 return m_wots_params.oid();
136 }
Botan::XMSS_PublicKey::m_wots_params
XMSS_WOTS_Parameters m_wots_params
Definition: xmss_publickey.h:251
Botan::XMSS_WOTS_Parameters::oid
ots_algorithm_t oid() const
Definition: xmss_wots_parameters.h:105

const XMSS_WOTS_Parameters& Botan::XMSS_PublicKey::wots_parameters | ( |  | ) | const
| inline inherited

Retrieves the Winternitz One Time Signature (WOTS) parameters corresponding to the chosen XMSS signature method.

Returns
  XMSS WOTS signature method parameters.

Definition at line 144 of file xmss_publickey.h.

145 {
146 return m_wots_params;
147 }
Botan::XMSS_PublicKey::m_wots_params
XMSS_WOTS_Parameters m_wots_params
Definition: xmss_publickey.h:251

const XMSS_WOTS_PrivateKey& Botan::XMSS_PrivateKey::wots_private_key | ( |  | ) | const
| inline

Winternitz One Time Signature Scheme key utilized for signing operations.

Returns
  WOTS+ private key.

Definition at line 157 of file xmss_privatekey.h.

Referenced by tree_hash().

158 {
159 return m_wots_priv_key;
160 }

XMSS_WOTS_PrivateKey& Botan::XMSS_PrivateKey::wots_private_key | ( |  | ) |
| inline

Winternitz One Time Signature Scheme key utilized for signing operations.

Returns
  WOTS+ private key.

Definition at line 168 of file xmss_privatekey.h.

169 {
170 return m_wots_priv_key;
171 }

XMSS_Parameters::xmss_algorithm_t Botan::XMSS_PublicKey::xmss_oid | ( |  | ) | const
| inline inherited

Retrieves the chosen XMSS signature method.

Returns
  XMSS signature method identifier.

Definition at line 100 of file xmss_publickey.h.

101 {
102 return m_xmss_params.oid();
103 }
Botan::XMSS_Parameters::oid
xmss_algorithm_t oid() const
Definition: xmss_parameters.h:89
Botan::XMSS_PublicKey::m_xmss_params
XMSS_Parameters m_xmss_params
Definition: xmss_publickey.h:250

const XMSS_Parameters& Botan::XMSS_PublicKey::xmss_parameters | ( |  | ) | const
| inline inherited

Retrieves the XMSS parameters determined by the chosen XMSS Signature method.

Returns
  XMSS parameters.

Definition at line 122 of file xmss_publickey.h.

Referenced by Botan::XMSS_Verification_Operation::is_valid_signature().

123 {
124 return m_xmss_params;
125 }
Botan::XMSS_PublicKey::m_xmss_params
XMSS_Parameters m_xmss_params
Definition: xmss_publickey.h:250

## Member Data Documentation

XMSS_Hash Botan::XMSS_Common_Ops::m_hash
| protected inherited

Definition at line 69 of file xmss_common_ops.h.

Referenced by Botan::XMSS_Common_Ops::randomize_tree_hash(), Botan::XMSS_Signature_Operation::sign(), and Botan::XMSS_Signature_Operation::update().

secure_vector<uint8_t> Botan::XMSS_PublicKey::m_public_seed
| protected inherited

Definition at line 253 of file xmss_publickey.h.

Referenced by Botan::XMSS_PublicKey::raw_public_key(), and Botan::XMSS_PublicKey::XMSS_PublicKey().

secure_vector<uint8_t> Botan::XMSS_PublicKey::m_root
| protected inherited

Definition at line 252 of file xmss_publickey.h.

Referenced by Botan::XMSS_PublicKey::raw_public_key(), and Botan::XMSS_PublicKey::XMSS_PublicKey().

XMSS_WOTS_Parameters Botan::XMSS_PublicKey::m_wots_params
| protected inherited

Definition at line 251 of file xmss_publickey.h.

Referenced by XMSS_PrivateKey().

XMSS_Parameters Botan::XMSS_Common_Ops::m_xmss_params
| protected inherited

Definition at line 68 of file xmss_common_ops.h.

Referenced by Botan::XMSS_Common_Ops::create_l_tree(), and Botan::XMSS_Common_Ops::randomize_tree_hash().

XMSS_Parameters Botan::XMSS_PublicKey::m_xmss_params
| protected inherited

Definition at line 250 of file xmss_publickey.h.

Referenced by Botan::XMSS_PublicKey::raw_public_key(), reserve_unused_leaf_index(), set_unused_leaf_index(), size(), tree_hash(), XMSS_PrivateKey(), and Botan::XMSS_PublicKey::XMSS_PublicKey().

The documentation for this class was generated from the following files:

- src/lib/pubkey/xmss/xmss_privatekey.h
- src/lib/pubkey/xmss/xmss_privatekey.cpp