CKKS: Controling PRNG in encryption

Hello!

For study reasons, I need to control de PRNG. Basically I need to get the same encryption if i encrypt the same plaintext.

I compile without OpenMP and uncomment the #FIXED_SEED in “src/core/include/math/distributiongenerator.h”

If I do something like this for some input:

  Plaintext ptxt1 = cc->MakeCKKSPackedPlaintext(input);
  auto c1 = cc->Encrypt(keys.publicKey, ptxt1);
  auto c2 = cc->Encrypt(keys.publicKey, ptxt1);
  auto encryptElems = c1->GetElements();
  auto encryptElems_bis = c2->GetElements();

encryptElems and encryptElems_bis, have coefficients totally different.

How can I make that the random part of the encryption be fix so c1 and c2 are the same?

I saw that they fix de seed in 1. But in can figure out where this is changing.

Lattice crypto schemes do not work that way. Encrypting the same plaintext should never generate the same ciphertext otherwise it would violate IND-CPA.

Fixed seed simply fixes the RNG seed to a known value, so each run of a given piece of code should deliver the same results (primarily for software testing purposes, you should NEVER use that flag for anything secure).

Thanks for your reply!

I understand what you say. And also about the seed.
For study purpose I need to have the same encryption. So I try to see in the code where it chance the seed after an encryption to try to hardcode it. I saw that with fixed_seed the seed is fix to one but i don’t see the change after. So after my fail I post here.

There is an “easy” way to get this? Or some tip? Or in witch file the actual Encryption of CKKS is implemented? I try to get deep and can’t find it, is like a rabbit hole! jeje

CKKS public-key encryption of message (m) calculates : (c_0,c_1) = ((p_0v + e_0+m),(p_1v + e_1)) \pmod{Q} , where p_0, p_1 are the public key components, v is a random ring element in R_Q following a uniform distribution, and e_0, e_1 are random ring elements from a truncated Gaussian distribution.

To fix the encryption, you’ll need to manually modify the random elements mentioned above. Be aware that this is an invasive procedure and carries risks. OpenFHE doesn’t provide any built-in methods for this modification.

CKKS encryption logic can be found here.

Thanks! With that I manage to fix the random generation of the samples of errors and v.

I add a question that I can’t find. When I did this, I find new data types that you don’t even know what the name comes from.
For example the data type Dgg, Dug, Bug and Tug. Some insight that you can give me?

Edit: I get it no. DGG is for Discrete Gaussian Generator, TUG for Ternary Uniform Generator BUG for Binary Uniform Generator.

Edit2: If someone is interested, the simple way that I found to get this job done is by adding a method to the blake2engine class to reset its internal variables, and call it in the discrete Gaussian generator implementation, in the different parts that calls GetPRNG.