Botan  2.6.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_W16 = 0x01000001, WOTSP_SHA2_512_W16 = 0x02000002, WOTSP_SHAKE128_W16 = 0x03000003, WOTSP_SHAKE256_W16 = 0x04000004 }
 

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, 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 27 of file xmss_wots_parameters.h.

Member Enumeration Documentation

◆ ots_algorithm_t

Enumerator
WOTSP_SHA2_256_W16 
WOTSP_SHA2_512_W16 
WOTSP_SHAKE128_W16 
WOTSP_SHAKE256_W16 

Definition at line 30 of file xmss_wots_parameters.h.

Constructor & Destructor Documentation

◆ XMSS_WOTS_Parameters() [1/2]

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

Definition at line 36 of file xmss_wots_parameters.cpp.

38  {}
static ots_algorithm_t xmss_wots_id_from_string(const std::string &param_set)
XMSS_WOTS_Parameters(const std::string &algo_name)

◆ XMSS_WOTS_Parameters() [2/2]

Botan::XMSS_WOTS_Parameters::XMSS_WOTS_Parameters ( ots_algorithm_t  ots_spec)

Definition at line 40 of file xmss_wots_parameters.cpp.

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

Member Function Documentation

◆ append_checksum()

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

Definition at line 125 of file xmss_wots_parameters.cpp.

References base_w(), and wots_parameter().

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

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

◆ base_w() [1/2]

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 92 of file xmss_wots_parameters.cpp.

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

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

◆ base_w() [2/2]

secure_vector< uint8_t > Botan::XMSS_WOTS_Parameters::base_w ( size_t  value) const

Definition at line 114 of file xmss_wots_parameters.cpp.

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

115  {
116  value <<= (8 - ((m_len_2 * m_lg_w) % 8));
117  size_t len_2_bytes = static_cast<size_t>(
118  std::ceil(static_cast<float>(m_len_2 * m_lg_w) / 8.f));
119  secure_vector<uint8_t> result;
120  XMSS_Tools::concat(result, value, len_2_bytes);
121  return base_w(result, m_len_2);
122  }
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:103

◆ element_size()

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 80 of file xmss_wots_parameters.h.

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

80 { return m_element_size; }

◆ estimated_strength()

size_t Botan::XMSS_WOTS_Parameters::estimated_strength ( ) const
inline

Definition at line 100 of file xmss_wots_parameters.h.

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

100 { return m_strength; }

◆ hash_function_name()

const std::string& Botan::XMSS_WOTS_Parameters::hash_function_name ( ) const
inline
Returns
Botan name for the hash function used.

Definition at line 68 of file xmss_wots_parameters.h.

69  {
70  return m_hash_name;
71  }

◆ len()

size_t Botan::XMSS_WOTS_Parameters::len ( ) const
inline

Definition at line 90 of file xmss_wots_parameters.h.

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

90 { return m_len; }

◆ len_1()

size_t Botan::XMSS_WOTS_Parameters::len_1 ( ) const
inline

Definition at line 92 of file xmss_wots_parameters.h.

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

92 { return m_len_1; }

◆ len_2()

size_t Botan::XMSS_WOTS_Parameters::len_2 ( ) const
inline

Definition at line 94 of file xmss_wots_parameters.h.

94 { return m_len_2; }

◆ lg_w()

size_t Botan::XMSS_WOTS_Parameters::lg_w ( ) const
inline

Definition at line 96 of file xmss_wots_parameters.h.

96 { return m_lg_w; }

◆ name()

const std::string& Botan::XMSS_WOTS_Parameters::name ( ) const
inline
Returns
XMSS WOTS registry name for the chosen parameter set.

Definition at line 60 of file xmss_wots_parameters.h.

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

61  {
62  return m_name;
63  }

◆ oid()

ots_algorithm_t Botan::XMSS_WOTS_Parameters::oid ( ) const
inline

Definition at line 98 of file xmss_wots_parameters.h.

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

98 { return m_oid; }

◆ operator==()

bool Botan::XMSS_WOTS_Parameters::operator== ( const XMSS_WOTS_Parameters p) const
inline

Definition at line 102 of file xmss_wots_parameters.h.

103  {
104  return m_oid == p.m_oid;
105  }

◆ wots_parameter()

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 88 of file xmss_wots_parameters.h.

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

88 { return m_w; }

◆ xmss_wots_id_from_string()

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

Definition at line 23 of file xmss_wots_parameters.cpp.

References WOTSP_SHA2_256_W16, WOTSP_SHA2_512_W16, WOTSP_SHAKE128_W16, and WOTSP_SHAKE256_W16.

24  {
25  if(param_set == "WOTSP_SHA2-256_W16")
26  { return WOTSP_SHA2_256_W16; }
27  if(param_set == "WOTSP_SHA2-512_W16")
28  { return WOTSP_SHA2_512_W16; }
29  if(param_set == "WOTSP_SHAKE128_W16")
30  { return WOTSP_SHAKE128_W16; }
31  if(param_set == "WOTSP_SHAKE256_W16")
32  { return WOTSP_SHAKE256_W16; }
33  throw Invalid_Argument("Unknown XMSS-WOTS algorithm param '" + param_set + "'");
34  }

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