A random generator that only fetches random from the PKCS#11 RNG.
More...
#include <p11_randomgenerator.h>
|
| bool | accepts_input () const override |
| |
| void | add_entropy (const uint8_t input[], size_t length) |
| |
| void | add_entropy (std::span< const uint8_t > input) |
| |
template<typename T >
requires std::is_standard_layout_v<T> && std::is_trivial_v<T> |
| void | add_entropy_T (const T &t) |
| |
| void | clear () final |
| |
| bool | is_seeded () const override |
| | Always returns true.
|
| |
| Module & | module () const |
| |
| std::string | name () const override |
| |
| uint8_t | next_byte () |
| |
| uint8_t | next_nonzero_byte () |
| |
| | PKCS11_RNG (Session &session) |
| | Initialize the RNG with the PKCS#11 session that provides access to the cryptoki functions.
|
| |
| template<size_t bytes> |
| std::array< uint8_t, bytes > | random_array () |
| |
template<concepts::resizable_byte_buffer T = secure_vector<uint8_t>>
requires std::default_initializable<T> |
| T | random_vec (size_t bytes) |
| |
| void | random_vec (std::span< uint8_t > v) |
| |
| template<concepts::resizable_byte_buffer T> |
| void | random_vec (T &v, size_t bytes) |
| |
| void | randomize (std::span< uint8_t > output) |
| |
| void | randomize (uint8_t output[], size_t length) |
| |
| void | randomize_with_input (std::span< uint8_t > output, std::span< const uint8_t > input) |
| |
| void | randomize_with_input (uint8_t output[], size_t output_len, const uint8_t input[], size_t input_len) |
| |
| void | randomize_with_ts_input (std::span< uint8_t > output) |
| |
| void | randomize_with_ts_input (uint8_t output[], size_t output_len) |
| |
| size_t | reseed (Entropy_Sources &, size_t, std::chrono::milliseconds) override |
| | No operation - always returns 0.
|
| |
| virtual void | reseed_from_rng (RandomNumberGenerator &rng, size_t poll_bits=RandomNumberGenerator::DefaultPollBits) |
| |
A random generator that only fetches random from the PKCS#11 RNG.
Definition at line 23 of file p11_randomgenerator.h.
◆ PKCS11_RNG()
| Botan::PKCS11::PKCS11_RNG::PKCS11_RNG |
( |
Session & | session | ) |
|
|
explicit |
Initialize the RNG with the PKCS#11 session that provides access to the cryptoki functions.
Definition at line 13 of file p11_randomgenerator.cpp.
13: m_session(session) {}
◆ accepts_input()
| bool Botan::PKCS11::PKCS11_RNG::accepts_input |
( |
| ) |
const |
|
inlineoverridevirtual |
Returns false if it is known that this RNG object is not able to accept externally provided inputs (via add_entropy, randomize_with_input, etc). In this case, any such provided inputs are ignored.
If this function returns true, then inputs may or may not be accepted.
Implements Botan::RandomNumberGenerator.
Definition at line 42 of file p11_randomgenerator.h.
◆ add_entropy() [1/2]
| void Botan::RandomNumberGenerator::add_entropy |
( |
const uint8_t | input[], |
|
|
size_t | length ) |
|
inlineinherited |
◆ add_entropy() [2/2]
| void Botan::RandomNumberGenerator::add_entropy |
( |
std::span< const uint8_t > | input | ) |
|
|
inlineinherited |
◆ add_entropy_T()
template<typename
T >
requires std::is_standard_layout_v<
T> && std::is_trivial_v<
T>
| void Botan::RandomNumberGenerator::add_entropy_T |
( |
const T & | t | ) |
|
|
inlineinherited |
◆ clear()
| void Botan::Hardware_RNG::clear |
( |
| ) |
|
|
inlinefinalvirtualinherited |
◆ is_seeded()
| bool Botan::PKCS11::PKCS11_RNG::is_seeded |
( |
| ) |
const |
|
inlineoverridevirtual |
◆ module()
| Module & Botan::PKCS11::PKCS11_RNG::module |
( |
| ) |
const |
|
inline |
- Returns
- the module used by this RNG
Definition at line 39 of file p11_randomgenerator.h.
39{ return m_session.get().module(); }
◆ name()
| std::string Botan::PKCS11::PKCS11_RNG::name |
( |
| ) |
const |
|
inlineoverridevirtual |
◆ next_byte()
| uint8_t Botan::RandomNumberGenerator::next_byte |
( |
| ) |
|
|
inlineinherited |
Return a random byte
- Returns
- random byte
- Exceptions
-
Definition at line 247 of file rng.h.
247 {
248 uint8_t b = 0;
250 return b;
251 }
Referenced by Botan::random_prime().
◆ next_nonzero_byte()
| uint8_t Botan::RandomNumberGenerator::next_nonzero_byte |
( |
| ) |
|
|
inlineinherited |
- Returns
- a random byte that is greater than zero
- Exceptions
-
Definition at line 258 of file rng.h.
258 {
260 while(b == 0) {
262 }
263 return b;
264 }
◆ random_array()
template<size_t bytes>
| std::array< uint8_t, bytes > Botan::RandomNumberGenerator::random_array |
( |
| ) |
|
|
inlineinherited |
Create a std::array of bytes random bytes
Definition at line 235 of file rng.h.
235 {
236 std::array<uint8_t, bytes> result{};
238 return result;
239 }
void random_vec(std::span< uint8_t > v)
◆ random_vec() [1/3]
template<concepts::resizable_byte_buffer T = secure_vector<uint8_t>>
requires std::default_initializable<
T>
| T Botan::RandomNumberGenerator::random_vec |
( |
size_t | bytes | ) |
|
|
inlineinherited |
Create some byte container type and fill it with some random bytes.
- Template Parameters
-
| T | the desired byte container type (e.g std::vector<uint8_t>) |
- Parameters
-
| bytes | number of random bytes to initialize the container with |
- Returns
- a container of type T with
bytes random bytes
- Exceptions
-
Definition at line 225 of file rng.h.
225 {
228 return result;
229 }
References T.
◆ random_vec() [2/3]
| void Botan::RandomNumberGenerator::random_vec |
( |
std::span< uint8_t > | v | ) |
|
|
inlineinherited |
Fill a given byte container with bytes random bytes
- Todo
- deprecate this overload (in favor of randomize())
- Parameters
-
| v | the container to be filled with bytes random bytes |
- Exceptions
-
Definition at line 199 of file rng.h.
void randomize(std::span< uint8_t > output)
Referenced by Botan::Classic_McEliece_PrivateKey::Classic_McEliece_PrivateKey(), Botan::TLS::Client_Key_Exchange::Client_Key_Exchange(), Botan::TLS::Client_Key_Exchange::Client_Key_Exchange(), Botan::PK_Decryptor::decrypt_or_random(), Botan::Dilithium_PrivateKey::Dilithium_PrivateKey(), Botan::Ed25519_PrivateKey::Ed25519_PrivateKey(), Botan::Kyber_KEM_Encryptor::encapsulate(), Botan::ML_KEM_Encryptor::encapsulate(), Botan::TLS::Session::encrypt(), Botan::KeyPair::encryption_consistency_check(), Botan::FrodoKEM_PrivateKey::FrodoKEM_PrivateKey(), Botan::generate_bcrypt(), Botan::HSS_LMS_PrivateKeyInternal::HSS_LMS_PrivateKeyInternal(), Botan::Kyber_PrivateKey::Kyber_PrivateKey(), Botan::TLS::make_hello_random(), Botan::OctetString::OctetString(), Botan::BigInt::randomize(), Botan::RandomNumberGenerator::reseed_from_rng(), Botan::SphincsPlus_PrivateKey::SphincsPlus_PrivateKey(), and Botan::X25519_PrivateKey::X25519_PrivateKey().
◆ random_vec() [3/3]
template<concepts::resizable_byte_buffer T>
| void Botan::RandomNumberGenerator::random_vec |
( |
T & | v, |
|
|
size_t | bytes ) |
|
inlineinherited |
Resize a given byte container to bytes and fill it with random bytes
- Template Parameters
-
| T | the desired byte container type (e.g std::vector<uint8_t>) |
- Parameters
-
| v | the container to be filled with bytes random bytes |
| bytes | number of random bytes to initialize the container with |
- Exceptions
-
Definition at line 210 of file rng.h.
210 {
211 v.resize(bytes);
213 }
◆ randomize() [1/2]
| void Botan::RandomNumberGenerator::randomize |
( |
std::span< uint8_t > | output | ) |
|
|
inlineinherited |
Randomize a byte array.
May block shortly if e.g. the RNG is not yet initialized or a retry because of insufficient entropy is needed.
- Parameters
-
| output | the byte array to hold the random output. |
- Exceptions
-
Definition at line 71 of file rng.h.
Referenced by Botan::TLS::Connection_Cipher_State::aead_nonce(), Botan::argon2_generate_pwhash(), Botan::BlindedScalarBits< C, WindowBits >::BlindedScalarBits(), botan_system_rng_get(), Botan::CryptoBox::encrypt(), Botan::generate_dsa_primes(), Botan::generate_passhash9(), Botan::IntMod< Rep >::random(), Botan::random_gf2m(), Botan::McEliece_PublicKey::random_plaintext_element(), Botan::random_prime(), Botan::Sodium::randombytes_buf(), Botan::RandomNumberGenerator::randomize_with_ts_input(), Botan::KeyPair::signature_consistency_check(), Botan::RTSS_Share::split(), and Botan::UUID::UUID().
◆ randomize() [2/2]
| void Botan::RandomNumberGenerator::randomize |
( |
uint8_t | output[], |
|
|
size_t | length ) |
|
inlineinherited |
◆ randomize_with_input() [1/2]
| void Botan::RandomNumberGenerator::randomize_with_input |
( |
std::span< uint8_t > | output, |
|
|
std::span< const uint8_t > | input ) |
|
inlineinherited |
Incorporate entropy into the RNG state then produce output. Some RNG types implement this using a single operation, default calls add_entropy + randomize in sequence.
Use this to further bind the outputs to your current process/protocol state. For instance if generating a new key for use in a session, include a session ID or other such value. See NIST SP 800-90 A, B, C series for more ideas.
- Parameters
-
| output | buffer to hold the random output |
| input | entropy buffer to incorporate |
- Exceptions
-
| PRNG_Unseeded | if the RNG fails because it has not enough entropy |
| Exception | if the RNG fails |
| Exception | may throw if the RNG accepts input, but adding the entropy failed. |
Definition at line 123 of file rng.h.
Referenced by Botan::System_RNG::fill_bytes_with_input().
◆ randomize_with_input() [2/2]
| void Botan::RandomNumberGenerator::randomize_with_input |
( |
uint8_t | output[], |
|
|
size_t | output_len, |
|
|
const uint8_t | input[], |
|
|
size_t | input_len ) |
|
inlineinherited |
Definition at line 127 of file rng.h.
127 {
129 }
void randomize_with_input(std::span< uint8_t > output, std::span< const uint8_t > input)
◆ randomize_with_ts_input() [1/2]
| void Botan::RandomNumberGenerator::randomize_with_ts_input |
( |
std::span< uint8_t > | output | ) |
|
|
inherited |
This calls randomize_with_input using some timestamps as extra input.
For a stateful RNG using non-random but potentially unique data the extra input can help protect against problems with fork, VM state rollback, or other cases where somehow an RNG state is duplicated. If both of the duplicated RNG states later incorporate a timestamp (and the timestamps don't themselves repeat), their outputs will diverge.
- Parameters
-
| output | buffer to hold the random output |
- Exceptions
-
| PRNG_Unseeded | if the RNG fails because it has not enough entropy |
| Exception | if the RNG fails |
| Exception | may throw if the RNG accepts input, but adding the entropy failed. |
Definition at line 27 of file rng.cpp.
27 {
29 std::array<uint8_t, 32> additional_input = {0};
30
31#if defined(BOTAN_HAS_OS_UTILS)
34 constexpr size_t offset = 12;
35#else
36 constexpr size_t offset = 0;
37#endif
38
39#if defined(BOTAN_HAS_SYSTEM_RNG)
41#else
43#endif
44
46 } else {
48 }
49}
virtual bool accepts_input() const =0
uint64_t BOTAN_TEST_API get_high_resolution_clock()
uint32_t BOTAN_TEST_API get_process_id()
RandomNumberGenerator & system_rng()
constexpr auto store_le(ParamTs &&... params)
References Botan::RandomNumberGenerator::accepts_input(), BOTAN_UNUSED, Botan::RandomNumberGenerator::fill_bytes_with_input(), Botan::OS::get_high_resolution_clock(), Botan::OS::get_process_id(), Botan::RandomNumberGenerator::randomize(), Botan::store_le(), and Botan::system_rng().
◆ randomize_with_ts_input() [2/2]
| void Botan::RandomNumberGenerator::randomize_with_ts_input |
( |
uint8_t | output[], |
|
|
size_t | output_len ) |
|
inlineinherited |
Definition at line 147 of file rng.h.
147 {
149 }
void randomize_with_ts_input(std::span< uint8_t > output)
◆ reseed()
| size_t Botan::PKCS11::PKCS11_RNG::reseed |
( |
Entropy_Sources & | , |
|
|
size_t | , |
|
|
std::chrono::milliseconds | ) |
|
inlineoverridevirtual |
◆ reseed_from_rng()
◆ DefaultPollBits
| size_t Botan::RandomNumberGenerator::DefaultPollBits = 256 |
|
staticconstexprinherited |
Number of entropy bits polled for reseeding userspace RNGs like HMAC_DRBG
Definition at line 41 of file rng.h.
◆ DefaultPollTimeout
| auto Botan::RandomNumberGenerator::DefaultPollTimeout = std::chrono::milliseconds(50) |
|
staticconstexprinherited |
Default poll timeout
Definition at line 46 of file rng.h.
◆ DefaultReseedInterval
| size_t Botan::RandomNumberGenerator::DefaultReseedInterval = 1024 |
|
staticconstexprinherited |
Userspace RNGs like HMAC_DRBG will reseed after a specified number of outputs are generated. Set to zero to disable automatic reseeding.
Definition at line 36 of file rng.h.
The documentation for this class was generated from the following files: