prgtest.cpp File Reference

Performs a brief test of the pseudo-random generator, i.e. the cryptoTools::PRG class. More...

#include <iostream>
#include <iomanip>
#include "cryptotools.hpp"

Go to the source code of this file.

Functions

int main (void)

Detailed Description

Performs a brief test of the pseudo-random generator, i.e. the cryptoTools::PRG class.

Author
Léo Perrin
Date
Time-stamp: <2012-08-26 00:07:41 leo>

This file contains its own data so the test is not really impressive and should not considered to be sufficient. You have to check that its output is identical to the content of the corresponding expected_output.txt file.

Definition in file prgtest.cpp.

Function Documentation

int main ( void  )

Definition at line 24 of file prgtest.cpp.

{
SHAx * hash;
PRG * p;
std::vector<uint8_t> seed;
// Testing with SHA-256
std::cout<<"SHA-256";
hash = new SHA256();
p = new PRG(hash);
seed.clear();
for (uint8_t byte=0; byte<32; byte++)
seed.push_back(byte);
p->initialize(seed);
for (unsigned int i=0; i<128; i++)
{
if ((i%32)==0)
std::cout<<std::endl;
std::cout<<std::hex<<std::setfill('0')
<<std::setw(2)<<(int)p->getNextRandByte();
}
std::cout<<std::endl;
// Testing with SHA-384
std::cout<<std::endl<<"SHA-384";
hash = new SHA384();
p = new PRG(hash);
seed.clear();
for (uint8_t byte=0; byte<48; byte++)
seed.push_back(byte);
p->initialize(seed);
for (unsigned int i=0; i<128; i++)
{
if ((i%32)==0)
std::cout<<std::endl;
std::cout<<std::hex<<std::setfill('0')
<<std::setw(2)<<(int)p->getNextRandByte();
}
std::cout<<std::endl;
// Testing with SHA-512
std::cout<<std::endl<<"SHA-512";
hash = new SHA512();
p = new PRG(hash);
seed.clear();
for (uint8_t byte=0; byte<64; byte++)
seed.push_back(byte);
p->initialize(seed);
for (unsigned int i=0; i<128; i++)
{
if ((i%32)==0)
std::cout<<std::endl;
std::cout<<std::hex<<std::setfill('0')
<<std::setw(2)<<(int)p->getNextRandByte();
}
std::cout<<std::endl;
return 0;
}