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

#include <xmss_wots.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 32 of file xmss_wots.h.

Member Enumeration Documentation

◆ ots_algorithm_t

Enumerator
WOTSP_SHA2_256 
WOTSP_SHA2_512 
WOTSP_SHAKE_256 
WOTSP_SHAKE_512 

Definition at line 35 of file xmss_wots.h.

36 {
37 WOTSP_SHA2_256 = 0x00000001,
38 WOTSP_SHA2_512 = 0x00000002,
39 WOTSP_SHAKE_256 = 0x00000003,
40 WOTSP_SHAKE_512 = 0x00000004
41 };

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 {}
XMSS_WOTS_Parameters(const std::string &algo_name)
static ots_algorithm_t xmss_wots_id_from_string(const std::string &param_set)

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

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

Member Function Documentation

◆ append_checksum()

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

Definition at line 124 of file xmss_wots_parameters.cpp.

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

References base_w(), and wots_parameter().

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

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

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

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

◆ base_w() [2/2]

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

Definition at line 113 of file xmss_wots_parameters.cpp.

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

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

◆ 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 85 of file xmss_wots.h.

85{ return m_element_size; }

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

◆ estimated_strength()

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

Definition at line 105 of file xmss_wots.h.

105{ return m_strength; }

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

◆ 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 73 of file xmss_wots.h.

74 {
75 return m_hash_name;
76 }

◆ len()

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

Definition at line 95 of file xmss_wots.h.

95{ return m_len; }

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

◆ len_1()

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

Definition at line 97 of file xmss_wots.h.

97{ return m_len_1; }

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

◆ len_2()

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

Definition at line 99 of file xmss_wots.h.

99{ return m_len_2; }

◆ lg_w()

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

Definition at line 101 of file xmss_wots.h.

101{ 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 65 of file xmss_wots.h.

66 {
67 return m_name;
68 }

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

◆ oid()

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

Definition at line 103 of file xmss_wots.h.

103{ return m_oid; }

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

◆ operator==()

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

Definition at line 107 of file xmss_wots.h.

108 {
109 return m_oid == p.m_oid;
110 }

◆ 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 93 of file xmss_wots.h.

93{ return m_w; }

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

◆ 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.

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

References WOTSP_SHA2_256, WOTSP_SHA2_512, WOTSP_SHAKE_256, and WOTSP_SHAKE_512.


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