Botan 3.9.0
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_Generatoroperator= (const RFC6979_Nonce_Generator &other)=delete
RFC6979_Nonce_Generatoroperator= (RFC6979_Nonce_Generator &&other) noexcept
 RFC6979_Nonce_Generator (const RFC6979_Nonce_Generator &other)=delete
 RFC6979_Nonce_Generator (RFC6979_Nonce_Generator &&other) noexcept
 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() [1/3]

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

Definition at line 22 of file rfc6979.cpp.

22 :
23 m_qlen(order_bits), m_rlen((m_qlen + 7) / 8), m_rng_in(m_rlen * 2), m_rng_out(m_rlen) {
24 m_hmac_drbg = std::make_unique<HMAC_DRBG>(MessageAuthenticationCode::create_or_throw(fmt("HMAC({})", hash)));
25
26 x.serialize_to(std::span{m_rng_in}.first(m_rlen));
27}
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().

Referenced by operator=(), operator=(), RFC6979_Nonce_Generator(), and RFC6979_Nonce_Generator().

◆ RFC6979_Nonce_Generator() [2/3]

Botan::RFC6979_Nonce_Generator::RFC6979_Nonce_Generator ( const RFC6979_Nonce_Generator & other)
delete

◆ RFC6979_Nonce_Generator() [3/3]

Botan::RFC6979_Nonce_Generator::RFC6979_Nonce_Generator ( RFC6979_Nonce_Generator && other)
defaultnoexcept

◆ ~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 29 of file rfc6979.cpp.

29 {
30 BOTAN_DEBUG_ASSERT(order.bits() == m_qlen);
31
32 m.serialize_to(std::span{m_rng_in}.last(m_rlen));
33
34 m_hmac_drbg->initialize_with(m_rng_in);
35
36 const size_t shift = 8 * m_rlen - m_qlen;
37 BOTAN_ASSERT_NOMSG(shift < 8);
38
39 BigInt k;
40
41 for(;;) {
42 m_hmac_drbg->randomize(m_rng_out);
43 k._assign_from_bytes(m_rng_out);
44
45 if(shift > 0) {
46 k >>= shift;
47 }
48
49 if(k > 0 && k < order) {
50 break;
51 }
52 }
53
54 return k;
55}
#define BOTAN_ASSERT_NOMSG(expr)
Definition assert.h:75
#define BOTAN_DEBUG_ASSERT(expr)
Definition assert.h:129

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().

◆ operator=() [1/2]

RFC6979_Nonce_Generator & Botan::RFC6979_Nonce_Generator::operator= ( const RFC6979_Nonce_Generator & other)
delete

◆ operator=() [2/2]

RFC6979_Nonce_Generator & Botan::RFC6979_Nonce_Generator::operator= ( RFC6979_Nonce_Generator && other)
defaultnoexcept

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