homenc / HElib

HElib is an open-source software library that implements homomorphic encryption. It supports the BGV scheme with bootstrapping and the Approximate Number CKKS scheme. HElib also includes optimizations for efficient homomorphic evaluation, focusing on effective use of ciphertext packing techniques and on the Gentry-Halevi-Smart optimizations.
https://homenc.github.io/HElib
Other
3.11k stars 760 forks source link

EXC_BAD_ACCESS when calling recrypt method in v2.0.0 #419

Open s-naveen opened 3 years ago

s-naveen commented 3 years ago

Please let me know how to solve this.

Stack Trace:

helib::EvalMap::apply(helib::Ctxt&) const EvalMap.cpp:173
helib::PubKey::reCrypt(helib::Ctxt&) const recryption.cpp:513
main test.cpp:135
faberga commented 3 years ago

Hi @s-naveen Can you give us more information on what you are trying to do in your test.cpp program and also the parameters you used to build the context ?

-Flavio

s-naveen commented 3 years ago

@faberga

  // Plaintext prime modulus
  unsigned long p = 131;
  // Cyclotomic polynomial - defines phi(m)
  unsigned long m = 10075;
  // Hensel lifting (default = 1)
  unsigned long r = 1;
  // Number of bits of the modulus chain
  unsigned long bits = 2000;
  // Number of columns of Key-Switching matrix (default = 2 or 3)
  unsigned long c = 2;
  // Generating set of Zm* group.
  std::vector<long> gens = {3876, 6852, 1301};
  // Orders of the previous generators.
  std::vector<long> ords = {12, 20, 2};
  NTL::Vec<long> mvec;
  mvec.SetLength(3);
  mvec[0] = 13;
  mvec[1] = 25;
  mvec[2] = 31;

    helib::Context context = helib::ContextBuilder<helib::BGV>()
      .m(m)
      .p(p)
      .r(r)
      .gens(gens)
      .ords(ords)
      .bits(bits)
      .c(c)
      .bootstrappable(true)
      .mvec(mvec)
      .build();

Just a simple test of addition and couple of multiplications

helib::Ptxt<helib::BGV> query_ptxt(context);
query_ptxt[0] = 20;
public_key.Encrypt(encrypted_text, query_ptxt);
public_key.Encrypt(encrypted_text2, query_ptxt);
public_key.Encrypt(encrypted_text3, query_ptxt);
public_key.Encrypt(encrypted_text4, query_ptxt);
encrypted_text.addCtxt(encrypted_text2);
encrypted_text.multiplyBy(encrypted_text3);
encrypted_text.multiplyBy(encrypted_text4);
public_key.ReCrypt(encrypted_text);  <--- Error Line
helib::Ptxt<helib::BGV> result(context);
secret_key.Decrypt(result, encrypted_text);
faberga commented 3 years ago

@s-naveen Hi Naveen, please refer to comment @jlhcrawford posted to Issue #418 .