Botan 3.6.1
Crypto and TLS for C&
Botan::RFC6979_Nonce_Generator Class Referencefinal

#include <rfc6979.h>

Public Member Functions

BigInt nonce_for (const BigInt &group_order, const BigInt &m)
 
 RFC6979_Nonce_Generator (std::string_view hash, size_t order_bits, const BigInt &x)
 
 ~RFC6979_Nonce_Generator ()
 

Detailed Description

Definition at line 24 of file rfc6979.h.

Constructor & Destructor Documentation

◆ RFC6979_Nonce_Generator()

Botan::RFC6979_Nonce_Generator::RFC6979_Nonce_Generator ( std::string_view hash,
size_t order_bits,
const BigInt & x )

Definition at line 18 of file rfc6979.cpp.

18 :
19 m_qlen(order_bits), m_rlen((m_qlen + 7) / 8), m_rng_in(m_rlen * 2), m_rng_out(m_rlen) {
20 m_hmac_drbg = std::make_unique<HMAC_DRBG>(MessageAuthenticationCode::create_or_throw(fmt("HMAC({})", hash)));
21
22 x.serialize_to(std::span{m_rng_in}.first(m_rlen));
23}
static std::unique_ptr< MessageAuthenticationCode > create_or_throw(std::string_view algo_spec, std::string_view provider="")
Definition mac.cpp:148
std::string fmt(std::string_view format, const T &... args)
Definition fmt.h:53

References Botan::MessageAuthenticationCode::create_or_throw(), Botan::fmt(), and Botan::BigInt::serialize_to().

◆ ~RFC6979_Nonce_Generator()

Botan::RFC6979_Nonce_Generator::~RFC6979_Nonce_Generator ( )
default

Member Function Documentation

◆ nonce_for()

BigInt Botan::RFC6979_Nonce_Generator::nonce_for ( const BigInt & group_order,
const BigInt & m )

Definition at line 25 of file rfc6979.cpp.

25 {
26 BOTAN_DEBUG_ASSERT(order.bits() == m_qlen);
27
28 m.serialize_to(std::span{m_rng_in}.last(m_rlen));
29
30 m_hmac_drbg->initialize_with(m_rng_in);
31
32 const size_t shift = 8 * m_rlen - m_qlen;
33 BOTAN_ASSERT_NOMSG(shift < 8);
34
35 BigInt k;
36
37 do {
38 m_hmac_drbg->randomize(m_rng_out);
39 k._assign_from_bytes(m_rng_out);
40
41 if(shift > 0) {
42 k >>= shift;
43 }
44 } while(k == 0 || k >= order);
45
46 return k;
47}
#define BOTAN_ASSERT_NOMSG(expr)
Definition assert.h:59
#define BOTAN_DEBUG_ASSERT(expr)
Definition assert.h:98

References Botan::BigInt::_assign_from_bytes(), Botan::BigInt::bits(), BOTAN_ASSERT_NOMSG, BOTAN_DEBUG_ASSERT, and Botan::BigInt::serialize_to().

Referenced by Botan::generate_rfc6979_nonce().


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