Botan  2.7.0
Crypto and TLS for C++11
Public Member Functions | List of all members
Botan::XMSS_Hash Class Referencefinal

#include <xmss_hash.h>

Public Member Functions

void f (secure_vector< uint8_t > &result, const secure_vector< uint8_t > &key, const secure_vector< uint8_t > &data)
 
void h (secure_vector< uint8_t > &result, const secure_vector< uint8_t > &key, const secure_vector< uint8_t > &data)
 
secure_vector< uint8_t > h_msg (const secure_vector< uint8_t > &randomness, const secure_vector< uint8_t > &root, const secure_vector< uint8_t > &index_bytes, const secure_vector< uint8_t > &data)
 
secure_vector< uint8_t > h_msg_final ()
 
void h_msg_init (const secure_vector< uint8_t > &randomness, const secure_vector< uint8_t > &root, const secure_vector< uint8_t > &index_bytes)
 
void h_msg_update (const uint8_t data[], size_t size)
 
size_t output_length () const
 
void prf (secure_vector< uint8_t > &result, const secure_vector< uint8_t > &key, const secure_vector< uint8_t > &data)
 
secure_vector< uint8_t > prf (const secure_vector< uint8_t > &key, const secure_vector< uint8_t > &data)
 
 XMSS_Hash (const std::string &h_func_name)
 
 XMSS_Hash (const XMSS_Hash &hash)
 

Detailed Description

A collection of pseudorandom hash functions required for XMSS and WOTS computations.

Definition at line 19 of file xmss_hash.h.

Constructor & Destructor Documentation

◆ XMSS_Hash() [1/2]

Botan::XMSS_Hash::XMSS_Hash ( const std::string &  h_func_name)

Definition at line 20 of file xmss_hash.cpp.

20  :
21  m_hash(HashFunction::create(h_func_name)),
22  m_hash_func_name(h_func_name)
23  {
24  if(!m_hash)
25  throw Lookup_Error("XMSS cannot use hash " + h_func_name +
26  " because it is unavailable");
27 
28  m_output_length = m_hash->output_length();
29  BOTAN_ASSERT(m_output_length > 0, "Hash output length of zero is invalid.");
30 
31  m_zero_padding.resize(m_output_length - 1);
32  m_msg_hash.reset(m_hash->clone());
33  }
#define BOTAN_ASSERT(expr, assertion_made)
Definition: assert.h:43
static std::unique_ptr< HashFunction > create(const std::string &algo_spec, const std::string &provider="")
Definition: hash.cpp:106

◆ XMSS_Hash() [2/2]

Botan::XMSS_Hash::XMSS_Hash ( const XMSS_Hash hash)

Definition at line 15 of file xmss_hash.cpp.

16  : XMSS_Hash(hash.m_hash_func_name)
17  {
18  }
XMSS_Hash(const std::string &h_func_name)
Definition: xmss_hash.cpp:20
MechanismType hash

Member Function Documentation

◆ f()

void Botan::XMSS_Hash::f ( secure_vector< uint8_t > &  result,
const secure_vector< uint8_t > &  key,
const secure_vector< uint8_t > &  data 
)
inline

F is a keyed cryptographic hash function used by the WOTS+ algorithm.

Parameters
[out]resultThe hash calculated using key and data.
[in]keykey of length n bytes.
[in]datastring of arbitrary length.

Definition at line 69 of file xmss_hash.h.

72  {
73  m_hash->update(m_zero_padding);
74  m_hash->update(m_id_f);
75  m_hash->update(key);
76  m_hash->update(data);
77  m_hash->final(result);
78  }

◆ h()

void Botan::XMSS_Hash::h ( secure_vector< uint8_t > &  result,
const secure_vector< uint8_t > &  key,
const secure_vector< uint8_t > &  data 
)

Cryptographic hash function h accepting n byte keys and 2n byte strings of data.

Parameters
[out]resultThe hash calculated using key and data.
[in]keykey of length n bytes.
[in]datastring of 2n bytes length.

Definition at line 36 of file xmss_hash.cpp.

39  {
40  m_hash->update(m_zero_padding);
41  m_hash->update(m_id_h);
42  m_hash->update(key);
43  m_hash->update(data);
44  m_hash->final(result);
45  }

◆ h_msg()

secure_vector< uint8_t > Botan::XMSS_Hash::h_msg ( const secure_vector< uint8_t > &  randomness,
const secure_vector< uint8_t > &  root,
const secure_vector< uint8_t > &  index_bytes,
const secure_vector< uint8_t > &  data 
)

Cryptographic hash function h accepting 3n byte keys and data strings of arbitrary length.

Parameters
randomnessn-byte value.
rootn-byte root node.
index_bytesIndex value padded with leading zeros.
datastring of arbitrary length.
Returns
hash value of n-bytes length.

Definition at line 70 of file xmss_hash.cpp.

References h_msg_init().

74  {
75  h_msg_init(randomness, root, index_bytes);
76  m_msg_hash->update(data);
77  return m_msg_hash->final();
78  }
void h_msg_init(const secure_vector< uint8_t > &randomness, const secure_vector< uint8_t > &root, const secure_vector< uint8_t > &index_bytes)
Definition: xmss_hash.cpp:47

◆ h_msg_final()

secure_vector< uint8_t > Botan::XMSS_Hash::h_msg_final ( )

Finalizes buffered h_msg computation and retrieves the result.

Returns
Hash calculated using the prefix set by h_msg_init() and message blocks provided through calls to h_msg_update().

Definition at line 64 of file xmss_hash.cpp.

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

65  {
66  return m_msg_hash->final();
67  }

◆ h_msg_init()

void Botan::XMSS_Hash::h_msg_init ( const secure_vector< uint8_t > &  randomness,
const secure_vector< uint8_t > &  root,
const secure_vector< uint8_t > &  index_bytes 
)

Initializes buffered h_msg computation with prefix data.

Parameters
randomnessrandom n-byte value.
rootn-byte root node.
index_bytesIndex value padded with leading zeros.

Definition at line 47 of file xmss_hash.cpp.

Referenced by h_msg().

50  {
51  m_msg_hash->clear();
52  m_msg_hash->update(m_zero_padding);
53  m_msg_hash->update(m_id_hmsg);
54  m_msg_hash->update(randomness);
55  m_msg_hash->update(root);
56  m_msg_hash->update(index_bytes);
57  }

◆ h_msg_update()

void Botan::XMSS_Hash::h_msg_update ( const uint8_t  data[],
size_t  size 
)

Adds a message block to buffered h_msg computation.

Parameters
dataA message block
sizeLength of the message block in bytes.

Definition at line 59 of file xmss_hash.cpp.

Referenced by Botan::XMSS_Signature_Operation::update().

60  {
61  m_msg_hash->update(data, size);
62  }

◆ output_length()

size_t Botan::XMSS_Hash::output_length ( ) const
inline

Definition at line 135 of file xmss_hash.h.

135 { return m_output_length; }

◆ prf() [1/2]

void Botan::XMSS_Hash::prf ( secure_vector< uint8_t > &  result,
const secure_vector< uint8_t > &  key,
const secure_vector< uint8_t > &  data 
)
inline

Pseudoranom function creating a hash out of a key and data using a cryptographic hash function.

Parameters
[out]resultThe hash calculated using key and data.
[in]keyAn n-byte key value.
[in]dataA 32-byte XMSS_Address data value

Definition at line 33 of file xmss_hash.h.

36  {
37  m_hash->update(m_zero_padding);
38  m_hash->update(m_id_prf);
39  m_hash->update(key);
40  m_hash->update(data);
41  m_hash->final(result);
42  }

◆ prf() [2/2]

secure_vector<uint8_t> Botan::XMSS_Hash::prf ( const secure_vector< uint8_t > &  key,
const secure_vector< uint8_t > &  data 
)
inline

Pseudoranom function creating a hash out of a key and data using a cryptographic hash function.

Parameters
[in]keyAn n-byte key value.
[in]dataA 32-byte XMSS_Address data value
Returns
result The hash calculated using key and data.

Definition at line 52 of file xmss_hash.h.

54  {
55  m_hash->update(m_zero_padding);
56  m_hash->update(m_id_prf);
57  m_hash->update(key);
58  m_hash->update(data);
59  return m_hash->final();
60  }

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