Botan: Botan::ANSI_X931_RNG Class Reference

Botan 1.10.17

Public Member Functions | Static Public Member Functions | List of all members
Botan::ANSI_X931_RNG Class Reference

`#include <x931_rng.h>`

Inheritance diagram for Botan::ANSI_X931_RNG:

## Public Member Functions
void | add_entropy (const byte[], size_t)
void | add_entropy_source (EntropySource *)
| ANSI_X931_RNG (BlockCipher *cipher, RandomNumberGenerator *rng)
void | clear ()
bool | is_seeded () const
std::string | name () const
byte | next_byte ()
SecureVector< byte > | random_vec (size_t bytes)
void | randomize (byte[], size_t)
void | reseed (size_t poll_bits)
| ~ANSI_X931_RNG ()

## Static Public Member Functions
static RandomNumberGenerator * | make_rng ()

## Detailed Description

ANSI X9.31 RNG

Definition at line 19 of file x931_rng.h.

## Constructor & Destructor Documentation

## ◆ ANSI_X931_RNG()

Botan::ANSI_X931_RNG::ANSI_X931_RNG | ( | BlockCipher * | cipher,
|  | RandomNumberGenerator * | rng
| ) |  |

Parameters

  cipher | the block cipher to use in this PRNG
  rng | the underlying PRNG for generating inputs (eg, an HMAC_RNG)

Definition at line 132 of file x931_rng.cpp.

References Botan::BlockCipher::block_size(), and Botan::MemoryRegion< T >::resize().

134 {
135 if(!prng_in || !cipher_in)
136 throw Invalid_Argument("ANSI_X931_RNG constructor: NULL arguments");
137
138 cipher = cipher_in;
139 prng = prng_in;
140
141 R.resize(cipher->block_size());
142 position = 0;
143 }
Botan::MemoryRegion::resize
void resize(size_t n)
Definition: secmem.h:217
Botan::Invalid_Argument
std::invalid_argument Invalid_Argument
Definition: exceptn.h:20
Botan::BlockCipher::block_size
virtual size_t block_size() const =0

## ◆ ~ANSI_X931_RNG()

Botan::ANSI_X931_RNG::~ANSI_X931_RNG | ( |  | ) |

Definition at line 148 of file x931_rng.cpp.

149 {
150 delete cipher;
151 delete prng;
152 }

## Member Function Documentation

## ◆ add_entropy()

void Botan::ANSI_X931_RNG::add_entropy | ( | const byte | in[],
|  | size_t | length
| ) |  |
| virtual

Add entropy to this RNG.

Parameters

  in | a byte array containg the entropy to be added
  length | the length of the byte array in

Implements Botan::RandomNumberGenerator.

Definition at line 94 of file x931_rng.cpp.

References Botan::RandomNumberGenerator::add_entropy().

95 {
96 prng->add_entropy(input, length);
97 rekey();
98 }
Botan::RandomNumberGenerator::add_entropy
virtual void add_entropy(const byte in[], size_t length)=0

## ◆ add_entropy_source()

void Botan::ANSI_X931_RNG::add_entropy_source | ( | EntropySource * | source | ) |
| virtual

Add this entropy source to the RNG object

Parameters

  source | the entropy source which will be retained and used by RNG

Implements Botan::RandomNumberGenerator.

Definition at line 86 of file x931_rng.cpp.

References Botan::RandomNumberGenerator::add_entropy_source().

87 {
88 prng->add_entropy_source(src);
89 }
Botan::RandomNumberGenerator::add_entropy_source
virtual void add_entropy_source(EntropySource *source)=0

## ◆ clear()

void Botan::ANSI_X931_RNG::clear | ( |  | ) |
| virtual

Clear all internally held values of this RNG.

Implements Botan::RandomNumberGenerator.

Definition at line 111 of file x931_rng.cpp.

References Botan::Algorithm::clear(), Botan::RandomNumberGenerator::clear(), Botan::MemoryRegion< T >::clear(), and Botan::zeroise().

112 {
113 cipher->clear();
114 prng->clear();
115 zeroise(R);
116 V.clear();
117
118 position = 0;
119 }
Botan::Algorithm::clear
virtual void clear()=0
Botan::MemoryRegion::clear
void clear()
Definition: secmem.h:158
Botan::RandomNumberGenerator::clear
virtual void clear()=0
Botan::zeroise
void zeroise(MemoryRegion< T > &vec)
Definition: secmem.h:428

## ◆ is_seeded()

bool Botan::ANSI_X931_RNG::is_seeded | ( |  | ) | const
| virtual

Check whether this RNG is seeded.

Returns
  true if this RNG was already seeded, false otherwise.

Reimplemented from Botan::RandomNumberGenerator.

Definition at line 103 of file x931_rng.cpp.

References Botan::MemoryRegion< T >::size().

Referenced by randomize().

104 {
105 return (V.size() > 0);
106 }
Botan::MemoryRegion::size
size_t size() const
Definition: secmem.h:29

## ◆ make_rng()

RandomNumberGenerator * Botan::RandomNumberGenerator::make_rng | ( |  | ) |
| staticinherited

Create a seeded and active RNG object for general application use

Definition at line 29 of file rng.cpp.

30 {
31 #if defined(BOTAN_HAS_AUTO_SEEDING_RNG)
32 return new AutoSeeded_RNG;
33 #endif
34
35 throw Algorithm_Not_Found("RandomNumberGenerator::make_rng - no RNG found");
36 }

## ◆ name()

std::string Botan::ANSI_X931_RNG::name | ( |  | ) | const
| virtual

Return the name of this object

Implements Botan::RandomNumberGenerator.

Definition at line 124 of file x931_rng.cpp.

References Botan::Algorithm::name().

Referenced by randomize().

125 {
126 return "X9.31(" + cipher->name() + ")";
127 }
Botan::Algorithm::name
virtual std::string name() const =0

## ◆ next_byte()

byte Botan::RandomNumberGenerator::next_byte | ( |  | ) |
| inherited

Return a random byte

Returns
  random byte

Definition at line 19 of file rng.cpp.

References Botan::RandomNumberGenerator::randomize().

20 {
21 byte out;
22 this->randomize(&out, 1);
23 return out;
24 }
Botan::RandomNumberGenerator::randomize
virtual void randomize(byte output[], size_t length)=0
Botan::byte
unsigned char byte
Definition: types.h:22

## ◆ random_vec()

SecureVector<byte> Botan::RandomNumberGenerator::random_vec | ( | size_t | bytes | ) |
| inlineinherited

Return a random vector

Parameters

  bytes | number of bytes in the result

Returns
  randomized vector of length bytes

Definition at line 40 of file rng.h.

References Botan::MemoryRegion< T >::size().

41 {
42 SecureVector<byte> output(bytes);
43 randomize(&output[0], output.size());
44 return output;
45 }
Botan::RandomNumberGenerator::randomize
virtual void randomize(byte output[], size_t length)=0

## ◆ randomize()

void Botan::ANSI_X931_RNG::randomize | ( | byte | output[],
|  | size_t | length
| ) |  |
| virtual

Randomize a byte array.

Parameters

  output | the byte array to hold the random output.
  length | the length of the byte array output.

Implements Botan::RandomNumberGenerator.

Definition at line 17 of file x931_rng.cpp.

References Botan::copy_mem(), is_seeded(), name(), and Botan::MemoryRegion< T >::size().

18 {
19 if(!is_seeded())
20 throw PRNG_Unseeded(name());
21
22 while(length)
23 {
24 if(position == R.size())
25 update_buffer();
26
27 const size_t copied = std::min<size_t>(length, R.size() - position);
28
29 copy_mem(out, &R[position], copied);
30 out += copied;
31 length -= copied;
32 position += copied;
33 }
34 }
Botan::ANSI_X931_RNG::name
std::string name() const
Definition: x931_rng.cpp:124
Botan::ANSI_X931_RNG::is_seeded
bool is_seeded() const
Definition: x931_rng.cpp:103
Botan::copy_mem
void copy_mem(T *out, const T *in, size_t n)
Definition: mem_ops.h:22
Botan::MemoryRegion::size
size_t size() const
Definition: secmem.h:29

## ◆ reseed()

void Botan::ANSI_X931_RNG::reseed | ( | size_t | bits_to_collect | ) |
| virtual

Seed this RNG using the entropy sources it contains.

Parameters

  bits_to_collect | is the number of bits of entropy to attempt to gather from the entropy sources

Implements Botan::RandomNumberGenerator.

Definition at line 77 of file x931_rng.cpp.

References Botan::RandomNumberGenerator::reseed().

78 {
79 prng->reseed(poll_bits);
80 rekey();
81 }
Botan::RandomNumberGenerator::reseed
virtual void reseed(size_t bits_to_collect)=0

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

- src/rng/x931_rng/x931_rng.h
- src/rng/x931_rng/x931_rng.cpp