Closed yoshiko305 closed 3 years ago
Your code looks right. Having L=180 and getting 180 capacity is not correct, as encryption alone should introduce some noise. In my experience, it actually introduces a great amount of noise. For accurate reading also use capacity()
instead of bitCapacity()
.
Thank you for telling me about the capacity()
function.
I tried using it but I still get the same issue of getting different values for capacity()
of a newly encrypted ciphertext between the two cases in which I encrypt a vector using newly generated keys vs. using keys that I read in from a file. I got 124 and 118 as the result of calling capacity()
I get:
noise generated: 117.613279
noise read: 117.614043
Usually these are the same, strange they differ by a bit. I don't know what the problem is. I also have addFrbMatrices(secretKey);
in my code, but I don't think it matters in this case. This context takes really long to generate (296.376625 seconds), is there a particular reason you are using it? Asking out of curiosity, because the number of slots is also not that much - 218.
@yoshiko305 @boev Thank you for raising this issue and providing the code that replicates your issue. Let us reproduce the observed behavior and get back to you.
@yoshiko305 we have reproduced the issue of differences in the capacity you raised on our systems and are investigating. Will publish update as we progress.
@yoshiko305 How are you measuring the encryption time?
@faberga Thank you for investigating the issue. To measure the encryption time, I'm using C++'s std::chrono::system_clock::now()
to get the time at before and after the encryption and get the difference. I get the time in milliseconds using
msec = std::chrono::duration_cast<std::chrono::milliseconds>(diff).count()
Hi @yoshiko305, @boev @faberga, I was able to replicate the issue and understand the behaviour.
What I found is that in the first code snippet the encryption is done using the secret key because of the polymorphism from using a reference pointing to the FHESecKey
object (const FHEPubKey& publicKey = secretKey
).
However, in the second code snippet it is used the public key that has been de-serialised/read in as an actual FHEPubKey
object, therefore encryption is done using the public key. This is caused by the fact that the function writePubKeyBinary
serialise the key as an FHEPubKey
regardless the fact that the argument is a FHESecKey
reference.
Using the secret key for encryption gives a bigger capacity (as explained in the documentation [1] page 30: Secret-key encryption).
To obtain the same behaviour in term of capacity in the first code snippet, the public key cannot be a reference to the secret key, but an actual FHEPubKey
object. This can be done constructing the key explicitly: FHEPubKey publicKey(secretKey)
(using slicing).
[1] https://github.com/homenc/HElib/blob/master/doc/designDocument/he-library.pdf
@yoshiko305 hi there. Can you confirm whether Enrico's answer resolved your query, please? Thank you
OS: Ubuntu 16.04
Hi. I'm currently working on some experimental implementations for a project. During the implementation, I realized that there is a large difference in the encryption time between using newly generated keys and using keys read in from a file.
With the parameters I'm using right now, the time to encrypt a vector of different values using newly generated keys and keys read in from a file is approximately 0.34s and 0.02s, respectively. Also, I have noticed that the bitCapacity() of a newly encrypted ciphertext is different between the two cases (180 and 169). In some cases,
Why is such difference occurring? Thank you.
The following are the current parameters and source code for generating the keys, writing them out to a file, then continue using the newly generated keys for encrypting data.
Below is the source code for reading in the context, pk, and sk from a file then encrypting the same vector as previous code.