cryptoTools::RO Class Reference

Implements a random oracle as explained in the verificatum verifier specification. More...

#include <ro.hpp>

+ Collaboration diagram for cryptoTools::RO:

Public Member Functions

 RO (SHAx *hash, uint32_t outlen)
 Creates a new RO instance.
std::vector< uint8_t > query (std::vector< uint8_t > d)
 Implements a query to this random oracle.

Private Attributes

SHAxhashfunction
 The hashfunction used by both the PRG and this RO instance.
PRGprg
 The PRG to use to generate the pseudo random bytes.
uint32_t nout
 A 32 bits long unsigned representation of the length of the output required.
std::vector< uint8_t > vectNout
 A representation of nout as a vector of 4 uint8_t.

Detailed Description

Implements a random oracle as explained in the verificatum verifier specification.

See Also
rotests.cpp

Definition at line 31 of file ro.hpp.

Constructor & Destructor Documentation

RO::RO ( SHAx hash,
uint32_t  outlen 
)

Creates a new RO instance.

Parameters
hashThe hashfunction used by the PRG.
outlenThe length of the output, it is used to set the nout attribute.

Definition at line 20 of file ro.cpp.

{
hashfunction = hash;
prg = new PRG(hash);
nout = outlen;
vectNout.push_back( (outlen>>24) % 0x100);
vectNout.push_back( (outlen>>16) % 0x100);
vectNout.push_back( (outlen>> 8) % 0x100);
vectNout.push_back( outlen % 0x100);
}

Member Function Documentation

std::vector< uint8_t > RO::query ( std::vector< uint8_t >  d)

Implements a query to this random oracle.

Parameters
dThe input bytes.
Returns
The result of the query, a vector of bits of length nout.

Definition at line 32 of file ro.cpp.

{
// computing the length of the output and the number of bits
// to set to zero.
unsigned int len = (nout%8 == 0) ? nout/8 : (nout/8) +1,
padding = (nout%8 == 0) ? 0 :
(nout%8 > 0) ? 8-(nout%8) : 8+(nout%8);
// computing the seed
std::vector<uint8_t> in(vectNout);
in.insert(in.end(), d.begin(), d.end());
std::vector<uint8_t> digest(hashfunction->getHash());
// calling the PRG
prg->initialize(digest);
std::vector<uint8_t> out;
for (unsigned int i=0; i<len; i++)
out.push_back(prg->getNextRandByte());
// setting the padding first bits to zero.
for (unsigned int i=8; i>=8-padding; i--)
out[0] &= ~(1<<i);
return out;
}

Member Data Documentation

SHAx* cryptoTools::RO::hashfunction
private

The hashfunction used by both the PRG and this RO instance.

Definition at line 38 of file ro.hpp.

uint32_t cryptoTools::RO::nout
private

A 32 bits long unsigned representation of the length of the output required.

Definition at line 50 of file ro.hpp.

PRG* cryptoTools::RO::prg
private

The PRG to use to generate the pseudo random bytes.

Definition at line 43 of file ro.hpp.

std::vector<uint8_t> cryptoTools::RO::vectNout
private

A representation of nout as a vector of 4 uint8_t.

The aim of this attribute is to avoid computing this representation each time the RO is queried. Rather than performances, the quest for code simplicity lead to its existence.

Definition at line 60 of file ro.hpp.


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