#include <crypto/kem.h>

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

NTL_CLIENT

int main()
{
	ostring txt , K;
	int l;

#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);

	ECIESKEM<modp_group> ecies(kdf, grp, 128, 0, 0, 1, 0);

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

	ECIESKEM<ecmodp_group> ecies(kdf, grp, 128, 0, 0, 0, 0);

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

	ECIESKEM<ecgf2_group> ecies(kdf, grp, 128, 0, 0, 0, 0);

#endif

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

	// for writing pseckem keys to file
	//ofstream fileo("psec.txt");
	//if (!fileo) cout << " cannot open psec output file ";
	//psec.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));

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

	K = ecies.encrypt(txt);

	if(K != ecies.decrypt(txt, l))
		cout << " ECIESkem failed " << endl;
	else
		cout << " ECIESkem success " << endl;
}

