コード例 #1
0
ファイル: FHEContext.cpp プロジェクト: ssmiler/HElib
// 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;
}
コード例 #2
0
ファイル: FHEContext.cpp プロジェクト: fionser/HElib
// 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;
}
コード例 #3
0
ファイル: FHEContext.cpp プロジェクト: fionser/HElib
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;
}