cryptoTools::PRG Class Reference

Implements a pseudo-random byte generator as explained in the verificatum verifier specification. More...

#include <prg.hpp>

+ Collaboration diagram for cryptoTools::PRG:

Public Member Functions

 PRG (SHAx *hash)
 Creates a new PRG instance, using the given hash as a hash function. The seedLen is set depending on the hash given.
void updateDigest ()
 Updates the digest, i.e. assigns to the value of H(seed||counter) and then increments counter.
void initialize (std::vector< uint8_t > newSeed)
 Initializes the PRG with the seed given as the input.
uint8_t getNextRandByte ()
 Computes the next random byte, i.e. H(seed||counter).

Private Attributes

SHAxhashfunction
 The SHA function to use to generate the pseudo random bytes.
std::vector< uint8_t > seed
 The seed to use.
std::vector< uint8_t > digest
 The digest from which we are extracting pseudo random bytes.
unsigned int index
 The index of the byte of the digest we output last.
unsigned int seedLen
 The length of the seed necessary for this PRG to be correctly initialised.
uint32_t counter
 A 32 bits long unsigned counter used during the computation of the output.

Detailed Description

Implements a pseudo-random byte generator as explained in the verificatum verifier specification.

See Also
prgtest.cpp

Definition at line 26 of file prg.hpp.

Constructor & Destructor Documentation

PRG::PRG ( SHAx hash)

Creates a new PRG instance, using the given hash as a hash function. The seedLen is set depending on the hash given.

Definition at line 22 of file prg.cpp.

{
hashfunction = hash;
}

Member Function Documentation

uint8_t PRG::getNextRandByte ( )

Computes the next random byte, i.e. H(seed||counter).

Returns
The next random byte.

Definition at line 58 of file prg.cpp.

{
uint8_t out = digest[index];
index++;
{
index = 0;
}
return out;
}
void PRG::initialize ( std::vector< uint8_t >  newSeed)

Initializes the PRG with the seed given as the input.

If the length of the seed is wrong, exits with exit code

  1. It also sets counter to 0.

Definition at line 42 of file prg.cpp.

{
if (newSeed.size()*8 != seedLen)
{
std::cout<<"ERROR: wrong seed length for the PRG ("
<<newSeed.size()*8<<" instead of "<<seedLen
<<")"<<std::endl;
exit(1);
}
seed = newSeed;
counter = 0;
index = 0;
}
void PRG::updateDigest ( )

Updates the digest, i.e. assigns to the value of H(seed||counter) and then increments counter.

Definition at line 29 of file prg.cpp.

{
std::vector<uint8_t> toHash (seed);
toHash.push_back( (counter>>24) % 0x100);
toHash.push_back( (counter>>16) % 0x100);
toHash.push_back( (counter>> 8) % 0x100);
toHash.push_back( counter % 0x100);
hashfunction->hash(toHash);
}

Member Data Documentation

uint32_t cryptoTools::PRG::counter
private

A 32 bits long unsigned counter used during the computation of the output.

Definition at line 61 of file prg.hpp.

std::vector<uint8_t> cryptoTools::PRG::digest
private

The digest from which we are extracting pseudo random bytes.

Definition at line 44 of file prg.hpp.

SHAx* cryptoTools::PRG::hashfunction
private

The SHA function to use to generate the pseudo random bytes.

Definition at line 33 of file prg.hpp.

unsigned int cryptoTools::PRG::index
private

The index of the byte of the digest we output last.

Definition at line 49 of file prg.hpp.

std::vector<uint8_t> cryptoTools::PRG::seed
private

The seed to use.

Definition at line 38 of file prg.hpp.

unsigned int cryptoTools::PRG::seedLen
private

The length of the seed necessary for this PRG to be correctly initialised.

Definition at line 55 of file prg.hpp.


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