Example #1
0
ECn2 mul(Big& a,ECn2& P,Big& b,ECn2& Q)
{
    ECn2 R;
    ecn2_mul2_jsf(a.getbig(),&(P.fn),b.getbig(),&(Q.fn),&(R.fn));
	R.norm();
    return R;
}
BOOL irreducible(int m,int a,int b,int c)
{
    GF2m w4,w5,modulo;
    Big modulus;
    
    get_mip()->M=m;
    get_mip()->AA=a;
    get_mip()->BB=b;
    get_mip()->CC=c;

    if (b==0) modulus=pow((Big)2,m)+pow((Big)2,a)+1;
    else      modulus=pow((Big)2,m)+pow((Big)2,a)+pow((Big)2,b)+pow((Big)2,c)+1;
    copy(modulus.getbig(),get_mip()->modulus);
    copy(modulus.getbig(),getbig(modulo));

    w4=2;
    for (int i=1;i<=m/2;i++)
    {
        w4*=w4;
        w5=w4+2;    
        if (gcd(w5,modulo)!=1) return FALSE;
    }

    return TRUE;
}
Example #3
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);
}
Example #4
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);
}
Example #5
0
Big Crt::eval(Big *u)
{           
    Big x;
    big *b=(big *)mr_alloc(bc.NP,sizeof(big));
    for (int i=0;i<bc.NP;i++) b[i]=u[i].getbig();
    crt(&bc,b,x.getbig());
    mr_free(b); 
    return x;
}
CvSakke::CMiracl::CMiracl( sak_domain& aSakkeDomain )   //about to be deprecated
{
#ifdef MR_GENERIC_AND_STATIC
	m_pMip = mirsys( &m_instance, aSakkeDomain.nibbles, 16 );
#else
	m_pMip = mirsys( aSakkeDomain.nibbles, 16 );
#endif

	Big a = from_binary( FS, aSakkeDomain.A );
	Big b = from_binary( FS, aSakkeDomain.B );
	Big q = from_binary( FS, aSakkeDomain.Q );
	
        m_pMip->ERCON=TRUE;
	m_pMip->TWIST = MR_SEXTIC_D;
	if ( ( aSakkeDomain.flags & 1 ) == 1 )
		m_pMip->TWIST = MR_SEXTIC_M;

	ecurve_init( _MIPP_ a.getbig(), b.getbig(), q.getbig(), MR_PROJECTIVE );
}
Example #7
0
void BaseOT::PointToByteArray(BYTE* pBufIdx, int field_size, ECn &point)
{
	int itmp;
	Big bigtmp;
	//compress to x-point and y-bit and convert to byte array
	itmp = point.get(bigtmp);

	//first store the y-bit
	pBufIdx[0] = (BYTE) (itmp & 0x01);

	//then store the x-coordinate (sec-param/8 + 4 byte size)
	big_to_bytes(field_size, bigtmp.getbig(), (char*) pBufIdx+1, true);
}
Example #8
0
void ZZn2::get(Big& x) const
{{redc(fn.a,x.getbig());} }
Example #9
0
void ZZn2::get(Big& x,Big& y)  const
{{redc(fn.a,x.getbig()); redc(fn.b,y.getbig()); }} 
Example #10
0
EC2 operator*(const Big& e,const EC2& b)
{
    EC2 t;
    ecurve2_mult(e.getbig(),b.p,t.p);
    return t;
}
Example #11
0
EC2 mul(const Big& e1,const EC2& p1,const Big& e2,const EC2& p2)
{ 
    EC2 t; 
    ecurve2_mult2(e1.getbig(),p1.get_point(),e2.getbig(),p2.get_point(),t.get_point());
    return t;
}
Example #12
0
void EC2::getxyz(Big& x,Big &y,Big &z) const
        {epoint2_getxyz(p,x.getbig(),y.getbig(),z.getbig());}
Example #13
0
Big Crt::eval(mr_utype *u)
{
    Big x;
    scrt(&sc,u,x.getbig());
    return x;
}
Example #14
0
ZZn pow( const ZZn& b1, const Big& b2)
{ZZn z; nres_powmod(b1.fn,b2.getbig(),z.fn);return z;}
Example #15
0
int EC2::get(Big& x) const   
        {return epoint2_get(p,x.getbig(),x.getbig());}
Example #16
0
ECn operator*(const Big& e,const ECn& b)
{
    ECn t;
    ecurve_mult(e.getbig(),b.p,t.p);
    return t;
}
Example #17
0
int ECn::get(Big& x,Big& y) const 
        {return epoint_get(p,x.getbig(),y.getbig());}
Example #18
0
void EC2::getx(Big& x) const
        {epoint2_getxyz(p,x.getbig(),NULL,NULL);}
Example #19
0
ZZn luc( const ZZn& b1, const Big& b2, ZZn *b3)
{ZZn z; if (b3!=NULL) nres_lucas(b1.fn,b2.getbig(),b3->fn,z.fn); 
        else          nres_lucas(b1.fn,b2.getbig(),z.fn,z.fn); 
 return z;}
Example #20
0
ZZn pow( const ZZn& b1, const Big& b2, const ZZn& b3,const Big& b4)
{ZZn z; nres_powmod2(b1.fn,b2.getbig(),b3.fn,b4.getbig(),z.fn); return z;}
Example #21
0
void EC2::getxy(Big& x,Big &y) const
        {epoint2_getxyz(p,x.getbig(),y.getbig(),NULL);}