// Find the next prime and add it to the chain long FHEcontext::AddPrime(long initialP, long delta, bool special, bool findRoot) { // long twoM = 2 * zMStar.getM(); // assert((initialP % twoM == 1) && (delta % twoM == 0)); // NOTE: this assertion will fail for the half-prime in ALT_CRT long p = initialP; do { p += delta; // delta could be positive or negative } while (p>initialP/16 && p<NTL_SP_BOUND && !(ProbPrime(p) && !inChain(p))); if (p<=initialP/16 || p>=NTL_SP_BOUND) return 0; // no prime found long i = moduli.size(); // The index of the new prime in the list moduli.push_back( Cmodulus(zMStar, p, findRoot ? 0 : 1) ); if (special) specialPrimes.insert(i); else ctxtPrimes.insert(i); return p; }
// Find the next prime and add it to the chain long FHEcontext::AddPrime(long initialP, long delta, bool special) { long p = initialP; do { p += delta; } // delta could be positive or negative while (p>initialP/16 && p<NTL_SP_BOUND && !(ProbPrime(p) && !inChain(p))); if (p<=initialP/16 || p>=NTL_SP_BOUND) return 0; // no prime found long i = moduli.size(); // The index of the new prime in the list moduli.push_back( Cmodulus(zMStar, p, 0) ); if (special) specialPrimes.insert(i); else ctxtPrimes.insert(i); return p; }
long FHEcontext::AddFFTPrime(bool special) { zz_pBak bak; bak.save(); // Backup the NTL context do { zz_p::FFTInit(fftPrimeCount); fftPrimeCount++; } while (inChain(zz_p::modulus())); long i = moduli.size(); // The index of the new prime in the list long p = zz_p::modulus(); moduli.push_back( Cmodulus(zMStar, 0, 1) ); // a dummy Cmodulus object if (special) specialPrimes.insert(i); else ctxtPrimes.insert(i); return p; }