Exemple #1
0
int main()
{
    ifstream common("common.ecs");    /* construct file I/O streams */
    ifstream public_key("public.ecs");
    ifstream message;
    ifstream signature;
    ECn G,Pub;
    int bits,ep;
    Big a,b,p,q,x,y,v,u1,u2,r,s,h;
    char ifname[13],ofname[13];
    miracl *mip=&precision;

/* get public data */
    common >> bits;
    mip->IOBASE=16;
    common >> p >> a >> b >> q >> x >> y;
    mip->IOBASE=10;
    ecurve(a,b,p,MR_PROJECTIVE);
    G=ECn(x,y);
/* get public key of signer */
    public_key >> ep >> x;
    Pub=ECn(x,ep);         // decompress
/* get message */
    cout << "signed file = " ;
    cin.sync();
    cin.getline(ifname,13);
    strcpy(ofname,ifname);
    strip(ofname);
    strcat(ofname,".ecs");
    message.open(ifname,ios::binary|ios::in|ios::nocreate); 
    if (!message)
    { /* no message */
        cout << "Unable to open file " << ifname << "\n";
        return 0;
    }
    h=hash(message);

    signature.open(ofname,ios::in|ios::nocreate);
    if (!signature)
    { /* no signature */
        cout << "signature file " << ofname << " does not exist\n";
        return 0;
    }
    signature >> r >> s;
    if (r>=q || s>=q)
    {
        cout << "Signature is NOT verified\n";
        return 0;
    }
    s=inverse(s,q);
    u1=(h*s)%q;
    u2=(r*s)%q;

    G=mul(u2,Pub,u1,G);
    G.get(v);
    v%=q;
    if (v==r) cout << "Signature is verified\n";
    else      cout << "Signature is NOT verified\n";
    return 0;
}
Exemple #2
0
void BaseOT::ByteArrayToPoint(ECn *point, int field_size, BYTE* pBufIdx) {
	int itmp;
	Big bigtmp;
	itmp = (int) (pBufIdx[0]);

	bytes_to_big(field_size, (const char*) pBufIdx + 1, bigtmp.getbig());
	*point = ECn(bigtmp, itmp);
}
Exemple #3
0
void BaseOT::SampleRandomPoint(ECn *point, int field_size) {
	Big bigtmp;
	int itmp = rand()%2;
	do
	{
		bigtmp = rand(field_size, 2);
		*point = ECn(bigtmp, itmp);
	}	
	while (point_at_infinity(point->get_point()));
}
Exemple #4
0
void SampleRandomPoint(ECn &point, fparams* params) {
	Big bigtmp;
	int itmp = rand()%2;
	do
	{
		bigtmp = rand(params->secparam, 2);
		point = ECn(bigtmp, itmp);
	}
	while (point_at_infinity(point.get_point()));
}
Exemple #5
0
int main(int argc, char *argv[])
{
    	int iy,i;
	char *line = new char[512];//buffer needs char instead of const char
    	ofstream fout;
    	ifstream fin;
    	time_t seed;
    	Big tempB,a,b,p,q,x,y,s1,s2;
    	ECn g;
    	miracl *mip=&precision;

    	time(&seed);
    	irand((long)seed);   /* change parameter for different values */
	

	//cout << "Adding EC-ElGamal ciphertexts...." << endl;
    	a=-3;
    	mip->IOBASE=16;
    	b=ecb;
    	p=ecp;
        q=ecq;// order
    	ecurve(a,b,p,MR_BEST);  // means use PROJECTIVE if possible, else AFFINE coordinates
    	x=ecx;
    	y=ecy;
    	g=ECn(x,y);
	
	//Read cipher and multiply
	i = 0;
	mip->IOBASE=64;
    fin.open(PFILE);
    s1 = 0;
    s2 = 0;
	while(fin.getline(line,512)){
        x = line;
        fin.getline(line,512);
        y = line;
        //"add" (could not fine add mod)
        s1 += x;
        s2 += y;
		i++;
	}
    fin.close();
    // a stupid way to mod q
    x = 1;
    s2 = modmult(s2,x,q);
	fout.open(TFILE);
	fout<<s1<<endl<<s2<<endl;
    fout.close();

	//free buffer
	delete [] line;
	return 0;
}
Exemple #6
0
int main(int argc, char *argv[])
{
    	int m,iy,i,j, n = 2, l = 2;
	char *line = new char[512];//buffer needs char instead of const char
    	ofstream fout;
    	ifstream fin;
    	time_t seed;
    	Big tempB,a,b,p,x,y;
    	ECn g,s1,s2;
    	miracl *mip=&precision;

    	time(&seed);
    	irand((long)seed);   /* change parameter for different values */
	if(argc ==3){
                n=atoi(argv[1]);
		l=atoi(argv[2]);
        }
	//we need to read all the ciphertexts in
	ECn *c1 = new ECn[n];
	ECn *c2 = new ECn[n];
	cout << "Producing EC-ElGamal Ballots...." << endl;
    	a=-3;
    	mip->IOBASE=16;
    	b=ecb;
    	p=ecp;
    	ecurve(a,b,p,MR_BEST);  // means use PROJECTIVE if possible, else AFFINE coordinates
    	x=ecx;
    	y=ecy;
    	g=ECn(x,y);
	
	//Read cipher and ballot transpose
	mip->IOBASE=64;
        fin.open(CFILE);
        for(i = 0;i<n;i++){
                fin.getline(line,512);
                x = line;
                fin.getline(line,512);
                iy = atoi(line);
                c1[i] = ECn(x,iy); //decompress
                fin.getline(line,512);
                x = line;
                fin.getline(line,512);
                iy = atoi(line);
                c2[i] = ECn(x,iy); //decompress
        }
	fin.close();

	fin.open(BFILE);
	fout.open(EBFILE);
    for(j=0;j<l;j++){
	for(i = 0;i<n;i++){
		fin>>m;
		if(i == 0){
			s1 = m*c1[i];
			s2 = m*c2[i];
		}
		else{
			s1 += m*c1[i];
                        s2 += m*c2[i];
		}
	}
	//write
	iy = s1.get(x);
        fout<<x<<endl<<iy<<endl;
        iy = s2.get(x);
        fout<<x<<endl<<iy<<endl;
    }
        fin.close();
	fout.close();



	//free buffer
	delete [] line;
	delete [] c1;
	delete [] c2;
	return 0;
}
Exemple #7
0
void BaseOT::Miracl_InitPoint(ECn* point, Big x, Big y)
{
	*point = ECn(x, y);
}
Exemple #8
0
void MiraclInitPoint(ECn& point, Big x, Big y)
{
	point = ECn(x, y);
}