Exemple #1
0
void BaseOT::ByteArrayToPoint(EC2 *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 = EC2(bigtmp, itmp);
}
Exemple #2
0
void SamplePointFromBytes(EC2 *point, BYTE* input, int inbytelen) {
	Big bigtmp;
	bytes_to_big (inbytelen, (const char*) input, bigtmp.getbig());//(bigtmp, inbytelen, input);
	premult(bigtmp.getbig(), MAXMSGSAMPLE, bigtmp.getbig());
	for(int i = 0; i < MAXMSGSAMPLE; i++)
	{
		*point = EC2(bigtmp, 0);
		if(!point_at_infinity(point->get_point()))
			return;
		*point = EC2(bigtmp, 1);
		if(!point_at_infinity(point->get_point()))
			return;
		incr(bigtmp.getbig(), 1, bigtmp.getbig());
	}
	cerr << "Error while sampling point, exiting!" << endl;
	exit(0);
}
Exemple #3
0
void BaseOT::SampleRandomPoint(EC2 *point, int field_size) {

	Big bigtmp;
	int itmp = rand()%2;
	do
	{
		bigtmp = rand(field_size, 2);
		*point = EC2(bigtmp, itmp);
	}	
	while (point_at_infinity(point->get_point()));
}
Exemple #4
0
void SampleRandomPoint(EC2 &point, fparams* params) {

	Big bigtmp;
	int itmp = rand()%2;
	do
	{
		bigtmp = rand(params->secparam, 2);
		point = EC2(bigtmp, itmp);
	}
	while (point_at_infinity(point.get_point()));
}
Exemple #5
0
void BaseOT::Miracl_InitPoint(EC2* point, Big x, Big y)
{
	*point = EC2(x, y);
}
Exemple #6
0
void MiraclInitPoint(EC2& point, Big x, Big y)
{
	point = EC2(x, y);
}
Exemple #7
0
int main()
{
    ifstream common("common2.ecs");    /* construct file I/O streams */
    ifstream private_key("private.ecs");
    ifstream message;
    ofstream signature;
    char ifname[13],ofname[13];
    EC2 G;
    Big a2,a6,q,x,y,h,r,s,d,k;
    long seed;
    int m,a,b,c,cf; 
    miracl *mip=&precision;

/* randomise */
    cout << "Enter 9 digit random number seed  = ";
    cin >> seed;
    irand(seed);

/* get common data */

    common >> m;
    mip->IOBASE=16;
    common >> a2 >> a6 >> q >> x >> y;
    mip->IOBASE=10;
    common >> a >> b >> c;

/* calculate r - this can be done off-line,
   and hence amortized to almost nothing    */
    ecurve2(m,a,b,c,a2,a6,FALSE,MR_PROJECTIVE);
    G=EC2(x,y);
    k=rand(q);
    G*=k;            /* see brick.cpp for technique to speed this up */
    G.get(r);
    r%=q;

/* get private key of recipient */
    private_key >> d;

/* get message */
    cout << "file to be signed = " ;
    cin >> ifname;
    strcpy(ofname,ifname);
    strip(ofname);
    strcat(ofname,".ecs");
    message.open(ifname,ios::binary|ios::in|ios::nocreate); 
    if (!message)
    {
        cout << "Unable to open file " << ifname << "\n";
        return 0;
    }
    h=hash(message);

/* calculate s */
    k=inverse(k,q);
    s=((h+d*r)*k)%q;
    signature.open(ofname);
    mip->IOBASE=10;
    signature << r << endl;
    signature << s << endl;
    return 0;
}