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

Add Serialization/Deserialization for all keys #3

Open
Janmajayamall opened this issue Jul 12, 2023 · 4 comments
Open

Add Serialization/Deserialization for all keys #3

Janmajayamall opened this issue Jul 12, 2023 · 4 comments

Comments

@Janmajayamall
Copy link
Owner

Janmajayamall commented Jul 12, 2023

Add serialization/deserialization for Poly, Ciphertext, KeySwitchingKey, RelinerizationKey, GaloisKey.

Since all keys depend on Poly and poly only consists of coefficients (ie Array2) and representation, the only important functions are converting vector of u64s (ie each row in Array2) to bytes and back.

I have already implemented functions to convert vector of u64s assumed to be in range [0, modulus) to bytes and back. Check convert_to_bytes and convert_from_bytes.

I have also added a rough way to convert Poly to proto::Poly here.

Conversion of proto::Poly to bytes is behaving as expected. For example, a Poly with modulus Q of size 500 bits (ie moduli chain = [50;10]) and degree 2^15 should take 500*(2^15)/8 = 2048000 bytes (ignoring representation value). I can confirm that converting such a Poly to proto::Poly and encoding converted value in bytes equals to 2048052 bytes, which is only a difference of 52 bytes.

@Janmajayamall
Copy link
Owner Author

Commit 5bf8e16 implements serialization/deserialization for HybridKeySwitchingKey, EvaluationKey, RelinearizationKey, GaloisKey.

I checked that serialized objects are of expected size in bytes by first estimating the sizes by hand and then converting the types to respective serialized types and then to bytes. Eveything looks correct.

@Janmajayamall
Copy link
Owner Author

I seem to have made a mistake by allowing Poly to be serialized in Evaluation representation. Since we plan to support mutiple NTT backends, Evaluation representation of same polynomial can be different on each. This can lead to incorrectness if one serializes a polynomial in Evaluation form using native NTT backend and deserializes it using hexl NTT backend, since the polynomial would not remain the same.

To avoid this, I think it is ok to forbid serliization of polynomial in Evaluation form.

@Janmajayamall
Copy link
Owner Author

Commit db97066 adds support for seeded Ciphertexts and makes necessary changes to forbid seriaization of Poly in Evalaution form

@Janmajayamall
Copy link
Owner Author

I have been contemplating to switch serialization to a feature. The obvious benefit of this is to allow users not in need of serialization to not download and install protobuf compiler. Plus, I don't see any downisdes of this.

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

1 participant