snucrypto/HEAAN

The serialization problem

Huelse opened this issue · 8 comments

When I use the latest HEAAN, I found I can't save the key and encrypt the array correctly.
Even the simplest code will also happen segmentation faul.
Environment: Ubuntu18.04.3, NTL-11.4.2

long logq = 300;
long logp = 30;
long logn = 10;
long n = 1 << logn;

TimeUtils timeutils;
Ring ring;
SecretKey secretKey(ring);
Scheme scheme(secretKey, ring, true); //1 is this right?
scheme.addLeftRotKeys(secretKey);
scheme.addRightRotKeys(secretKey);

complex<double>* mvec1 = EvaluatorUtils::randomComplexArray(slots);
complex<double>* mvec2 = EvaluatorUtils::randomComplexArray(slots);
// It's no problem that the program can run to here

cout << "Start Mat Encrypting" << endl;
Ciphertext cipher1;
// 2 Here segmentation fault, I can't encrypt anything.
scheme.encrypt(cipher1, mvec1, n, logp, logq);
Ciphertext cipher2;
scheme.encrypt(cipher2, mvec2, n, logp, logq);
  1. I need mkdir serkey .

e

I don't know if I made a mistake with it,
and the serialization can be used in below's HEANN which from KyoohyungHan/HELR

There is a problem in SerializationUtils. Look at my fork https://github.com/gamma-2017/libHEAAN, there it is repaired.

@gamma-2017 Thank you, a very quick answer, I will try it later.

@gamma-2017 I just tried to use it, and found a new probelem:
Snipaste_2020-02-13_01-14-56.jpg

Oh, you took my entire code. I just meant you to look into <SerializationUtils.cpp>.

Now, mind that <Params.h> contains some essential settings. In particular, logN and logQ are defined there. The values logn and logq that you choose MUST be smaller than those.

For faster testing I have decreased logN to a much smaller value than 16, namely 7 (unless you define SECURE). Things are much faster this way, but not secure. Also, there are only 2^6 slots instead of 2^15 slots, which is still enough for tests.

Your new problem now probably comes from having logn > logN-1 = 6. Among the things that my fork does differently are various assertions, they basically check that parameters are correct and rais an error like your one. In this case the assertion was

0<=n && n<=N && 0==N%n

and it failed. Recalling n=2^logn, N=2^logN you should understand that message.

I hope I could clarify what happend. It's tricky.

PS: Have you tried running your code with a nice debugger, in some development environment? That helps. [I am using kdevelop; but I am sure there are also others.]

@gamma-2017 got it, thank you.

Here is a new problem now, I have generated the key in local serkey/ROTATION_*.txt
when I diable the addkeys, it show me errors.

Ring ring;
SecretKey secretKey(ring);
Scheme scheme(secretKey, ring, true);
//scheme.addLeftRotKeys(secretKey);
//scheme.addRightRotKeys(secretKey);
...
scheme.rightRotateFast(ctemp, ctxt, 1);
===
terminate called after throwing an instance of 'std::out_of_range'
  what():  map::at

I think the scheme didn't load the rotation key.
How can I solve it? Thanks!

Hi,
the map struct keeping all rotation keys reports that the desired one, namely the rotation key for rotating right by 1 position, is not available. You need to call scheme.addRightRotKey( ..., 1 ) [check name] to generate it before calling rightRotate .
Enjoy

Alright, I don't know much about this lib, it don't have the i/o notes, thank you again.