Botan  2.13.0
Crypto and TLS for C++11
Public Types | Public Member Functions | Static Public Member Functions | List of all members
Botan::XMSS_WOTS_Parameters Class Referencefinal

#include <xmss_wots_parameters.h>

Public Types

enum  ots_algorithm_t { WOTSP_SHA2_256 = 0x00000001, WOTSP_SHA2_512 = 0x00000002, WOTSP_SHAKE_256 = 0x00000003, WOTSP_SHAKE_512 = 0x00000004 }
 

Public Member Functions

void append_checksum (secure_vector< uint8_t > &data)
 
secure_vector< uint8_t > base_w (const secure_vector< uint8_t > &msg, size_t out_size) const
 
secure_vector< uint8_t > base_w (size_t value) const
 
size_t element_size () const
 
size_t estimated_strength () const
 
const std::string & hash_function_name () const
 
size_t len () const
 
size_t len_1 () const
 
size_t len_2 () const
 
size_t lg_w () const
 
const std::string & name () const
 
ots_algorithm_t oid () const
 
bool operator== (const XMSS_WOTS_Parameters &p) const
 
size_t wots_parameter () const
 
 XMSS_WOTS_Parameters (const std::string &algo_name)
 
 XMSS_WOTS_Parameters (ots_algorithm_t ots_spec)
 

Static Public Member Functions

static ots_algorithm_t xmss_wots_id_from_string (const std::string &param_set)
 

Detailed Description

Descibes a signature method for XMSS Winternitz One Time Signatures, as defined in: [1] XMSS: Extended Hash-Based Signatures, Request for Comments: 8391 Release: May 2018. https://datatracker.ietf.org/doc/rfc8391/

Definition at line 26 of file xmss_wots_parameters.h.

Member Enumeration Documentation

Enumerator
WOTSP_SHA2_256 
WOTSP_SHA2_512 
WOTSP_SHAKE_256 
WOTSP_SHAKE_512 

Definition at line 29 of file xmss_wots_parameters.h.

Constructor & Destructor Documentation

Botan::XMSS_WOTS_Parameters::XMSS_WOTS_Parameters ( const std::string &  algo_name)

Definition at line 35 of file xmss_wots_parameters.cpp.

37  {}
static ots_algorithm_t xmss_wots_id_from_string(const std::string &param_set)
XMSS_WOTS_Parameters(const std::string &algo_name)
Botan::XMSS_WOTS_Parameters::XMSS_WOTS_Parameters ( ots_algorithm_t  ots_spec)

Definition at line 39 of file xmss_wots_parameters.cpp.

References BOTAN_ASSERT, element_size(), wots_parameter(), WOTSP_SHA2_256, WOTSP_SHA2_512, WOTSP_SHAKE_256, and WOTSP_SHAKE_512.

40  : m_oid(oid)
41  {
42  switch(oid)
43  {
44  case WOTSP_SHA2_256:
45  m_element_size = 32;
46  m_w = 16;
47  m_len = 67;
48  m_name = "WOTSP-SHA2_256";
49  m_hash_name = "SHA-256";
50  m_strength = 256;
51  break;
52  case WOTSP_SHA2_512:
53  m_element_size = 64;
54  m_w = 16;
55  m_len = 131;
56  m_name = "WOTSP-SHA2_512";
57  m_hash_name = "SHA-512";
58  m_strength = 512;
59  break;
60  case WOTSP_SHAKE_256:
61  m_element_size = 32;
62  m_w = 16;
63  m_len = 67;
64  m_name = "WOTSP-SHAKE_256";
65  m_hash_name = "SHAKE-128(256)";
66  m_strength = 256;
67  break;
68  case WOTSP_SHAKE_512:
69  m_element_size = 64;
70  m_w = 16;
71  m_len = 131;
72  m_name = "WOTSP-SHAKE_512";
73  m_hash_name = "SHAKE-256(512)";
74  m_strength = 512;
75  break;
76  default:
77  throw Not_Implemented("Algorithm id does not match any known XMSS WOTS algorithm id.");
78  break;
79  }
80 
81  m_lg_w = (m_w == 16) ? 4 : 2;
82  m_len_1 = static_cast<size_t>(std::ceil((8 * element_size()) / m_lg_w));
83  m_len_2 = static_cast<size_t>(
84  floor(log2(m_len_1 * (wots_parameter() - 1)) / m_lg_w) + 1);
85  BOTAN_ASSERT(m_len == m_len_1 + m_len_2, "Invalid XMSS WOTS parameter "
86  "\"len\" detedted.");
87  }
#define BOTAN_ASSERT(expr, assertion_made)
Definition: assert.h:55
ots_algorithm_t oid() const

Member Function Documentation

void Botan::XMSS_WOTS_Parameters::append_checksum ( secure_vector< uint8_t > &  data)

Definition at line 123 of file xmss_wots_parameters.cpp.

References base_w(), and wots_parameter().

Referenced by Botan::XMSS_WOTS_PrivateKey::sign().

124  {
125  size_t csum = 0;
126 
127  for(size_t i = 0; i < data.size(); i++)
128  {
129  csum += wots_parameter() - 1 - data[i];
130  }
131 
132  secure_vector<uint8_t> csum_bytes = base_w(csum);
133  std::move(csum_bytes.begin(), csum_bytes.end(), std::back_inserter(data));
134  }
secure_vector< uint8_t > base_w(const secure_vector< uint8_t > &msg, size_t out_size) const
secure_vector< uint8_t > Botan::XMSS_WOTS_Parameters::base_w ( const secure_vector< uint8_t > &  msg,
size_t  out_size 
) const

Algorithm 1: convert input string to base.

Parameters
msgInput string (referred to as X in [1]).
out_sizesize of message in base w.
Returns
Input string converted to the given base.

Definition at line 90 of file xmss_wots_parameters.cpp.

Referenced by append_checksum(), base_w(), and Botan::XMSS_WOTS_PrivateKey::sign().

91  {
92  secure_vector<uint8_t> result;
93  size_t in = 0;
94  size_t total = 0;
95  size_t bits = 0;
96 
97  for(size_t i = 0; i < out_size; i++)
98  {
99  if(bits == 0)
100  {
101  total = msg[in];
102  in++;
103  bits += 8;
104  }
105  bits -= m_lg_w;
106  result.push_back(static_cast<uint8_t>((total >> bits) & (m_w - 1)));
107  }
108  return result;
109  }
secure_vector< uint8_t > Botan::XMSS_WOTS_Parameters::base_w ( size_t  value) const

Definition at line 112 of file xmss_wots_parameters.cpp.

References base_w(), and Botan::XMSS_Tools::concat().

113  {
114  value <<= (8 - ((m_len_2 * m_lg_w) % 8));
115  size_t len_2_bytes = static_cast<size_t>(
116  std::ceil(static_cast<float>(m_len_2 * m_lg_w) / 8.f));
117  secure_vector<uint8_t> result;
118  XMSS_Tools::concat(result, value, len_2_bytes);
119  return base_w(result, m_len_2);
120  }
secure_vector< uint8_t > base_w(const secure_vector< uint8_t > &msg, size_t out_size) const
static void concat(secure_vector< uint8_t > &target, const T &src)
Definition: xmss_tools.h:63
size_t Botan::XMSS_WOTS_Parameters::element_size ( ) const
inline

Retrieves the uniform length of a message, and the size of each node. This correlates to XMSS parameter "n" defined in [1].

Returns
element length in bytes.

Definition at line 79 of file xmss_wots_parameters.h.

Referenced by Botan::XMSS_WOTS_PrivateKey::at(), Botan::XMSS_PrivateKey::XMSS_PrivateKey(), and XMSS_WOTS_Parameters().

79 { return m_element_size; }
size_t Botan::XMSS_WOTS_Parameters::estimated_strength ( ) const
inline

Definition at line 99 of file xmss_wots_parameters.h.

Referenced by Botan::XMSS_WOTS_PublicKey::estimated_strength(), and Botan::XMSS_WOTS_PublicKey::key_length().

99 { return m_strength; }
const std::string& Botan::XMSS_WOTS_Parameters::hash_function_name ( ) const
inline
Returns
Botan name for the hash function used.

Definition at line 67 of file xmss_wots_parameters.h.

68  {
69  return m_hash_name;
70  }
size_t Botan::XMSS_WOTS_Parameters::len ( ) const
inline

Definition at line 89 of file xmss_wots_parameters.h.

Referenced by Botan::XMSS_WOTS_PrivateKey::generate_public_key(), and Botan::XMSS_WOTS_PrivateKey::sign().

89 { return m_len; }
size_t Botan::XMSS_WOTS_Parameters::len_1 ( ) const
inline

Definition at line 91 of file xmss_wots_parameters.h.

Referenced by Botan::XMSS_WOTS_PrivateKey::sign().

91 { return m_len_1; }
size_t Botan::XMSS_WOTS_Parameters::len_2 ( ) const
inline

Definition at line 93 of file xmss_wots_parameters.h.

93 { return m_len_2; }
size_t Botan::XMSS_WOTS_Parameters::lg_w ( ) const
inline

Definition at line 95 of file xmss_wots_parameters.h.

95 { return m_lg_w; }
const std::string& Botan::XMSS_WOTS_Parameters::name ( ) const
inline
Returns
XMSS WOTS registry name for the chosen parameter set.

Definition at line 59 of file xmss_wots_parameters.h.

Referenced by Botan::XMSS_WOTS_PublicKey::algo_name().

60  {
61  return m_name;
62  }
ots_algorithm_t Botan::XMSS_WOTS_Parameters::oid ( ) const
inline

Definition at line 97 of file xmss_wots_parameters.h.

Referenced by Botan::XMSS_WOTS_PrivateKey::generate_public_key().

97 { return m_oid; }
bool Botan::XMSS_WOTS_Parameters::operator== ( const XMSS_WOTS_Parameters p) const
inline

Definition at line 101 of file xmss_wots_parameters.h.

102  {
103  return m_oid == p.m_oid;
104  }
size_t Botan::XMSS_WOTS_Parameters::wots_parameter ( ) const
inline

The Winternitz parameter.

Returns
numeric base used for internal representation of data.

Definition at line 87 of file xmss_wots_parameters.h.

Referenced by append_checksum(), Botan::XMSS_WOTS_PublicKey::chain(), Botan::XMSS_WOTS_PrivateKey::generate_public_key(), and XMSS_WOTS_Parameters().

87 { return m_w; }
XMSS_WOTS_Parameters::ots_algorithm_t Botan::XMSS_WOTS_Parameters::xmss_wots_id_from_string ( const std::string &  param_set)
static

Definition at line 22 of file xmss_wots_parameters.cpp.

References WOTSP_SHA2_256, WOTSP_SHA2_512, WOTSP_SHAKE_256, and WOTSP_SHAKE_512.

23  {
24  if(param_set == "WOTSP-SHA2_256")
25  { return WOTSP_SHA2_256; }
26  if(param_set == "WOTSP-SHA2_512")
27  { return WOTSP_SHA2_512; }
28  if(param_set == "WOTSP-SHAKE_256")
29  { return WOTSP_SHAKE_256; }
30  if(param_set == "WOTSP-SHAKE_512")
31  { return WOTSP_SHAKE_512; }
32  throw Invalid_Argument("Unknown XMSS-WOTS algorithm param '" + param_set + "'");
33  }

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