// (C) 2017 University of Bristol. See License.txt #include "Math/Setup.h" #include "Math/gfp.h" #include "Math/gf2n.h" #include "Tools/mkpath.h" #include /* * Just setup the primes, doesn't need NTL. * Sets idx and m to be used by SHE setup if necessary */ void SPDZ_Data_Setup_Primes(bigint& p,int lgp,int& idx,int& m) { cout << "Setting up parameters" << endl; switch (lgp) { case -1: m=16; idx=1; // Any old figures will do, but need to be for lgp at last lgp=32; // Switch to bigger prime to get parameters break; case 32: m=8192; idx=0; break; case 64: m=16384; idx=1; break; case 128: m=32768; idx=2; break; case 256: m=32768; idx=3; break; case 512: m=65536; idx=4; break; default: throw invalid_params(); break; } cout << "m = " << m << endl; // Here we choose a prime which is the order of a BN curve // - Reason is that there are some applications where this // would be a good idea. So I have hard coded it in here // - This is pointless/impossible for lgp=32, 64 so for // these do something naive // - Have not tested 256 and 512 bigint u; int ex; if (lgp!=32 && lgp!=64) { u=1; u=u<<(lgp-1); u=sqrt(sqrt(u/36))/m; u=u*m; bigint q; // cout << ex << " " << u << " " << numBits(u) << endl; p=(((36*u+36)*u+18)*u+6)*u+1; // The group order of a BN curve q=(((36*u+36)*u+24)*u+6)*u+1; // The base field size of a BN curve while (!probPrime(p) || !probPrime(q) || numBits(p)> p; inpf >> lg2; inpf.close(); gfp::init_field(p); gf2n::init_field(lg2); } void read_setup(int nparties, int lg2p, int gf2ndegree) { string dir = get_prep_dir(nparties, lg2p, gf2ndegree); read_setup(dir); }