Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use an array to build a Ciphertext? #708

Open
cipeizheng opened this issue Oct 23, 2024 · 2 comments
Open

How to use an array to build a Ciphertext? #708

cipeizheng opened this issue Oct 23, 2024 · 2 comments

Comments

@cipeizheng
Copy link

I am trying to use the GPU etc. to compute Ciphertext. I have used for_each_n() function and iterators to extract Dynarray's elements ( I think they are coefficients of ciphertext polynomials) in Ciphertext and computed them. But I am confusing with how to use the results (In my case they are vector<uint64_t>) to build a Ciphertext object.

I tried copy() function, but it works in a weird way: If I copy an extracted data to its original Ciphertext, it works well in decryption and decode, but in another case I get wrong results. So is there a way to use an array to build a Ciphertext? Do I have to use Deserialization?

@kimlaine
Copy link
Contributor

kimlaine commented Nov 1, 2024

I would just use the SEAL iterators to write the ciphertext data. It's kind of impossible to say what might be going wrong without a lot more details. Can you debug and check at least that the ciphertext data is what you think it should be after you write it?

@cipeizheng
Copy link
Author

Thanks for your reply!
I have tried adding some output in Decryptor::bfv_decrypt to trace the decryption process, and I think the problem maybe happening in rns_tool()->decrypt_scale_and_round().

Here is what I did:
In main.cpp I extract data, and copied it like this:

ConstCoeffIter operand1 = encrypted1.data();
ConstCoeffIter operand2 = encrypted2.data();

vector<uint64_t> data1, data2;

for_each_n(iter(operand1, operand2), coeff_count, [&](auto I){
    data1.push_back(get<0>(I));
    data2.push_back(get<1>(I));
});

copy(data2.begin(), data2.end(), encrypted1.data()); 

In decryptor.cpp I added output before and after the call to rns_tool()->decrypt_scale_and_round(). After decrypting both encrypted1 and encrypted2, I noticed that the two tmp_dest_modqs are same, but the two destination values were different. In my opinion, since the parameters passed to decrypt_scale_and_round() are the same, this discrepancy is quite confusing.

Besides, could you help me understand how to use SEAL iterators to properly write ciphertext data? Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants