XmlConfig Class Reference

Encapsulates the TinyXml library to retrieve easily information from the xml configuration file described in the verificatum verifier specification. More...

#include <xmlconfig.hpp>

+ Collaboration diagram for XmlConfig:

Public Member Functions

const char * retrieveText (std::string node, TiXmlHandle hdl)
 Returns the text at the node whose name is given as an argument. If there is no such node, stops everything by exiting with code 1.
int toInteger (std::string node, TiXmlHandle hdl)
 Gets the content of the node specified and returns its value as an integer.
cryptoTools::SHAxstring2hash (const char *hashRepresentation)
 Parses a c-string and returns a pointer to the corresponding child of SHAx.
arithm::GroupunmarshalPGroup (const char *fieldRepresentation)
 Performs the "unmarshalling" of the pgroup used for the computations.
 XmlConfig (std::string path2file)
 Class contructor.
unsigned int getNopart ()
unsigned int getThres ()
unsigned int getMaxciph ()
unsigned int getVbitlenro ()
unsigned int getStatdist ()
unsigned int getCbitlenro ()
cryptoTools::SHAxgetRohash ()
cryptoTools::SHAxgetPrghash ()
arithm::GroupgetPgroup ()

Private Attributes

TiXmlDocument doc
 A class from the tinyxml library used to store a xml document and access it.
unsigned int nopart
 The number of parties involved.
unsigned int thres
 The threshold number of mix-servers that must be corrupted to break the privacy of the senders (thres node).
unsigned int maxciph
 The maximal number of ciphertext (maxciph node).
unsigned int vbitlenro
 The number of bits in each component of random vectors used for batching in proofs of shuffles and proofs of correct decryption (vbitlenro node).
unsigned int statdist
 The acceptable statistical error when sampling random values (statdist node).
unsigned int cbitlenro
 The number of bits used in the challenge of the verifier in zero-knowledge proofs (cbitlenro node).
cryptoTools::SHAxrohash
 An implementation of the cryptoTools::SHAx class corresponding to the hash function specified in the rohash node.
cryptoTools::SHAxprghash
 An implementation of the cryptoTools::SHAx class corresponding to the hash function specified in the prg node.
arithm::Grouppgroup
 A pointer to the arithm::Field instance corresponding to the one described in the pgroup node.

Detailed Description

Encapsulates the TinyXml library to retrieve easily information from the xml configuration file described in the verificatum verifier specification.

Retrieves the following (as they are defined in the spec):

  • nopart (unsigned int)
  • thres (unsigned int)
  • maxciph (unsigned int)
  • vbitlenroh (unsigned int)
  • statdist (unsigned int)
  • cbitlenroh (unsigned int)
  • rohash (cryptoTools::SHAx)
  • prghash (cryptoTools::SHAx)
  • pgroup (ModPGrp)
See Also
cryptoTools::SHAx
PRG
RO
ModPGrp
xmltest.cpp

Definition at line 50 of file xmlconfig.hpp.

Constructor & Destructor Documentation

XmlConfig::XmlConfig ( std::string  path2file)

Class contructor.

Parameters
path2fileThe path to the file to parse.

Definition at line 96 of file xmlconfig.cpp.

{
TiXmlDocument doc(path2file.c_str());
// Checking if we can open it; otherwise we stop everything.
if(!doc.LoadFile())
{
std::cout<<"Error when loading file"<<std::endl;
std::cout<<"error #"<<doc.ErrorId()<<" : "<<doc.ErrorDesc()<<std::endl;
exit(1);
}
// Reading every first level nodes of the file and assigning
// the instance's sttribute accordingly.
TiXmlHandle hdl(&doc); // it is apparently better to use
// handles than pointers and I am a man
// of peace, so I do.
// reading simple constants
nopart = toInteger("nopart" ,hdl);
thres = toInteger("thres" ,hdl);
maxciph = toInteger("maxciph" ,hdl);
vbitlenro = toInteger("vbitlenro",hdl);
statdist = toInteger("statdist",hdl);
cbitlenro = toInteger("cbitlenro",hdl);
// reading rohash
const char * ro = retrieveText("rohash",hdl);
// reading prghash
const char * prgType = retrieveText("prg",hdl);
prghash = string2hash(prgType);
// reading pgroup
const char * fieldRepr = retrieveText("pgroup",hdl);
pgroup = unmarshalPGroup(fieldRepr);
}

Member Function Documentation

unsigned int XmlConfig::getCbitlenro ( )

Definition at line 164 of file xmlconfig.cpp.

{
return cbitlenro;
}
unsigned int XmlConfig::getMaxciph ( )

Definition at line 146 of file xmlconfig.cpp.

{
return maxciph;
}
unsigned int XmlConfig::getNopart ( )

Definition at line 134 of file xmlconfig.cpp.

{
return nopart;
}
arithm::Group * XmlConfig::getPgroup ( )

Definition at line 182 of file xmlconfig.cpp.

{
return pgroup;
}
cryptoTools::SHAx * XmlConfig::getPrghash ( )

Definition at line 176 of file xmlconfig.cpp.

{
return prghash;
}
cryptoTools::SHAx * XmlConfig::getRohash ( )

Definition at line 170 of file xmlconfig.cpp.

{
return rohash;
}
unsigned int XmlConfig::getStatdist ( )

Definition at line 158 of file xmlconfig.cpp.

{
return statdist;
}
unsigned int XmlConfig::getThres ( )

Definition at line 140 of file xmlconfig.cpp.

{
return thres;
}
unsigned int XmlConfig::getVbitlenro ( )

Definition at line 152 of file xmlconfig.cpp.

{
return vbitlenro;
}
const char * XmlConfig::retrieveText ( std::string  node,
TiXmlHandle  hdl 
)

Returns the text at the node whose name is given as an argument. If there is no such node, stops everything by exiting with code 1.

Parameters
nodeThe name of the node we are interested in.
hdlTinyXml stuff, it is a Handle to the XML documented we are using.
Returns
A C string containing the content of the text of this node.

Definition at line 19 of file xmlconfig.cpp.

{
TiXmlElement *elem;
elem = hdl.FirstChildElement("protocol").FirstChildElement(node.c_str()).Element();
if (!elem)
{
std::cout<<"error: no '"<<node<<"' node in the config file. Aborting."<<std::endl;
exit(1);
}
else
{
const char * cont = elem->GetText();
return cont;
}
}
cryptoTools::SHAx * XmlConfig::string2hash ( const char *  hashRepresentation)

Parses a c-string and returns a pointer to the corresponding child of SHAx.

Can read "SHA-256", "SHA-384" and "SHA-512". If none of these is found, exits with exit code 1.

Parameters
hashRepresentationA string describing the hashfunction to use.
Returns
A hashfunction.

Definition at line 43 of file xmlconfig.cpp.

{
if (strcmp(hashRepresentation,"SHA-256") == 0)
return new cryptoTools::SHA256();
else if (strcmp(hashRepresentation,"SHA-384") == 0)
return new cryptoTools::SHA384();
else if (strcmp(hashRepresentation,"SHA-512") == 0)
return new cryptoTools::SHA512();
else
{
std::cout<<"ERROR: in XmlCOnfig.string2hash,"
<<"Incorrect hash type: "
<<hashRepresentation<<std::endl;
exit(1);
}
}
int XmlConfig::toInteger ( std::string  node,
TiXmlHandle  hdl 
)

Gets the content of the node specified and returns its value as an integer.

Parameters
nodeThe name of the node we want to read.
hdlTinyXml stuff, it is a Handle to the XML documented we are using.
Returns
The integer contained in the node node. If it is not an integer, returns zero (uses the atoi function from the C standard library).

Definition at line 36 of file xmlconfig.cpp.

{
int number = atoi(retrieveText(node,hdl));
return number;
}
arithm::Group * XmlConfig::unmarshalPGroup ( const char *  fieldRepresentation)

Performs the "unmarshalling" of the pgroup used for the computations.

Can currently read "ModPGrp" instances. Reads a string containing:

< class name>(...)::< bytetree representation of the group>

Depending on < class name>, the correct Field child is instanciated with its constructor taking a verifierUtils::ByteTree as its input.

Parameters
fieldRepresentationA string which must contain the name of the class, then parenthesis containing human readable data we are not interested in, then two ':' and then the bytetree representation of the field.
Returns
The mathematical field encoded in the "pgroup", well, field of the protocol file.

Definition at line 61 of file xmlconfig.cpp.

{
std::string fieldRepr(fieldRepresentation);
unsigned int index=0;
std::string fieldByteTree = "";
// getting rid of the comment
while (fieldRepr[index] != ':')
index++;
index += 2; // taking care of the second ':'
// reading the ByteTree corresponding to the group
while (index < fieldRepr.size())
{
// to suppress spaces
if (fieldRepr[index]!=' ')
fieldByteTree.push_back(fieldRepr[index]);
index++;
}
// returning a field of the correct type
if (bt->getChild(0)->compare("verificatum.arithm.ModPGroup") == 0)
return new arithm::ModPGrp(bt->getChild(1));
else
{
std::cout<<"ERROR: in xmlConfig.unmarshalPGroup"
<<"pgroup type unkown: "
<<bt->getChild(0)->toString()<<"."
<<"Aborting."<<std::endl;
exit(1);
}
}

Member Data Documentation

unsigned int XmlConfig::cbitlenro
private

The number of bits used in the challenge of the verifier in zero-knowledge proofs (cbitlenro node).

Definition at line 92 of file xmlconfig.hpp.

TiXmlDocument XmlConfig::doc
private

A class from the tinyxml library used to store a xml document and access it.

Definition at line 57 of file xmlconfig.hpp.

unsigned int XmlConfig::maxciph
private

The maximal number of ciphertext (maxciph node).

Definition at line 73 of file xmlconfig.hpp.

unsigned int XmlConfig::nopart
private

The number of parties involved.

Definition at line 62 of file xmlconfig.hpp.

arithm::Group* XmlConfig::pgroup
private

A pointer to the arithm::Field instance corresponding to the one described in the pgroup node.

Definition at line 112 of file xmlconfig.hpp.

cryptoTools::SHAx* XmlConfig::prghash
private

An implementation of the cryptoTools::SHAx class corresponding to the hash function specified in the prg node.

Definition at line 106 of file xmlconfig.hpp.

cryptoTools::SHAx* XmlConfig::rohash
private

An implementation of the cryptoTools::SHAx class corresponding to the hash function specified in the rohash node.

Definition at line 99 of file xmlconfig.hpp.

unsigned int XmlConfig::statdist
private

The acceptable statistical error when sampling random values (statdist node).

Definition at line 86 of file xmlconfig.hpp.

unsigned int XmlConfig::thres
private

The threshold number of mix-servers that must be corrupted to break the privacy of the senders (thres node).

Definition at line 68 of file xmlconfig.hpp.

unsigned int XmlConfig::vbitlenro
private

The number of bits in each component of random vectors used for batching in proofs of shuffles and proofs of correct decryption (vbitlenro node).

Definition at line 80 of file xmlconfig.hpp.


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