#include <crypto/kem.h>

#define STR_AUX(a) #a
#define STR(a) STR_AUX(a)

NTL_CLIENT

int main()
{
	ostring txt, K;

#if !defined(Kdf)
#error "Error - Kdf not defined."
#endif

#if !defined(Hash)
#error "Error - Hash not defined."
#endif

#if (Hash == 1)
	SHA1 hash(20);
	Kdf kdf(hash);
#elif (Hash == 2)
	SHA256 hash(20);
	Kdf kdf(hash);
#elif (Hash == 3)
	MD5 hash(16);
        Kdf kdf(hash);
#else
#error "Error - Hash value not defined."
#endif

#if (GRP != 1 && GRP != 2 && GRP != 3) || !defined(GRP)
#error "Error - GRP not defined."
#endif

	// for reading group keys from file
#if (GRP == 1)
	ifstream ifile("grp.txt");
	modp_group grp(ifile);

	ACEKEM<modp_group> ace(0, kdf, hash, 128, grp);	

#elif (GRP == 2)
	ifstream ifile("192.txt");
	ecmodp_group grp(ifile);

	ACEKEM<ecmodp_group> ace(0, kdf, hash, 128, grp);

#else
	ifstream ifile("163.txt");
	ecgf2_group grp(ifile);

	ACEKEM<ecgf2_group> ace(0, kdf, hash, 128, grp);

#endif

	if (!ifile) cout << " cannot open input file ";

	// for writing acekem keys to file
	//ofstream fileo("ace.txt");
	//if (!fileo) cout << " cannot open ace output file ";
	//ace.writetofile(fileo);

	txt = "hello world! this is a test!";

#if defined(COMPRESS)
	grp.encoding_fmt = compressed_fmt;
#endif

	ofstream io(STR(DESC));
	ofstream trace(STR(TRACE));

	ace.PrettyPrint(io);
	ace.logfile = &trace;

	K = ace.encrypt(txt);
	int nbytes;

	if(K != ace.decrypt(txt, nbytes) || nbytes != txt.size())
		cout << " ACEkem failed " << endl;
	else
		cout << " ACEkem success " << endl;
}

