// // Generate random non-supersingular curves suitable for pairings... // Security Multiplier 2,4 or 8 // Uses "folklore method" - actually due to Cocks & Pinch // // See Chapter 9 (by Steve Galbraith) in Advances in Elliptic Curve // Cryptography, edited by Blake, Seroussi and Smart, Cambridge University // Press (published January 2005) // // cl /O2 /GX folklore.cpp big.cpp miracl.lib // // if k=2 prime p = 3 mod 4 // // Creates batch file c.bat to generate curve using CM // You MUST make sure that the CM utility builds the curve with the right // number of points (normally you get two choices for the given D). // // NOTE: The CM utility creates a file kn.ecs (where n=2,4 or 8) // Then you must delete the last line from kn.ecs and manually insert the file // extra.ecs at the bottom. // The file extra.ecs is created by this program. // #include #include #include "big.h" #include using namespace std; Miracl precision(100,0); BOOL sqr_free(Big m) { Big r; for (r=2;;r+=1) { if (m%(r*r)==0) return FALSE; if (r*r > m) break; } return TRUE; } int main(int argc,char **argv) { Big D; time_t seed; int i,e,k,nbits; Big s,j,p,r,g,b0,a,c,n,v,w,t; ofstream batch("c.bat"); ofstream extra("extra.ecs"); miracl *mip=&precision; BOOL correct; time(&seed); irand((long)seed); argc--; argv++; if (argc!=1) { cout << "Missing parameter" << endl; return 0; } e=atoi(argv[0]); if (e<1 || e>3) { cout << "Bad parameters" << endl; cout << "folklore N " << endl; cout << "where N is 1,2 or 3. Security multiplier k=2^N" << endl; return 0; } // important parameters calculated here... k=1<IOBASE=16; extra << n/r << endl; extra << r << endl; if (k==4) { // extra << pow(p-2,(p-1)/4,p) << endl; w=(pow(p,2)+1)/r; extra << w/p << endl; extra << w%p << endl; } if (k==8) { // extra << pow(p-2,(p-5)/8,p) << endl; w=(pow(p,4)+1)/r; extra << w/(p*p*p) << endl; w%=(p*p*p); extra << w/(p*p) << endl; w%=(p*p); extra << w/p << endl; extra << w%p << endl; } return 0; }