// // Program to generate "best" BN, BLS12, BLS24 and BLS48 curves (with modulus p=3 mod 8) // // g++ -O2 bestpair.cpp zzn8.cpp zzn4.cpp zzn2.cpp zzn.cpp ecn8.cpp ecn4.cpp ecn2.cpp ecn.cpp big.cpp miracl.a -o bestpair.exe // // Further tests may be needed to ensure full satisfaction (e.g. twist security, even x, etc.) // // Note that finding curves that are both GT and G2 Strong, can take a while // // SUggestions:- // For AES-128 security: bestpair BLS12 64 3 // For AES-192 security: bestpair BLS24 48 4 // FOr AES-256 security: bestpair BLS48 32 4 // Some possible rational points on y^2=x^3+b (x^3+b is a perfect square) // b=1, x=0, -1 or 2 // b=2, x=-1 // b=3, x=1 // b=4, x=0 // b=5, x=-1 // b=8, x=-2, 1, 2 // b=9, x=0, 3, 6, 40 // b=10, x=-1 // b=12, x=-2, 13 // b=-1, x=1 // b=-2, x=3; // b=-4, x=2, 5 // b=-7, x=2, 32 // b=-8, x=2 // b=-11, x=3, 15 // of course these points need to be checked for correct order... #include #include "big.h" #include "ecn.h" #include "ecn2.h" #include "ecn4.h" #include "ecn8.h" #define BN 0 #define BLS12 1 #define BLS24 2 #define BLS48 3 using namespace std; Miracl precision=500; // Number of ways of selecting k items from n Big combo(int n,int k) { // calculate n C k int i; Big c,d; d=1; for (i=2;i<=k;i++) d*=i; c=1; for (i=n;i>n-k;i--) c*=i; c/=d; return c; } // Number of candidates to be searched. Big count(int b,int h) { Big c=combo(b-h+1,h-1)+combo(b-h+1,h-2); c*=pow((Big)2,h); return c; } // Move to next NAF pattern int iterate(int *x,int n) { int i,j,k,gotone=0; for (i=0;i30 and <200)" << endl; cout << "and hamming-weight is the number of non-zero bits (>1 and <10)" << endl; cout << "e.g. bestpair BLS12 77 3" << endl; cout << "Use flag /GT for GT-Strong curves" << endl; cout << "Use flag /G2 for G2-Strong curves" << endl; cout << "Use flag /P to show progress" << endl; exit(0); } ip=0; HW=0; BITS=0; G2=GT=gotB=gotH=gotT=progress=FALSE; while (ip9 || HW<2 || BITS>=200 || BITS<30) { cout << "Error in command line" << endl; return 0; } hw=HW-1; msb=pow((Big)2,BITS); for (i=0;i<=BITS;i++) xb[i]=0; for (i=0;i0 && !iterate(xb,BITS)) break; for (i=j=0;i=-20) { nb-=1; ecurve(0,nb,p,MR_AFFINE); while (!P.set(rand(p))) ; P*=cof; if ((q*P).iszero()) cb[m++]=nb; } ecurve(0,b,p,MR_AFFINE); // find number of points on sextic twist.. twist=MR_SEXTIC_D; mip->TWIST=MR_SEXTIC_D; if (type==BLS12 || type==BN) { ECn2 Q; ZZn2 rr; do { rr=randn2(); } while (!Q.set(rr)); Q*=cof2; if (!(n*Q).iszero()) { twist=MR_SEXTIC_M; mip->TWIST=MR_SEXTIC_M; do { rr=randn2(); } while (!Q.set(rr)); Q*=cof2; if (!(n*Q).iszero()) { cout << "Never Happens" << endl; continue; } } } if (type==BLS24) { ECn4 Q; ZZn4 rr; do { rr=randn4(); } while (!Q.set(rr)); Q*=cof2; if (!(n*Q).iszero()) { twist=MR_SEXTIC_M; mip->TWIST=MR_SEXTIC_M; do { rr=randn4(); } while (!Q.set(rr)); Q*=cof2; if (!(n*Q).iszero()) { cout << "Never Happens" << endl; continue; } } } if (type==BLS48) { ECn8 Q; ZZn8 rr; do { rr=randn8(); } while (!Q.set(rr)); Q*=cof2; if (!(n*Q).iszero()) { twist=MR_SEXTIC_M; mip->TWIST=MR_SEXTIC_M; do { rr=randn8(); } while (!Q.set(rr)); Q*=cof2; if (!(n*Q).iszero()) { cout << "Never Happens" << endl; continue; } } } S++; cout << endl; cout << "Solution " << S << endl; x=0; bt=1; mip->IOBASE=16; cout << "x= "; for (k=0;k0) { cout << "(or) "; for (jj=0;jjIOBASE=10; // cout << "twist= " << p+1+t << endl; } } cout << endl; cout << cnt << " solutions searched" << endl; if (S==0) { cout << "No solutions found" << endl; return 0; } if (S==1) { cout << "One solution found" << endl; return 0; } cout << S << " solutions found" << endl; return 0; }