|
Botan
1.11.15
|
#include <x931_rng.h>
Public Member Functions | |
| void | add_entropy (const byte[], size_t) |
| ANSI_X931_RNG (BlockCipher *cipher, RandomNumberGenerator *rng) | |
| void | clear () |
| bool | is_seeded () const |
| std::string | name () const |
| byte | next_byte () |
| virtual secure_vector< byte > | random_vec (size_t bytes) |
| void | randomize (byte[], size_t) |
| void | reseed (size_t poll_bits) |
Static Public Member Functions | |
| static RandomNumberGenerator * | make_rng () |
ANSI X9.31 RNG
Definition at line 19 of file x931_rng.h.
| Botan::ANSI_X931_RNG::ANSI_X931_RNG | ( | BlockCipher * | cipher, |
| RandomNumberGenerator * | rng | ||
| ) |
| cipher | the block cipher to use in this PRNG |
| rng | the underlying PRNG for generating inputs (eg, an HMAC_RNG) |
Definition at line 108 of file x931_rng.cpp.
:
m_cipher(cipher),
m_prng(prng),
m_R(m_cipher->block_size()),
m_R_pos(0)
{
}
| void Botan::ANSI_X931_RNG::add_entropy | ( | const byte | in[], |
| size_t | length | ||
| ) | [virtual] |
Add entropy to this RNG.
| in | a byte array containg the entropy to be added |
| length | the length of the byte array in |
Implements Botan::RandomNumberGenerator.
Definition at line 82 of file x931_rng.cpp.
{
m_prng->add_entropy(input, length);
rekey();
}
| void Botan::ANSI_X931_RNG::clear | ( | ) | [virtual] |
Clear all internally held values of this RNG.
Implements Botan::RandomNumberGenerator.
Definition at line 93 of file x931_rng.cpp.
References Botan::zeroise().
{
m_cipher->clear();
m_prng->clear();
zeroise(m_R);
m_V.clear();
m_R_pos = 0;
}
| bool Botan::ANSI_X931_RNG::is_seeded | ( | ) | const [virtual] |
Check whether this RNG is seeded.
Implements Botan::RandomNumberGenerator.
Definition at line 88 of file x931_rng.cpp.
Referenced by randomize().
{
return (m_V.size() > 0);
}
| RandomNumberGenerator * Botan::RandomNumberGenerator::make_rng | ( | ) | [static, inherited] |
Create a seeded and active RNG object for general application use Added in 1.8.0
Definition at line 14 of file rng.cpp.
{
std::unique_ptr<RandomNumberGenerator> rng(
new HMAC_RNG(make_a<MessageAuthenticationCode>("HMAC(SHA-512)"),
make_a<MessageAuthenticationCode>("HMAC(SHA-256)"))
);
rng->reseed(256);
return rng.release();
}
| std::string Botan::ANSI_X931_RNG::name | ( | ) | const [virtual] |
Return the name of this object
Implements Botan::RandomNumberGenerator.
Definition at line 103 of file x931_rng.cpp.
Referenced by randomize().
{
return "X9.31(" + m_cipher->name() + ")";
}
| byte Botan::RandomNumberGenerator::next_byte | ( | ) | [inline, inherited] |
Return a random byte
Definition at line 53 of file rng.h.
Referenced by Botan::random_prime().
| virtual secure_vector<byte> Botan::RandomNumberGenerator::random_vec | ( | size_t | bytes | ) | [inline, virtual, inherited] |
Return a random vector
| bytes | number of bytes in the result |
Definition at line 42 of file rng.h.
Referenced by Botan::TLS::Client_Key_Exchange::Client_Key_Exchange(), Botan::Curve25519_PrivateKey::Curve25519_PrivateKey(), Botan::TLS::Session::encrypt(), Botan::KeyPair::encryption_consistency_check(), Botan::generate_bcrypt(), Botan::mceies_encrypt(), Botan::OctetString::OctetString(), Botan::pbes2_encrypt(), Botan::BigInt::randomize(), Botan::TLS::Session_Manager_SQL::Session_Manager_SQL(), and Botan::KeyPair::signature_consistency_check().
{
secure_vector<byte> output(bytes);
randomize(&output[0], output.size());
return output;
}
| void Botan::ANSI_X931_RNG::randomize | ( | byte | output[], |
| size_t | length | ||
| ) | [virtual] |
Randomize a byte array.
| output | the byte array to hold the random output. |
| length | the length of the byte array output. |
Implements Botan::RandomNumberGenerator.
Definition at line 14 of file x931_rng.cpp.
References Botan::copy_mem(), is_seeded(), name(), and reseed().
{
if(!is_seeded())
{
reseed(BOTAN_RNG_RESEED_POLL_BITS);
if(!is_seeded())
throw PRNG_Unseeded(name());
}
while(length)
{
if(m_R_pos == m_R.size())
update_buffer();
const size_t copied = std::min<size_t>(length, m_R.size() - m_R_pos);
copy_mem(out, &m_R[m_R_pos], copied);
out += copied;
length -= copied;
m_R_pos += copied;
}
}
| void Botan::ANSI_X931_RNG::reseed | ( | size_t | bits_to_collect | ) | [virtual] |
Seed this RNG using the entropy sources it contains.
| bits_to_collect | is the number of bits of entropy to attempt to gather from the entropy sources |
Implements Botan::RandomNumberGenerator.
Definition at line 76 of file x931_rng.cpp.
Referenced by randomize().
{
m_prng->reseed(poll_bits);
rekey();
}
1.7.6.1