Exemplo n.º 1
0
// 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;
}
Exemplo n.º 2
0
void readContextBinary(istream& str, FHEcontext& context)
{
  assert(readEyeCatcher(str, BINIO_EYE_CONTEXT_BEGIN)==0);

  // Get the standard deviation
  context.stdev = read_raw_xdouble(str);

  long sizeOfS = read_raw_int(str);

  IndexSet s;
  for(long tmp, i=0; i<sizeOfS; i++){
    tmp = read_raw_int(str);
    s.insert(tmp);
  }

  context.moduli.clear();
  context.specialPrimes.clear();
  context.ctxtPrimes.clear();

  long nPrimes = read_raw_int(str);

  for (long p,i=0; i<nPrimes; i++) {
    p = read_raw_int(str);

    context.moduli.push_back(Cmodulus(context.zMStar,p,0));

    if (s.contains(i))
      context.specialPrimes.insert(i); // special prime
    else
      context.ctxtPrimes.insert(i);    // ciphertext prime
  }
  
  long nDigits = read_raw_int(str);

  context.digits.resize(nDigits);
  for(long i=0; i<(long)context.digits.size(); i++){
    sizeOfS = read_raw_int(str);

    for(long tmp, n=0; n<sizeOfS; n++){
      tmp = read_raw_int(str);
      context.digits[i].insert(tmp);
    }
  }

  // Read in the partition of m into co-prime factors (if bootstrappable)
  Vec<long> mv;
  read_ntl_vec_long(str, mv);

  long t = read_raw_int(str);
  bool consFlag = read_raw_int(str);  

  if (mv.length()>0) {
    context.makeBootstrappable(mv, t, consFlag);
  }

  assert(readEyeCatcher(str, BINIO_EYE_CONTEXT_END)==0);
}
Exemplo n.º 3
0
// 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;
}
Exemplo n.º 4
0
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;
}