Botan 3.11.0
Crypto and TLS for C&
rfc6979.h
Go to the documentation of this file.
1/*
2* RFC 6979 Deterministic Nonce Generator
3* (C) 2014,2015,2024 Jack Lloyd
4*
5* Botan is released under the Simplified BSD License (see license.txt)
6*/
7
8#ifndef BOTAN_RFC6979_GENERATOR_H_
9#define BOTAN_RFC6979_GENERATOR_H_
10
11#include <botan/bigint.h>
12#include <memory>
13#include <string_view>
14
15#if defined(BOTAN_HAS_ECC_GROUP)
16 #include <botan/ec_scalar.h>
17#endif
18
19namespace Botan {
20
21class HMAC_DRBG;
22
24 public:
25 RFC6979_Nonce_Generator(std::string_view hash, size_t order_bits, const BigInt& x);
26
27 BigInt nonce_for(const BigInt& group_order, const BigInt& m);
28
29#if defined(BOTAN_HAS_ECC_GROUP)
30 RFC6979_Nonce_Generator(std::string_view hash, size_t order_bits, const EC_Scalar& scalar);
31
32 EC_Scalar nonce_for(const EC_Group& group, const EC_Scalar& m);
33#endif
34
37
41
42 private:
43 size_t m_qlen;
44 size_t m_rlen;
45 std::unique_ptr<HMAC_DRBG> m_hmac_drbg;
47 secure_vector<uint8_t> m_rng_out;
48};
49
50/**
51* @param x the secret (EC)DSA key
52* @param q the group order
53* @param h the message hash already reduced mod q
54* @param hash the hash function used to generate h
55*/
56inline BigInt generate_rfc6979_nonce(const BigInt& x, const BigInt& q, const BigInt& h, std::string_view hash) {
57 RFC6979_Nonce_Generator gen(hash, q.bits(), x);
58 return gen.nonce_for(q, h);
59}
60
61} // namespace Botan
62
63#endif
#define BOTAN_TEST_API
Definition api.h:41
size_t bits() const
Definition bigint.cpp:307
RFC6979_Nonce_Generator(const RFC6979_Nonce_Generator &other)=delete
RFC6979_Nonce_Generator & operator=(RFC6979_Nonce_Generator &&other) noexcept
RFC6979_Nonce_Generator & operator=(const RFC6979_Nonce_Generator &other)=delete
RFC6979_Nonce_Generator(std::string_view hash, size_t order_bits, const BigInt &x)
Definition rfc6979.cpp:22
RFC6979_Nonce_Generator(RFC6979_Nonce_Generator &&other) noexcept
BigInt nonce_for(const BigInt &group_order, const BigInt &m)
Definition rfc6979.cpp:29
BigInt generate_rfc6979_nonce(const BigInt &x, const BigInt &q, const BigInt &h, std::string_view hash)
Definition rfc6979.h:56
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:68