diff --git a/Cargo.lock b/Cargo.lock index a3cdac95..8da34455 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -213,7 +213,7 @@ dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.46", + "syn 2.0.94", ] [[package]] @@ -235,7 +235,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4f4643dbd5de069e099122ae6c2bbd3db70d69ffec348dfc228448d635f949e" dependencies = [ "aligned-vec", - "pulp", + "pulp 0.18.9 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -457,6 +457,7 @@ dependencies = [ "prost-build", "rand", "rand_chacha", + "serde", "thiserror", "zeroize", "zeroize_derive", @@ -481,9 +482,10 @@ dependencies = [ "proptest", "prost", "prost-build", - "pulp", + "pulp 0.18.9 (git+https://github.com/zefr0x/pulp.git?branch=implserde)", "rand", "rand_chacha", + "serde", "sha2", "thiserror", "zeroize", @@ -746,6 +748,7 @@ dependencies = [ "num-integer", "num-traits", "rawpointer", + "serde", ] [[package]] @@ -757,6 +760,7 @@ dependencies = [ "autocfg", "num-integer", "num-traits", + "serde", ] [[package]] @@ -892,14 +896,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae005bd773ab59b4725093fd7df83fd7892f7d8eafb48dbd7de6e024e4215f9d" dependencies = [ "proc-macro2", - "syn 2.0.46", + "syn 2.0.94", ] [[package]] name = "proc-macro2" -version = "1.0.74" +version = "1.0.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2de98502f212cfcea8d0bb305bd0f49d7ebdd75b64ba0a68f937d888f4e0d6db" +checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" dependencies = [ "unicode-ident", ] @@ -951,7 +955,7 @@ dependencies = [ "prost", "prost-types", "regex", - "syn 2.0.46", + "syn 2.0.94", "tempfile", "which", ] @@ -966,7 +970,7 @@ dependencies = [ "itertools 0.12.1", "proc-macro2", "quote", - "syn 2.0.46", + "syn 2.0.94", ] [[package]] @@ -990,6 +994,18 @@ dependencies = [ "reborrow", ] +[[package]] +name = "pulp" +version = "0.18.9" +source = "git+https://github.com/zefr0x/pulp.git?branch=implserde#69980e2dc564055aedb1a6263e011fc57dd4aac5" +dependencies = [ + "bytemuck", + "libm", + "num-complex", + "reborrow", + "serde", +] + [[package]] name = "quick-error" version = "1.2.3" @@ -1014,6 +1030,7 @@ dependencies = [ "libc", "rand_chacha", "rand_core", + "serde", ] [[package]] @@ -1024,6 +1041,7 @@ checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ "ppv-lite86", "rand_core", + "serde", ] [[package]] @@ -1033,6 +1051,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ "getrandom", + "serde", ] [[package]] @@ -1162,22 +1181,22 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "serde" -version = "1.0.188" +version = "1.0.217" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e" +checksum = "02fc4265df13d6fa1d00ecff087228cc0a2b5f3c0e87e258d8b94a156e984c70" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.188" +version = "1.0.217" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" +checksum = "5a9bf7cf98d04a2b28aead066b7496853d4779c9cc183c440dbac457641e19a0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.46", + "syn 2.0.94", ] [[package]] @@ -1233,9 +1252,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.46" +version = "2.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89456b690ff72fddcecf231caedbe615c59480c93358a93dfae7fc29e3ebbf0e" +checksum = "987bc0be1cdea8b10216bd06e2ca407d40b9543468fafd3ddfb02f36e77f71f3" dependencies = [ "proc-macro2", "quote", @@ -1272,7 +1291,7 @@ checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.46", + "syn 2.0.94", ] [[package]] @@ -1367,7 +1386,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.46", + "syn 2.0.94", "wasm-bindgen-shared", ] @@ -1389,7 +1408,7 @@ checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.46", + "syn 2.0.94", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -1599,5 +1618,5 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.46", + "syn 2.0.94", ] diff --git a/Cargo.toml b/Cargo.toml index 31dfca36..f5c367bd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,6 +33,7 @@ prost = "^0.12.4" prost-build = "^0.12.3" rand = "^0.8.5" rand_chacha = "^0.3.1" +serde = "1.0.217" sha2 = "^0.10.8" thiserror = "^1.0.58" zeroize = "^1.8.0" diff --git a/crates/fhe-math/Cargo.toml b/crates/fhe-math/Cargo.toml index b844dab5..a496515f 100644 --- a/crates/fhe-math/Cargo.toml +++ b/crates/fhe-math/Cargo.toml @@ -13,6 +13,7 @@ rust-version.workspace = true bench = false # Disable default bench (we use criterion) [features] +serde = ["dep:serde", "ndarray/serde", "num-bigint/serde", "rand/serde1", "rand_chacha/serde"] concrete-ntt = [] concrete-ntt-nightly = ["concrete-ntt/nightly"] @@ -30,12 +31,13 @@ num-bigint.workspace = true num-bigint-dig.workspace = true num-traits.workspace = true prost.workspace = true -pulp = "^0.18.9" +pulp = { git = "https://github.com/zefr0x/pulp.git", branch = "implserde", features = ["serde"] } rand.workspace = true rand_chacha.workspace = true thiserror.workspace = true zeroize.workspace = true zeroize_derive.workspace = true +serde = { workspace = true, optional = true } sha2.workspace = true [build-dependencies] diff --git a/crates/fhe-math/src/ntt/native.rs b/crates/fhe-math/src/ntt/native.rs index b34a91b9..cf40b5a2 100644 --- a/crates/fhe-math/src/ntt/native.rs +++ b/crates/fhe-math/src/ntt/native.rs @@ -5,6 +5,7 @@ use rand_chacha::ChaCha8Rng; use std::iter::successors; /// Number-Theoretic Transform operator. +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Debug, Clone, PartialEq, Eq)] pub struct NttOperator { p: Modulus, diff --git a/crates/fhe-math/src/rns/mod.rs b/crates/fhe-math/src/rns/mod.rs index eec5bfef..d8787ba8 100644 --- a/crates/fhe-math/src/rns/mod.rs +++ b/crates/fhe-math/src/rns/mod.rs @@ -15,6 +15,7 @@ mod scaler; pub use scaler::{RnsScaler, ScalingFactor}; /// Context for a Residue Number System. +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Default, Clone, PartialEq, Eq)] pub struct RnsContext { moduli_u64: Vec, diff --git a/crates/fhe-math/src/rns/scaler.rs b/crates/fhe-math/src/rns/scaler.rs index b3051b1b..04091fd7 100644 --- a/crates/fhe-math/src/rns/scaler.rs +++ b/crates/fhe-math/src/rns/scaler.rs @@ -11,6 +11,7 @@ use num_traits::{One, ToPrimitive, Zero}; use std::{cmp::min, sync::Arc}; /// Scaling factor when performing a RNS scaling. +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Default, Debug, Clone, PartialEq, Eq)] pub struct ScalingFactor { numerator: BigUint, @@ -41,6 +42,7 @@ impl ScalingFactor { /// Scaler for a RNS context. /// This is a helper struct to perform RNS scaling. +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Default, Debug, Clone, PartialEq, Eq)] pub struct RnsScaler { from: Arc, diff --git a/crates/fhe-math/src/rq/context.rs b/crates/fhe-math/src/rq/context.rs index edd80fd3..afd13b16 100644 --- a/crates/fhe-math/src/rq/context.rs +++ b/crates/fhe-math/src/rq/context.rs @@ -5,6 +5,7 @@ use std::{fmt::Debug, sync::Arc}; use crate::{ntt::NttOperator, rns::RnsContext, zq::Modulus, Error, Result}; /// Struct that holds the context associated with elements in rq. +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Default, Clone, PartialEq, Eq)] pub struct Context { pub(crate) moduli: Box<[u64]>, diff --git a/crates/fhe-math/src/rq/mod.rs b/crates/fhe-math/src/rq/mod.rs index 14fa3819..9079fd4c 100644 --- a/crates/fhe-math/src/rq/mod.rs +++ b/crates/fhe-math/src/rq/mod.rs @@ -25,6 +25,7 @@ use std::sync::Arc; use zeroize::{Zeroize, Zeroizing}; /// Possible representations of the underlying polynomial. +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Default, Debug, Clone, PartialEq, Eq)] pub enum Representation { /// This is the list of coefficients ci, such that the polynomial is c0 + c1 @@ -39,6 +40,7 @@ pub enum Representation { } /// An exponent for a substitution. +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Debug, PartialEq, Eq)] pub struct SubstitutionExponent { /// The value of the exponent. @@ -76,6 +78,7 @@ impl SubstitutionExponent { } /// Struct that holds a polynomial for a specific context. +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Default, Debug, Clone, PartialEq, Eq)] pub struct Poly { ctx: Arc, diff --git a/crates/fhe-math/src/rq/scaler.rs b/crates/fhe-math/src/rq/scaler.rs index b1c8a3d8..c1f886c5 100644 --- a/crates/fhe-math/src/rq/scaler.rs +++ b/crates/fhe-math/src/rq/scaler.rs @@ -12,6 +12,7 @@ use ndarray::{s, Array2, Axis}; use std::sync::Arc; /// Context extender. +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Default, Debug, Clone, PartialEq, Eq)] pub struct Scaler { from: Arc, diff --git a/crates/fhe-math/src/zq/mod.rs b/crates/fhe-math/src/zq/mod.rs index 07e438a2..37e87aad 100644 --- a/crates/fhe-math/src/zq/mod.rs +++ b/crates/fhe-math/src/zq/mod.rs @@ -25,6 +25,7 @@ const fn const_time_cond_select(on_true: u64, on_false: u64, cond: bool) -> u64 /// Structure encapsulating an integer modulus up to 62 bits. #[derive(Derivative)] #[derivative(PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Debug, Clone)] pub struct Modulus { pub(crate) p: u64, diff --git a/crates/fhe/Cargo.toml b/crates/fhe/Cargo.toml index c647965d..450f7705 100644 --- a/crates/fhe/Cargo.toml +++ b/crates/fhe/Cargo.toml @@ -13,6 +13,7 @@ rust-version.workspace = true bench = false # Disable default bench (we use criterion) [features] +serde = ["dep:serde", "ndarray/serde", "num-bigint/serde", "rand/serde1", "rand_chacha/serde", "fhe-math/serde"] concrete-ntt = ["fhe-math/concrete-ntt"] concrete-ntt-nightly = ["fhe-math/concrete-ntt-nightly"] @@ -28,6 +29,7 @@ num-traits.workspace = true prost.workspace = true rand.workspace = true rand_chacha.workspace = true +serde = { workspace = true, optional = true } zeroize.workspace = true zeroize_derive.workspace = true ndarray.workspace = true diff --git a/crates/fhe/src/bfv/ciphertext.rs b/crates/fhe/src/bfv/ciphertext.rs index 354b11b1..01f55bdd 100644 --- a/crates/fhe/src/bfv/ciphertext.rs +++ b/crates/fhe/src/bfv/ciphertext.rs @@ -14,6 +14,7 @@ use std::ops::{Deref, DerefMut}; use std::sync::Arc; /// A ciphertext encrypting a plaintext. +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Debug, Clone, PartialEq, Eq)] pub struct Ciphertext { /// The parameters of the underlying BFV encryption scheme. diff --git a/crates/fhe/src/bfv/encoding.rs b/crates/fhe/src/bfv/encoding.rs index bafd3384..17b756a6 100644 --- a/crates/fhe/src/bfv/encoding.rs +++ b/crates/fhe/src/bfv/encoding.rs @@ -4,6 +4,7 @@ use std::fmt::Display; use fhe_traits::FhePlaintextEncoding; +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Debug, Clone, Eq, PartialEq)] pub(crate) enum EncodingEnum { Poly, @@ -17,6 +18,7 @@ impl Display for EncodingEnum { } /// An encoding for the plaintext. +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Debug, Clone, Eq, PartialEq)] pub struct Encoding { pub(crate) encoding: EncodingEnum, diff --git a/crates/fhe/src/bfv/keys/evaluation_key.rs b/crates/fhe/src/bfv/keys/evaluation_key.rs index 2426dd27..0e5bcee7 100644 --- a/crates/fhe/src/bfv/keys/evaluation_key.rs +++ b/crates/fhe/src/bfv/keys/evaluation_key.rs @@ -19,6 +19,7 @@ use zeroize::{Zeroize, ZeroizeOnDrop}; /// - row rotation /// - oblivious expansion /// - inner sum +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Debug, PartialEq, Eq)] pub struct EvaluationKey { par: Arc, diff --git a/crates/fhe/src/bfv/keys/galois_key.rs b/crates/fhe/src/bfv/keys/galois_key.rs index 42b0e8c5..47488955 100644 --- a/crates/fhe/src/bfv/keys/galois_key.rs +++ b/crates/fhe/src/bfv/keys/galois_key.rs @@ -15,6 +15,7 @@ use zeroize::Zeroizing; /// Galois key for the BFV encryption scheme. /// A Galois key is a special type of key switching key, /// which switch from `s(x^i)` to `s(x)` where `s(x)` is the secret key. +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Debug, PartialEq, Eq)] pub struct GaloisKey { pub(crate) element: SubstitutionExponent, diff --git a/crates/fhe/src/bfv/keys/key_switching_key.rs b/crates/fhe/src/bfv/keys/key_switching_key.rs index 0e663cc6..dbbb0b9c 100644 --- a/crates/fhe/src/bfv/keys/key_switching_key.rs +++ b/crates/fhe/src/bfv/keys/key_switching_key.rs @@ -18,6 +18,7 @@ use std::sync::Arc; use zeroize::Zeroizing; /// Key switching key for the BFV encryption scheme. +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Debug, PartialEq, Eq, Clone)] pub struct KeySwitchingKey { /// The parameters of the underlying BFV encryption scheme. diff --git a/crates/fhe/src/bfv/keys/public_key.rs b/crates/fhe/src/bfv/keys/public_key.rs index 4f2d8c8f..405600ea 100644 --- a/crates/fhe/src/bfv/keys/public_key.rs +++ b/crates/fhe/src/bfv/keys/public_key.rs @@ -14,6 +14,7 @@ use zeroize::Zeroizing; use super::SecretKey; /// Public key for the BFV encryption scheme. +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Debug, PartialEq, Eq, Clone)] pub struct PublicKey { pub(crate) par: Arc, diff --git a/crates/fhe/src/bfv/keys/relinearization_key.rs b/crates/fhe/src/bfv/keys/relinearization_key.rs index 7ac26a6e..d0b879ae 100644 --- a/crates/fhe/src/bfv/keys/relinearization_key.rs +++ b/crates/fhe/src/bfv/keys/relinearization_key.rs @@ -19,6 +19,7 @@ use zeroize::Zeroizing; /// Relinearization key for the BFV encryption scheme. /// A relinearization key is a special type of key switching key, /// which switch from `s^2` to `s` where `s` is the secret key. +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Debug, PartialEq, Eq, Clone)] pub struct RelinearizationKey { pub(crate) ksk: KeySwitchingKey, diff --git a/crates/fhe/src/bfv/keys/secret_key.rs b/crates/fhe/src/bfv/keys/secret_key.rs index a1ac9b87..cf30e090 100644 --- a/crates/fhe/src/bfv/keys/secret_key.rs +++ b/crates/fhe/src/bfv/keys/secret_key.rs @@ -17,6 +17,7 @@ use zeroize::Zeroizing; use zeroize_derive::{Zeroize, ZeroizeOnDrop}; /// Secret key for the BFV encryption scheme. +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Debug, PartialEq, Eq, Clone, Zeroize, ZeroizeOnDrop)] pub struct SecretKey { #[zeroize(skip)] diff --git a/crates/fhe/src/bfv/ops/mul.rs b/crates/fhe/src/bfv/ops/mul.rs index 28184fb0..3008bbec 100644 --- a/crates/fhe/src/bfv/ops/mul.rs +++ b/crates/fhe/src/bfv/ops/mul.rs @@ -19,6 +19,7 @@ use crate::{ /// - The basis at which the multiplication will occur; /// - The scaling factor after multiplication; /// - Whether relinearization should be used. +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Debug, Clone, PartialEq, Eq)] pub struct Multiplicator { par: Arc, diff --git a/crates/fhe/src/bfv/parameters.rs b/crates/fhe/src/bfv/parameters.rs index 34b24cf1..779bdbdb 100644 --- a/crates/fhe/src/bfv/parameters.rs +++ b/crates/fhe/src/bfv/parameters.rs @@ -18,6 +18,7 @@ use std::fmt::Debug; use std::sync::Arc; /// Parameters for the BFV encryption scheme. +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(PartialEq, Eq)] pub struct BfvParameters { /// Number of coefficients in a polynomial. @@ -456,6 +457,7 @@ impl Deserialize for BfvParameters { } /// Multiplication parameters +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Debug, PartialEq, Eq, Default)] pub(crate) struct MultiplicationParameters { pub(crate) extender: Scaler, diff --git a/crates/fhe/src/bfv/plaintext.rs b/crates/fhe/src/bfv/plaintext.rs index 52f8cc5c..b271944d 100644 --- a/crates/fhe/src/bfv/plaintext.rs +++ b/crates/fhe/src/bfv/plaintext.rs @@ -12,6 +12,7 @@ use zeroize_derive::{Zeroize, ZeroizeOnDrop}; use super::encoding::EncodingEnum; /// A plaintext object, that encodes a vector according to a specific encoding. +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Debug, Clone, Eq, Zeroize, ZeroizeOnDrop)] pub struct Plaintext { /// The parameters of the underlying BFV encryption scheme. diff --git a/crates/fhe/src/bfv/plaintext_vec.rs b/crates/fhe/src/bfv/plaintext_vec.rs index 74d53fa6..5f0b45ca 100644 --- a/crates/fhe/src/bfv/plaintext_vec.rs +++ b/crates/fhe/src/bfv/plaintext_vec.rs @@ -13,6 +13,7 @@ use super::encoding::EncodingEnum; /// A wrapper around a vector of plaintext which implements the [`FhePlaintext`] /// trait, and therefore can be encoded to / decoded from. +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Zeroize, ZeroizeOnDrop)] pub struct PlaintextVec(Vec); diff --git a/crates/fhe/src/bfv/rgsw_ciphertext.rs b/crates/fhe/src/bfv/rgsw_ciphertext.rs index b67d71a6..a447066c 100644 --- a/crates/fhe/src/bfv/rgsw_ciphertext.rs +++ b/crates/fhe/src/bfv/rgsw_ciphertext.rs @@ -17,6 +17,7 @@ use super::{ }; /// A RGSW ciphertext encrypting a plaintext. +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Debug, PartialEq, Eq)] pub struct RGSWCiphertext { ksk0: KeySwitchingKey, diff --git a/crates/fhe/src/mbfv/crp.rs b/crates/fhe/src/mbfv/crp.rs index 05a3e349..0917ab79 100644 --- a/crates/fhe/src/mbfv/crp.rs +++ b/crates/fhe/src/mbfv/crp.rs @@ -7,6 +7,7 @@ use rand::{CryptoRng, RngCore}; /// A polynomial sampled from a random _common reference string_. // TODO CRS->CRP implementation. For now just a random polynomial. +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Debug, PartialEq, Eq, Clone)] pub struct CommonRandomPoly { pub(crate) poly: Poly, diff --git a/crates/fhe/src/mbfv/public_key_gen.rs b/crates/fhe/src/mbfv/public_key_gen.rs index 618338ee..84ebfb68 100644 --- a/crates/fhe/src/mbfv/public_key_gen.rs +++ b/crates/fhe/src/mbfv/public_key_gen.rs @@ -12,6 +12,7 @@ use super::{Aggregate, CommonRandomPoly}; /// A party's share in public key generation protocol. /// /// Each party uses the `PublicKeyShare` to generate their share of the public key and participate in the in the "Protocol 1: EncKeyGen", as detailed in [Multiparty BFV](https://eprint.iacr.org/2020/304.pdf) (p6). Use the [`Aggregate`] impl to combine the shares into a [`PublicKey`]. +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Debug, PartialEq, Eq, Clone)] pub struct PublicKeyShare { pub(crate) par: Arc<BfvParameters>, diff --git a/crates/fhe/src/mbfv/public_key_switch.rs b/crates/fhe/src/mbfv/public_key_switch.rs index 1da2d895..fae873a5 100644 --- a/crates/fhe/src/mbfv/public_key_switch.rs +++ b/crates/fhe/src/mbfv/public_key_switch.rs @@ -15,6 +15,7 @@ use super::Aggregate; /// /// Each party uses the `PublicKeySwitchShare` to generate their share of the /// new ciphertext and participate in the "Protocol 4: PubKeySwitch" protocol detailed in as detailed in [Multiparty BFV](https://eprint.iacr.org/2020/304.pdf) (p7). Use the [`Aggregate`] impl to combine the shares into a [`Ciphertext`]. +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct PublicKeySwitchShare { pub(crate) par: Arc<BfvParameters>, /// The first component of the input ciphertext diff --git a/crates/fhe/src/mbfv/relin_key_gen.rs b/crates/fhe/src/mbfv/relin_key_gen.rs index 004a2ced..fe0fa878 100644 --- a/crates/fhe/src/mbfv/relin_key_gen.rs +++ b/crates/fhe/src/mbfv/relin_key_gen.rs @@ -15,6 +15,7 @@ use super::{Aggregate, CommonRandomPoly}; /// A party's share in the relinearization key generation protocol. /// Use the [`RelinKeyGenerator`] to create these shares. +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Debug, PartialEq, Eq, Clone)] pub struct RelinKeyShare<R: Round = R1> { pub(crate) par: Arc<BfvParameters>, diff --git a/crates/fhe/src/mbfv/round.rs b/crates/fhe/src/mbfv/round.rs index 10a1a920..5ff389f2 100644 --- a/crates/fhe/src/mbfv/round.rs +++ b/crates/fhe/src/mbfv/round.rs @@ -4,12 +4,15 @@ pub trait Round: sealed::Sealed {} /// Marks the shares produced in round 1 +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Debug, PartialEq, Eq, Clone)] pub struct R1; /// Marks the aggregated shares from round 1 +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Debug, PartialEq, Eq, Clone)] pub struct R1Aggregated; /// Marks the shares produced in round 2 +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Debug, PartialEq, Eq, Clone)] pub struct R2; diff --git a/crates/fhe/src/mbfv/secret_key_switch.rs b/crates/fhe/src/mbfv/secret_key_switch.rs index 68cb8648..6317312b 100644 --- a/crates/fhe/src/mbfv/secret_key_switch.rs +++ b/crates/fhe/src/mbfv/secret_key_switch.rs @@ -22,6 +22,8 @@ use super::Aggregate; /// /// Note: this protocol assumes the output key is split into the same number of /// parties as the input key, and is likely only useful for niche scenarios. +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[derive(Debug, PartialEq, Eq, Clone)] pub struct SecretKeySwitchShare { pub(crate) par: Arc<BfvParameters>, /// The original input ciphertext @@ -113,6 +115,8 @@ impl Aggregate<SecretKeySwitchShare> for Ciphertext { /// plaintext output. Note that this is a special case of the "Protocol 3: /// KeySwitch" protocol detailed in [Multiparty BFV](https://eprint.iacr.org/2020/304.pdf) (p7), using an output key of zero. Use the /// [`Aggregate`] impl to combine the shares into a [`Plaintext`]. +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[derive(Debug, PartialEq, Eq, Clone)] pub struct DecryptionShare { pub(crate) sks_share: SecretKeySwitchShare, } diff --git a/crates/fhe/src/proto/bfv.rs b/crates/fhe/src/proto/bfv.rs index 99d2aa48..3d8d4ead 100644 --- a/crates/fhe/src/proto/bfv.rs +++ b/crates/fhe/src/proto/bfv.rs @@ -1,6 +1,7 @@ #![allow(missing_docs)] #[allow(clippy::derive_partial_eq_without_eq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, PartialEq, ::prost::Message)] pub struct Ciphertext { #[prost(bytes = "vec", repeated, tag = "1")] @@ -11,6 +12,7 @@ pub struct Ciphertext { pub level: u32, } #[allow(clippy::derive_partial_eq_without_eq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, PartialEq, ::prost::Message)] pub struct RgswCiphertext { #[prost(message, optional, tag = "1")] @@ -19,6 +21,7 @@ pub struct RgswCiphertext { pub ksk1: ::core::option::Option<KeySwitchingKey>, } #[allow(clippy::derive_partial_eq_without_eq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, PartialEq, ::prost::Message)] pub struct KeySwitchingKey { #[prost(bytes = "vec", repeated, tag = "1")] @@ -35,12 +38,14 @@ pub struct KeySwitchingKey { pub log_base: u32, } #[allow(clippy::derive_partial_eq_without_eq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, PartialEq, ::prost::Message)] pub struct RelinearizationKey { #[prost(message, optional, tag = "1")] pub ksk: ::core::option::Option<KeySwitchingKey>, } #[allow(clippy::derive_partial_eq_without_eq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, PartialEq, ::prost::Message)] pub struct GaloisKey { #[prost(message, optional, tag = "1")] @@ -49,6 +54,7 @@ pub struct GaloisKey { pub exponent: u32, } #[allow(clippy::derive_partial_eq_without_eq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, PartialEq, ::prost::Message)] pub struct EvaluationKey { #[prost(message, repeated, tag = "2")] @@ -59,6 +65,7 @@ pub struct EvaluationKey { pub evaluation_key_level: u32, } #[allow(clippy::derive_partial_eq_without_eq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, PartialEq, ::prost::Message)] pub struct Parameters { #[prost(uint32, tag = "1")] @@ -71,6 +78,7 @@ pub struct Parameters { pub variance: u32, } #[allow(clippy::derive_partial_eq_without_eq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, PartialEq, ::prost::Message)] pub struct PublicKey { #[prost(message, optional, tag = "1")]