本文整理汇总了C++中ECn::get方法的典型用法代码示例。如果您正苦于以下问题:C++ ECn::get方法的具体用法?C++ ECn::get怎么用?C++ ECn::get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ECn
的用法示例。
在下文中一共展示了ECn::get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: to_string
String CvSakke::to_string( const ECn& point )
{
Big x, y;
point.get(x, y);
return "[" + to_string(x) + "," + to_string(y) + "]";
}
示例2: main
int main()
{
ifstream common("mnt.ecs"); // MNT elliptic curve parameters
ifstream private_key("bls_private.key");
ofstream signature("bls_signature.sig");
miracl* mip=&precision;
ECn PM;
Big x,s,p,q,B;
int bits,A,lsb;
common >> bits;
mip->IOBASE=16;
common >> p;
common >> A;
common >> B >> q;
private_key >> s;
ecurve(A,B,p,MR_PROJECTIVE);
PM=hash_and_map((char *)"This a quick test of the method",32);
cout << "Short message has been signed - signature in bls_signature.sig " << endl;
PM*=s;
lsb=PM.get(x);
signature << x << endl;
signature << lsb << endl;
return 0;
}
示例3: signatureofshorthash
int signatureofshorthash(unsigned char *sm,mr_unsign64 *smlen,const unsigned char *m,mr_unsign64 mlen,const unsigned char *sk,mr_unsign64 sklen)
{
miracl* mip=mirsys(40,16);
ECn PM;
Big x,y,s,p,B;
int lsb,bits;
mip->IOBASE=16;
p=ptext;
B=Btext;
ecurve((Big)-3,B,p,MR_PROJECTIVE);
s=from_binary((int)sklen,(char *)sk);
PM=hash_and_map((char *)m,32);
PM*=s;
lsb=PM.get(x);
to_binary(x,20,(char *)sm,TRUE);
*smlen=20;
if (lsb) sm[0]|=0x80;
return 0;
}
示例4: main
int main()
{
ifstream common("common.ecs"); /* construct file I/O streams */
ifstream private_key("private.ecs");
ifstream message;
ofstream signature;
char ifname[50],ofname[50];
ECn G;
Big a,b,p,q,x,y,h,r,s,d,k;
long seed;
int bits;
miracl *mip=&precision;
/* randomise */
cout << "Enter 9 digit random number seed = ";
cin >> seed;
irand(seed);
/* get common data */
common >> bits;
mip->IOBASE=16;
common >> p >> a >> b >> q >> x >> y;
mip->IOBASE=10;
/* calculate r - this can be done off-line,
and hence amortized to almost nothing */
ecurve(a,b,p,MR_PROJECTIVE);
G=ECn(x,y);
// k="702232148019446860144825009548118511996283736794"; // test vector from http://www.secg.org/collateral/gec2.pdf
k=rand(q);
G*=k; /* see ebrick.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);
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);
signature << r << endl;
signature << s << endl;
return 0;
}
示例5: map_f
ECn map_f(ECn& P,ZZn& zeta)
{
ECn R;
Big x,y;
P.get(x,y);
ZZn X=x;
X=zeta*X; x=Big(X);
if (!R.set(x,y)) cout << "something wrong in map_f" << endl;
return R;
}
示例6: ecap
BOOL ecap(ECn& P,ECn& Q,Big& order,ZZn& zeta,Big& cofactor,ZZn& res)
{
BOOL Ok;
Big Qx,Qy;
ZZn bQx;
Q.get(Qx,Qy);
bQx=zeta*zeta*(ZZn)Qx;
Ok=fast_tate_pairing(P,(ZZn)Qx,(ZZn)Qy,bQx,order,cofactor,res);
if (Ok) return TRUE;
return FALSE;
}
示例7: PointToByteArray
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);
}
示例8: ecap
BOOL ecap(ECn3& P,ECn& Q,Big& x,ZZn &X,ZZn18& r)
{
BOOL Ok;
Big xx,yy;
ZZn Qx,Qy;
Q.get(xx,yy); Qx=xx; Qy=yy;
Ok=fast_pairing(P,Qx,Qy,x,X,r);
if (Ok) return TRUE;
return FALSE;
}
示例9: ecap
BOOL ecap(ECn& P,ECn& Q,Big& order,BOOL precomp,ZZn *store,ZZn2& res)
{
ZZn Qx;
ZZn2 Qy;
Big xx,yy;
Q.get(xx,yy);
Qx=-xx;
Qy.set((Big)0,yy);
return fast_tate_pairing(P,Qx,Qy,order,precomp,store,res);
}
示例10: sizeof
int
ECnTochar (ECn &e, char *c, int s)
{
Big x, y;
e.get(x, y);
int len = 0;
int totlen = sizeof (int)*2;
// cout << "Entering ECnTochar" << endl;
// format: 4 bytes length, followed by the big
if (s <= sizeof (int))
return -1;
// Code assumes epoint contains either nulls or bigs > 0
s -= sizeof (int);
c += sizeof (int);
if (x.iszero()) {
len = 0;
} else {
len = to_binary (x, s, c, FALSE);
}
if (len < 0) {
return -1;
}
memcpy ((char *)(c - sizeof(int)), (void *)&len, sizeof (int));
totlen += len;
s -= len;
c += len;
// cout << "Len1 " << len << " x " << x;
if (s <= sizeof (int))
return -1;
s -= sizeof (int);
c += sizeof (int);
len = to_binary (y, s, c, FALSE);
if (len < 0)
return -1;
memcpy ((char *)(c - sizeof(int)), (void *)&len, sizeof (int));
totlen += len;
// cout << "Len2 " << len << " y " << y;
return totlen;
}
示例11: ecap
BOOL ecap(ECn2& P,ECn& Q,Big& x,ZZn2 &X,ZZn12& r)
{
BOOL Ok;
Big xx,yy;
ZZn Qx,Qy;
P.norm();
cout<<"P:"<<P<<endl;
Q.get(xx,yy); Qx=xx; Qy=yy;
Ok=fast_pairing(P,Qx,Qy,x,X,r);
if (Ok) return TRUE;
return FALSE;
}
示例12: ecap
BOOL ecap(ECn& P,ECn& Q,Big& order,ZZn2& cube,ZZn2& res)
{
ZZn2 Qx;
ZZn Qy,iy;
Big xx,yy;
Q.get(xx,yy);
Qx=(ZZn)xx*cube;
Qy=(ZZn)yy;
iy=(ZZn)1/(Qy+1);
Qx=-2*Qx*iy;
Qy=(Qy-3)*iy; // Q+=(0,1)
if (fast_tate_pairing(P,Qx,Qy,order,res)) return TRUE;
return FALSE;
}
示例13: ecap
BOOL ecap(ECn& P,ECn& Q,Big& order,ZZn2& cube,ZZn2& res)
{
ZZn2 Qx,Qy;
Big xx,yy;
#ifdef SCOTT
ZZn a,b,x,y,ib,w,t1,y2,ib2;
#else
ZZn2 lambda,ox;
#endif
Q.get(xx,yy);
Qx=(ZZn)xx*cube;
Qy=(ZZn)yy;
#ifndef SCOTT
// point doubling
lambda=(3*Qx*Qx)/(Qy+Qy);
ox=Qx;
Qx=lambda*lambda-(Qx+Qx);
Qy=lambda*(ox-Qx)-Qy;
#else
// explicit point subtraction
Qx.get(a,b);
y=yy;
ib=(ZZn)1/b;
t1=a*b*b;
y2=y*y;
ib2=ib*ib;
w=y2+2*t1;
x=-w*ib2;
y=-y*(w+t1)*(ib2*ib);
Qx.set(x); Qy.set((ZZn)0,y);
#endif
if (fast_tate_pairing(P,Qx,Qy,order,res)) return TRUE;
return FALSE;
}
示例14: main
//.........这里部分代码省略.........
Q=(p-1+t)*Q; // generator point in G2
cru=(18*pow(x,3)-18*x*x+9*x-2);
}
if (strcmp(curvename,"BLS383")==0)
{
curve=20;
printf("Curve= BLS383\n");
strcpy(fieldname,curvename);
mbits=383;
words=(1+((mbits-1)/bb));
curvetype=WEIERSTRASS;
modtype=NOT_SPECIAL;
curve_a=0;
mip->IOBASE=16;
// x=(char *)"11000001000000040";
x=(char *)"10008000001001200"; // SIGN_OF_X is POSITIVE
p=(pow(x,6)-2*pow(x,5)+2*pow(x,3)+x+1)/3;
t=x+1;
r=pow(x,4)-x*x+1;
cof=(p+1-t)/r;
// gx=-2; gy=-1;
// curve_b=9;
gx=1; gy=4;
curve_b=15;
ecurve((Big)0,curve_b,p,MR_AFFINE);
// mip->TWIST=MR_SEXTIC_D;
mip->TWIST=MR_SEXTIC_M;
P.set(gx,gy);
P*=cof;
P.get(gx,gy);
//cout << "gx= " << gx << endl;
//cout << "gy= " << gy << endl;
//cout << "y^2= " << (gy*gy)%p << endl;
//cout << "x^3+b= " << (gx*gx*gx+15)%p << endl;
//while (!Q.set(randn2())) ; // probably not best way to choose this
Xa=1;
while (!Q.set(Xa))
{
Xa=Xa+(ZZn2)1;
}
TT=t*t-2*p;
PP=p*p;
FF=sqrt((4*PP-TT*TT)/3);
np=PP+1-(-3*FF+TT)/2; // 2 possibilities...
Q=(np/r)*Q;
zcru=pow((ZZn)2,(p-1)/3);
// zcru*=zcru; // right cube root of unity
cru=(Big)zcru;
}
if (strcmp(curvename,"BLS381")==0)
{
curve=21;
printf("Curve= BLS381\n");
strcpy(fieldname,curvename);
mbits=381;
示例15: if
//.........这里部分代码省略.........
cout << setw(3) << (p+1-tau)%lp << flush;
}
t[i]=tau;
if ((p+1-tau)%lp==0)
{
cout << " ***" << endl;
if (search && (!Edwards || lp!=4)) escape=TRUE;
}
else cout << endl;
break;
}
cout << "\b\b\b";
}
for (jj=0;jj<low;jj++)
{
Pf[jj].clear();
P2f[jj].clear();
P3f[jj].clear();
}
if (escape) break;
}
Modulus.clear();
for (i=0;i<=L+1;i++)
{
P[i].clear(); // reclaim space
P2[i].clear();
P3[i].clear();
}
if (escape) {b+=1; continue;}
Big order,ordermod;
ordermod=1; for (i=0;i<nl-start_prime;i++) ordermod*=(int)l[start_prime+i];
order=(p+1-CRT.eval(&t[start_prime]))%ordermod; // get order mod product of primes
nrp=kangaroo(p,order,ordermod);
if (Edwards)
{
if (!prime(nrp/4) && search) {b+=1; continue; }
else break;
}
else
{
if (!prime(nrp) && search) {b+=1; continue; }
else break;
}
}
if (fout)
{
ECn P;
ofile << bits(p) << endl;
mip->IOBASE=16;
ofile << p << endl;
ofile << a << endl;
ofile << b << endl;
// generate a random point on the curve
// point will be of prime order for "ideal" curve, otherwise any point
if (!Edwards)
{
do {
x=rand(p);
} while (!P.set(x,x));
P.get(x,y);
ofile << nrp << endl;