Exemple #1
0
PFC::PFC(int s)
{
	int t,u,v,b,words,mod_bits;

	if (s!=80 && s!=128)
	{
		cout << "No suitable curve available" << endl;
		exit(0);
	}

	if (s==80)  mod_bits=379;
	if (s==128) mod_bits=1223;

	words=(mod_bits/MIRACL)+1;

#ifdef MR_SIMPLE_BASE
	miracl *mip=mirsys((MIRACL/4)*words,16);
#else
	miracl *mip=mirsys(words,0); 
	mip->IOBASE=16;
#endif

	ord=new Big;

	S=s;
	M=mod_bits;
	if (s==80)
	{
		t=253; u=251; v=59; B=1; CF=1; 
		*ord=pow((Big)2,M)+pow((Big)2,(M+1)/2)+1; //TYPE=1
	}
	if (s==128)
	{
		t=255; u=0; v=0; B=0; CF=5;
		*ord=pow((Big)2,M)+pow((Big)2,(M+1)/2)+1; //TYPE=1
	}
	*ord/=CF;
	
#ifdef MR_AFFINE_ONLY
	ecurve2(-M,t,u,v,(Big)1,(Big)B,TRUE,MR_AFFINE);
#else
	ecurve2(-M,t,u,v,(Big)1,(Big)B,TRUE,MR_PROJECTIVE);
#endif
}
Exemple #2
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;
}