arithmtest.cpp File Reference

A test suite for the whole arithm module which is intended to be used in coordination with a python script. More...

#include <cstdlib>
#include <cstring>
#include <iostream>
#include <fstream>
#include "arithm.hpp"

Go to the source code of this file.

Macros

#define PATH_TO_INPUT_FILE   "./input.txt"
#define PATH_TO_OUTPUT_FILE   "./actual_output.txt"
#define STATISTICAL_ERROR   100
#define N_RAND_ARRAYS   3

Functions

void test_ModPGrp_toByteTree (std::ifstream &input, std::ofstream &output)
 Tests the byteTree related functions of the ModPGrp.
void test_ModPGrp_exponentiation (std::ifstream &input, std::ofstream &output)
 Tests the modular exponentiation as implemented in ModPGrp (i.e. in ModField).
void test_ModPGrp_multiplication (std::ifstream &input, std::ofstream &output)
 Tests the multiplication as implemented in ModPGrp (i.e. in ModField).
void test_ModPGrp_getRandArray (std::ifstream &input, std::ofstream &output)
 Tests the derivation of random elements as implemented in ModPGrp.
void test_ModPGrp_product (std::ifstream &input, std::ofstream &output)
 Tests the product of within an array of Elmts as implemented in ModPGrp (i.e. in ModField).
void test_ModPGrp_expProduct (std::ifstream &input, std::ofstream &output)
 Tests the product of ModPGrpElmts as implemented in ArrayOfModPGrpElmts.
void printHelp ()
 Prints the help of this program, including a list of the functions that can be tested.
int main (int argc, char **argv)

Detailed Description

A test suite for the whole arithm module which is intended to be used in coordination with a python script.

Author
Léo Perrin leope.nosp@m.rrin.nosp@m.@pica.nosp@m.rres.nosp@m.ursix.nosp@m..fr
Date
Time-stamp: <2012-08-26 13:53:55 leo>

It is meant to be used in coordination with the unitarytest.py python script to compare its behaviour with that of the reference implementation. The functions in this file are sort of interfaces between the actual classes tested and the unitary tests provided by the python script and based on the reference implementation (which is in python). This script produces a test vector, "./input.txt", and a file containing what this program should output, "./ideal_out.txt".

For each non-virtual function in this module, there is a unitary test reading its data line by line. It reads one line of the "./input.txt" file, processes it, writes one line in "./actual_out.txt" and continues until the end of the input file is found.

In the end, the differences between "ideal_out.txt" and "actual_out.txt" are computed. If there is even one error, then you have a problem.

Definition in file arithmtest.cpp.

Macro Definition Documentation

#define N_RAND_ARRAYS   3

Definition at line 42 of file arithmtest.cpp.

#define PATH_TO_INPUT_FILE   "./input.txt"

Definition at line 39 of file arithmtest.cpp.

#define PATH_TO_OUTPUT_FILE   "./actual_output.txt"

Definition at line 40 of file arithmtest.cpp.

#define STATISTICAL_ERROR   100

Definition at line 41 of file arithmtest.cpp.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 255 of file arithmtest.cpp.

{
if (argc<2)
else
{
std::ifstream input(PATH_TO_INPUT_FILE,
std::ifstream::in);
std::ofstream output(PATH_TO_OUTPUT_FILE);
if (strcmp(argv[1],"ModPGrp.toByteTree") == 0)
test_ModPGrp_toByteTree(input,output);
else if (strcmp(argv[1], "ModPGrp.exponentiation") == 0)
else if (strcmp(argv[1], "ModPGrp.multiplication") == 0)
else if (strcmp(argv[1], "ModPGrp.getRandArray") == 0)
else if (strcmp(argv[1], "ModPGrp.product") == 0)
test_ModPGrp_product(input,output);
else if (strcmp(argv[1], "ModPGrp.expProduct") == 0)
test_ModPGrp_expProduct(input,output);
else
output.close();
}
return 0;
}
void printHelp ( )

Prints the help of this program, including a list of the functions that can be tested.

Definition at line 238 of file arithmtest.cpp.

{
std::cout<<"Run ./arithm_test <function to test> and it will parse"
<< "the"<<PATH_TO_INPUT_FILE<< "file to produce the "
<<PATH_TO_OUTPUT_FILE<<" file. If this is giberish to you,"
<<"you\nshould read the documentation ^^"<<"\n\n"
<<"Available functions are:"<<"\n"
<<" - ModPGrp.toByteTree\n"
<<" - ModPGrp.exponentiation\n"
<<" - ModPGrp.multiplication\n"
<<" - ModPGrp.getRandArray\n"
<<" - ModPGrp.product\n"
<<" - ModPGrp.expProduct\n"
<<"\n"<<std::endl;
}
void test_ModPGrp_exponentiation ( std::ifstream &  input,
std::ofstream &  output 
)

Tests the modular exponentiation as implemented in ModPGrp (i.e. in ModField).

Parameters
inputThe input file at PATH_TO_INPUT_FILE (read).
outputThe output file at PATH_TO_OUTPUT_FILE (write).

Definition at line 78 of file arithmtest.cpp.

{
mpz_class exp;
std::string line;
while (input>>line)
{
ModPGrp modpgrp(bt);
Elmt elm = modpgrp.getElmt(bt);
Elmt exp(bt->toInteger(), NULL);
elm = modpgrp.exponentiation(elm,exp);
bt = new verifierUtils::Leaf(elm.getValue());
output<<bt->toString()<<std::endl;
}
free(bt);
}
void test_ModPGrp_expProduct ( std::ifstream &  input,
std::ofstream &  output 
)

Tests the product of ModPGrpElmts as implemented in ArrayOfModPGrpElmts.

Parameters
inputThe input file at PATH_TO_INPUT_FILE (read).
outputThe output file at PATH_TO_OUTPUT_FILE (write).

Definition at line 211 of file arithmtest.cpp.

{
std::string line;
while (input>>line)
{
ModPGrp modpgrp(bt);
ModField modfield(bt->getChild(0)->toInteger());
ArrayOfElmts ar = modpgrp.getArray(bt);
ArrayOfElmts ex = modfield.getArray(bt);
Elmt res = modfield.expProduct(ar,ex);
output<<res.toByteTree()->toString()<<std::endl;
}
}
void test_ModPGrp_getRandArray ( std::ifstream &  input,
std::ofstream &  output 
)

Tests the derivation of random elements as implemented in ModPGrp.

Parameters
inputThe input file at PATH_TO_INPUT_FILE (read).
outputThe output file at PATH_TO_OUTPUT_FILE (write).

Definition at line 142 of file arithmtest.cpp.

{
std::vector<uint8_t> seed(32,0);
std::string line;
while (input>>line)
{
// reading group
ModPGrp modpgrp(bt);
// reading seed
for (unsigned int i=0; i<seed.size(); i++)
{
unsigned int read;
input>>read;
seed[i] = read;
}
prg->initialize(seed);
// generating an array in the ModPGrp using the seed
for (unsigned int i=0; i<N_RAND_ARRAYS; i++)
{
unsigned int size;
input>>size;
ArrayOfElmts arr = modpgrp.getRandArray(prg,STATISTICAL_ERROR,size);
for (unsigned int j=0; j<arr.size(); j++)
output<<arr.getElmt(j).toByteTree()->toString()<<std::endl;
}
}
free(bt);
}
void test_ModPGrp_multiplication ( std::ifstream &  input,
std::ofstream &  output 
)

Tests the multiplication as implemented in ModPGrp (i.e. in ModField).

Parameters
inputThe input file at PATH_TO_INPUT_FILE (read).
outputThe output file at PATH_TO_OUTPUT_FILE (write).

Definition at line 111 of file arithmtest.cpp.

{
std::string line;
while (input>>line)
{
ModPGrp modpgrp(bt);
Elmt elm1 = modpgrp.getElmt(bt);
Elmt elm2 = modpgrp.getElmt(bt);
Elmt res = modpgrp.multiplication(elm1,elm2);
bt = new verifierUtils::Leaf(res.getValue());
output<<bt->toString()<<std::endl;
}
free(bt);
}
void test_ModPGrp_product ( std::ifstream &  input,
std::ofstream &  output 
)

Tests the product of within an array of Elmts as implemented in ModPGrp (i.e. in ModField).

Parameters
inputThe input file at PATH_TO_INPUT_FILE (read).
outputThe output file at PATH_TO_OUTPUT_FILE (write).

Definition at line 185 of file arithmtest.cpp.

{
std::string line;
while (input>>line)
{
ModPGrp modpgrp(bt);
ArrayOfElmts ar = modpgrp.getArray(bt);
bt = modpgrp.product(ar).toByteTree();
output<<bt->toString()<<std::endl;
}
}
void test_ModPGrp_toByteTree ( std::ifstream &  input,
std::ofstream &  output 
)

Tests the byteTree related functions of the ModPGrp.

Reads a bytetree from the input file, parses into a ModPGrp and then turns it again into a bytetree. This last bytetree is printed on the output file. This procedure is carried on each line of the input file, until the end of file is reached.

Parameters
inputThe input file at PATH_TO_INPUT_FILE (read).
outputThe output file at PATH_TO_OUTPUT_FILE (write).

Definition at line 56 of file arithmtest.cpp.

{
std::string line;
while (input>>line)
{
ModPGrp modpgrp(bt);
output<<modpgrp.toByteTree()->toString()<<std::endl;
}
free(bt);
}