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

#include <rfc6979.h>

Public Member Functions

const BigIntnonce_for (const BigInt &m)
 
 RFC6979_Nonce_Generator (std::string_view hash, const BigInt &order, const BigInt &x)
 
 ~RFC6979_Nonce_Generator ()
 

Detailed Description

Definition at line 19 of file rfc6979.h.

Constructor & Destructor Documentation

◆ RFC6979_Nonce_Generator()

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

Note: keeps persistent reference to order

Definition at line 16 of file rfc6979.cpp.

16 :
17 m_order(order),
18 m_qlen(m_order.bits()),
19 m_rlen(m_qlen / 8 + (m_qlen % 8 ? 1 : 0)),
20 m_rng_in(m_rlen * 2),
21 m_rng_out(m_rlen) {
22 m_hmac_drbg = std::make_unique<HMAC_DRBG>(MessageAuthenticationCode::create_or_throw(fmt("HMAC({})", hash)));
23
24 x.serialize_to(std::span{m_rng_in}.first(m_rlen));
25}
size_t bits() const
Definition bigint.cpp:295
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()

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

Definition at line 29 of file rfc6979.cpp.

29 {
30 m.serialize_to(std::span{m_rng_in}.subspan(m_rlen));
31 m_hmac_drbg->clear();
32 m_hmac_drbg->initialize_with(m_rng_in.data(), m_rng_in.size());
33
34 do {
35 m_hmac_drbg->randomize(m_rng_out.data(), m_rng_out.size());
36 m_k._assign_from_bytes(m_rng_out);
37 m_k >>= (8 * m_rlen - m_qlen);
38 } while(m_k == 0 || m_k >= m_order);
39
40 return m_k;
41}
void _assign_from_bytes(std::span< const uint8_t > bytes)
Definition bigint.h:942

References Botan::BigInt::_assign_from_bytes(), and Botan::BigInt::serialize_to().

Referenced by Botan::generate_rfc6979_nonce().


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