Arduino Cryptography Library
Public Member Functions | List of all members
TransistorNoiseSource Class Reference

Processes the signal from a transistor-based noise source. More...

#include <TransistorNoiseSource.h>

Inheritance diagram for TransistorNoiseSource:
NoiseSource

Public Member Functions

 TransistorNoiseSource (uint8_t pin)
 Constructs a new transitor-based noise source handler. More...
 
bool calibrating () const
 Determine if the noise source is still calibrating itself. More...
 
void stir ()
 Stirs entropy from this noise source into the global random number pool. More...
 
- Public Member Functions inherited from NoiseSource
 NoiseSource ()
 Constructs a new random noise source.
 
virtual ~NoiseSource ()
 Destroys this random noise source.
 
virtual void added ()
 Called when the noise source is added to RNG with RNG.addNoiseSource(). More...
 

Additional Inherited Members

- Protected Member Functions inherited from NoiseSource
virtual void output (const uint8_t *data, size_t len, unsigned int credit)
 Called from subclasses to output noise to the global random number pool. More...
 

Detailed Description

Processes the signal from a transistor-based noise source.

This class processes input from a transistor-based noise source, such as that described by Rob Seward. See that Web page for full details on how such noise sources work, how the output should be used, and caveats for the unwary. For convenience, Rob's circuit is reproduced below:

The following example shows how to initialize a transistor-based noise source and use it with RNG. The noise is read from the A1 pin on the Arduino and stirred into the random number pool on a regular basis. For more information, see the documentation for RNG.

#include <Crypto.h>
#include <RNG.h>
#include <TransistorNoiseSource.h>
// Noise source to seed the random number generator.
void setup() {
// Initialize the random number generator with the application tag
// "MyApp 1.0" and load the previous seed from EEPROM address 500.
RNG.begin("MyApp 1.0", 500);
// Add the noise source to the list of sources known to RNG.
RNG.addNoiseSource(noise);
// ...
}
void loop() {
// ...
// Perform regular housekeeping on the random number generator.
RNG.loop();
// ...
}
void begin(const char *tag)
Initializes the random number generator.
Definition: RNG.cpp:438
void loop()
Run periodic housekeeping tasks on the random number generator.
Definition: RNG.cpp:898
void addNoiseSource(NoiseSource &source)
Adds a noise source to the random number generator.
Definition: RNG.cpp:611
Processes the signal from a transistor-based noise source.
See also
RNG, NoiseSource, RingOscillatorNoiseSource

Definition at line 29 of file TransistorNoiseSource.h.

Constructor & Destructor Documentation

◆ TransistorNoiseSource()

TransistorNoiseSource::TransistorNoiseSource ( uint8_t  pin)
explicit

Constructs a new transitor-based noise source handler.

Parameters
pinThe analog input pin that the noise will appear on.

Definition at line 138 of file TransistorNoiseSource.cpp.

Member Function Documentation

◆ calibrating()

bool TransistorNoiseSource::calibrating ( ) const
virtual

Determine if the noise source is still calibrating itself.

Returns
Returns true if calibration is in progress; false if the noise source is generating valid random data.

Noise sources that require calibration start doing so at system startup and then switch over to random data generation once calibration is complete. Since no random data is being generated during calibration, the output from RNG.rand() may be predictable. Use RNG.available() to determine when sufficient entropy is available to generate good random values.

It is possible that the noise source never exits calibration. This can happen if the input voltage is insufficient to trigger noise or if the noise source is not connected. Noise sources may also periodically recalibrate themselves.

See also
stir()

Implements NoiseSource.

Definition at line 156 of file TransistorNoiseSource.cpp.

◆ stir()

void TransistorNoiseSource::stir ( )
virtual

Stirs entropy from this noise source into the global random number pool.

This function should call output() to add the entropy from this noise source to the global random number pool.

The noise source should batch up the entropy data, providing between 16 and 48 bytes of data each time. If the noise source does not have sufficient entropy data at the moment, it should return without stiring the current data in.

See also
calibrating(), output()

Implements NoiseSource.

Definition at line 161 of file TransistorNoiseSource.cpp.


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