From 8f345c74fdfc33b6f1bce36c619c14fd4136d050 Mon Sep 17 00:00:00 2001 From: Hernando Castano Date: Tue, 30 Jul 2024 14:59:23 -0700 Subject: [PATCH 1/7] Bump `bincode` to `2.0.0-rc.3` --- synedrion/Cargo.toml | 2 +- synedrion/src/sessions/type_erased.rs | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/synedrion/Cargo.toml b/synedrion/Cargo.toml index bf1d67a4..553b3f31 100644 --- a/synedrion/Cargo.toml +++ b/synedrion/Cargo.toml @@ -29,7 +29,7 @@ crypto-bigint = { version = "0.5.3", default-features = false, features = ["serd crypto-primes = { version = "0.5", default-features = false } serde = { version = "1", default-features = false, features = ["derive"] } -bincode = "1" +bincode = { version = "2.0.0-rc.3", default-features = false, features = ["serde", "alloc"] } displaydoc = { version = "0.2", default-features = false} [dev-dependencies] diff --git a/synedrion/src/sessions/type_erased.rs b/synedrion/src/sessions/type_erased.rs index cfdb3c36..0b1efe7f 100644 --- a/synedrion/src/sessions/type_erased.rs +++ b/synedrion/src/sessions/type_erased.rs @@ -18,7 +18,7 @@ use crate::rounds::{ }; pub(crate) fn serialize_message(message: &impl Serialize) -> Result, LocalError> { - bincode::serialize(message) + bincode::serde::encode_to_vec(message, bincode::config::legacy()) .map(|serialized| serialized.into_boxed_slice()) .map_err(|err| LocalError(format!("Failed to serialize: {err:?}"))) } @@ -26,7 +26,8 @@ pub(crate) fn serialize_message(message: &impl Serialize) -> Result, L pub(crate) fn deserialize_message Deserialize<'de>>( message_bytes: &[u8], ) -> Result { - bincode::deserialize(message_bytes).map_err(|err| err.to_string()) + bincode::serde::decode_borrowed_from_slice(message_bytes, bincode::config::legacy()) + .map_err(|err| err.to_string()) } pub(crate) enum FinalizeOutcome { From c4fe49e5a8471aa91e09357c101a6140ef29ab7d Mon Sep 17 00:00:00 2001 From: Hernando Castano Date: Tue, 30 Jul 2024 15:24:10 -0700 Subject: [PATCH 2/7] Bump `secrecy` to `0.9.0-pre.0` --- synedrion/Cargo.toml | 2 +- synedrion/src/cggmp21/entities.rs | 27 ++++++++++--------- synedrion/src/cggmp21/protocols/aux_gen.rs | 5 ++-- synedrion/src/cggmp21/protocols/key_init.rs | 5 ++-- .../src/cggmp21/protocols/key_refresh.rs | 7 ++--- synedrion/src/cggmp21/protocols/presigning.rs | 7 ++--- synedrion/src/curve/arithmetic.rs | 4 +-- synedrion/src/paillier/keys.rs | 16 +++++------ synedrion/src/www02/entities.rs | 22 +++++++-------- synedrion/src/www02/key_resharing.rs | 5 ++-- 10 files changed, 53 insertions(+), 47 deletions(-) diff --git a/synedrion/Cargo.toml b/synedrion/Cargo.toml index 553b3f31..ed7997a8 100644 --- a/synedrion/Cargo.toml +++ b/synedrion/Cargo.toml @@ -19,7 +19,7 @@ digest = { version = "0.10", default-features = false, features = ["alloc"]} hex = { version = "0.4", default-features = false, features = ["alloc"] } base64 = { version = "0.21", default-features = false, features = ["alloc"] } hashing-serializer = { version = "0.1", default-features = false } -secrecy = { version = "0.8", default-features = false, features = ["alloc", "serde"] } +secrecy = { version = "0.9.0-pre.0", default-features = false, features = ["serde"] } zeroize = { version = "1.8", default-features = false, features = ["alloc", "zeroize_derive"] } bip32 = { version = "0.5.2", default-features = false, features = ["alloc", "secp256k1"] } diff --git a/synedrion/src/cggmp21/entities.rs b/synedrion/src/cggmp21/entities.rs index 97b79025..edcabd63 100644 --- a/synedrion/src/cggmp21/entities.rs +++ b/synedrion/src/cggmp21/entities.rs @@ -1,11 +1,12 @@ use alloc::collections::{BTreeMap, BTreeSet}; +use alloc::boxed::Box; use alloc::vec::Vec; use core::fmt::Debug; use core::marker::PhantomData; use k256::ecdsa::VerifyingKey; use rand_core::CryptoRngCore; -use secrecy::{ExposeSecret, Secret}; +use secrecy::{ExposeSecret, SecretBox}; use serde::{Deserialize, Serialize}; use crate::cggmp21::SchemeParams; @@ -24,7 +25,7 @@ use crate::paillier::RandomizerMod; pub struct KeyShare { pub(crate) owner: I, /// Secret key share of this node. - pub(crate) secret_share: Secret, // `x_i` + pub(crate) secret_share: SecretBox, // `x_i` pub(crate) public_shares: BTreeMap, // `X_j` // TODO (#27): this won't be needed when Scalar/Point are a part of `P` pub(crate) phantom: PhantomData

, @@ -43,7 +44,7 @@ pub struct AuxInfo { #[serde(bound(deserialize = "SecretKeyPaillier: for <'x> Deserialize<'x>"))] pub(crate) struct SecretAuxInfo { pub(crate) paillier_sk: SecretKeyPaillier, - pub(crate) el_gamal_sk: Secret, // `y_i` + pub(crate) el_gamal_sk: SecretBox, // `y_i` } #[derive(Debug, Clone, Serialize, Deserialize)] @@ -67,7 +68,7 @@ pub(crate) struct AuxInfoPrecomputed { pub(crate) struct SecretAuxInfoPrecomputed { pub(crate) paillier_sk: SecretKeyPaillierPrecomputed, #[allow(dead_code)] // TODO (#36): this will be needed for the 6-round presigning protocol. - pub(crate) el_gamal_sk: Secret, // `y_i` + pub(crate) el_gamal_sk: SecretBox, // `y_i` } #[derive(Clone)] @@ -83,7 +84,7 @@ pub(crate) struct PublicAuxInfoPrecomputed { pub struct KeyShareChange { pub(crate) owner: I, /// The value to be added to the secret share. - pub(crate) secret_share_change: Secret, // `x_i^* - x_i == \sum_{j} x_j^i` + pub(crate) secret_share_change: SecretBox, // `x_i^* - x_i == \sum_{j} x_j^i` /// The values to be added to the public shares of remote nodes. pub(crate) public_share_changes: BTreeMap, // `X_k^* - X_k == \sum_j X_j^k`, for all nodes // TODO (#27): this won't be needed when Scalar/Point are a part of `P` @@ -95,9 +96,9 @@ pub struct KeyShareChange { pub struct PresigningData { pub(crate) nonce: Scalar, // x-coordinate of $R$ /// An additive share of the ephemeral scalar. - pub(crate) ephemeral_scalar_share: Secret, // $k_i$ + pub(crate) ephemeral_scalar_share: SecretBox, // $k_i$ /// An additive share of `k * x` where `x` is the secret key. - pub(crate) product_share: Secret, + pub(crate) product_share: SecretBox, // Values generated during presigning, // kept in case we need to generate a proof of correctness. @@ -129,8 +130,8 @@ impl KeyShare { // TODO (#68): check that party_idx is the same for both, and the number of parties is the same assert_eq!(self.owner, change.owner); - let secret_share = Secret::new( - self.secret_share.expose_secret() + change.secret_share_change.expose_secret(), + let secret_share = SecretBox::new( + Box::new(self.secret_share.expose_secret() + change.secret_share_change.expose_secret()), ); let public_shares = self .public_shares @@ -172,7 +173,7 @@ impl KeyShare { id.clone(), KeyShare { owner: id.clone(), - secret_share: Secret::new(secret_share), + secret_share: SecretBox::new(Box::new(secret_share)), public_shares: public_shares.clone(), phantom: PhantomData, }, @@ -215,7 +216,7 @@ impl AuxInfo { let secret_aux = (0..ids.len()) .map(|_| SecretAuxInfo { paillier_sk: SecretKeyPaillier::::random(rng), - el_gamal_sk: Secret::new(Scalar::random(rng)), + el_gamal_sk: SecretBox::new(Box::new(Scalar::random(rng))), }) .collect::>(); @@ -405,8 +406,8 @@ impl PresigningData { id_i.clone(), PresigningData { nonce, - ephemeral_scalar_share: Secret::new(k_i), - product_share: Secret::new(P::scalar_from_signed(&product_share_nonreduced)), + ephemeral_scalar_share: SecretBox::new(Box::new(k_i)), + product_share: SecretBox::new(Box::new(P::scalar_from_signed(&product_share_nonreduced))), product_share_nonreduced, cap_k: all_cap_k[&id_i].clone(), values, diff --git a/synedrion/src/cggmp21/protocols/aux_gen.rs b/synedrion/src/cggmp21/protocols/aux_gen.rs index 0dee7573..288918f2 100644 --- a/synedrion/src/cggmp21/protocols/aux_gen.rs +++ b/synedrion/src/cggmp21/protocols/aux_gen.rs @@ -3,11 +3,12 @@ use alloc::collections::{BTreeMap, BTreeSet}; use alloc::string::String; +use alloc::boxed::Box; use core::fmt::Debug; use core::marker::PhantomData; use rand_core::CryptoRngCore; -use secrecy::Secret; +use secrecy::SecretBox; use serde::{Deserialize, Serialize}; use super::super::{ @@ -526,7 +527,7 @@ impl FinalizableToResult let secret_aux = SecretAuxInfo { paillier_sk: self.context.paillier_sk.to_minimal(), - el_gamal_sk: Secret::new(self.context.y), + el_gamal_sk: SecretBox::new(Box::new(self.context.y)), }; let aux_info = AuxInfo { diff --git a/synedrion/src/cggmp21/protocols/key_init.rs b/synedrion/src/cggmp21/protocols/key_init.rs index 61bd443a..a463a037 100644 --- a/synedrion/src/cggmp21/protocols/key_init.rs +++ b/synedrion/src/cggmp21/protocols/key_init.rs @@ -3,11 +3,12 @@ //! auxiliary parameters need to be generated as well (during the KeyRefresh protocol). use alloc::collections::{BTreeMap, BTreeSet}; +use alloc::boxed::Box; use core::fmt::Debug; use core::marker::PhantomData; use rand_core::CryptoRngCore; -use secrecy::Secret; +use secrecy::SecretBox; use serde::{Deserialize, Serialize}; use super::super::{ @@ -367,7 +368,7 @@ impl FinalizableToResult public_shares.insert(my_id.clone(), self.context.public_data.cap_x); Ok(KeyShare { owner: my_id, - secret_share: Secret::new(self.context.x), + secret_share: SecretBox::new(Box::new(self.context.x)), public_shares, phantom: PhantomData, }) diff --git a/synedrion/src/cggmp21/protocols/key_refresh.rs b/synedrion/src/cggmp21/protocols/key_refresh.rs index 56c662e1..3a14ddf5 100644 --- a/synedrion/src/cggmp21/protocols/key_refresh.rs +++ b/synedrion/src/cggmp21/protocols/key_refresh.rs @@ -3,13 +3,14 @@ //! for ZK proofs (e.g. Paillier keys). use alloc::collections::{BTreeMap, BTreeSet}; +use alloc::boxed::Box; use alloc::string::String; use alloc::vec::Vec; use core::fmt::Debug; use core::marker::PhantomData; use rand_core::CryptoRngCore; -use secrecy::Secret; +use secrecy::SecretBox; use serde::{Deserialize, Serialize}; use super::super::{ @@ -662,12 +663,12 @@ impl FinalizableToResult let secret_aux = SecretAuxInfo { paillier_sk: self.context.paillier_sk.to_minimal(), - el_gamal_sk: Secret::new(self.context.y), + el_gamal_sk: SecretBox::new(Box::new(self.context.y)), }; let key_share_change = KeyShareChange { owner: my_id.clone(), - secret_share_change: Secret::new(x_star), + secret_share_change: SecretBox::new(Box::new(x_star)), public_share_changes: cap_x_star, phantom: PhantomData, }; diff --git a/synedrion/src/cggmp21/protocols/presigning.rs b/synedrion/src/cggmp21/protocols/presigning.rs index 007f2ac0..ba09c97f 100644 --- a/synedrion/src/cggmp21/protocols/presigning.rs +++ b/synedrion/src/cggmp21/protocols/presigning.rs @@ -1,13 +1,14 @@ //! Presigning protocol, in the paper ECDSA Pre-Signing (Fig. 7). use alloc::collections::{BTreeMap, BTreeSet}; +use alloc::boxed::Box; use alloc::string::String; use alloc::vec::Vec; use core::fmt::Debug; use core::marker::PhantomData; use rand_core::CryptoRngCore; -use secrecy::{ExposeSecret, Secret}; +use secrecy::{ExposeSecret, SecretBox}; use serde::{Deserialize, Serialize}; use super::super::{ @@ -733,8 +734,8 @@ impl FinalizableToResult return Ok(PresigningData { nonce, - ephemeral_scalar_share: Secret::new(self.context.k), - product_share: Secret::new(P::scalar_from_signed(&self.chi)), + ephemeral_scalar_share: SecretBox::new(Box::new(self.context.k)), + product_share: SecretBox::new(Box::new(P::scalar_from_signed(&self.chi))), product_share_nonreduced: self.chi, cap_k: self.all_cap_k[&my_id].clone(), values, diff --git a/synedrion/src/curve/arithmetic.rs b/synedrion/src/curve/arithmetic.rs index cd18eb3a..b9031b65 100644 --- a/synedrion/src/curve/arithmetic.rs +++ b/synedrion/src/curve/arithmetic.rs @@ -24,7 +24,7 @@ use k256::{ Secp256k1, }; use rand_core::CryptoRngCore; -use secrecy::{CloneableSecret, DebugSecret, SerializableSecret}; +use secrecy::{CloneableSecret, SecretBox, SerializableSecret}; use serde::{Deserialize, Deserializer, Serialize, Serializer}; use zeroize::DefaultIsZeroes; @@ -164,7 +164,7 @@ impl<'de> Deserialize<'de> for Scalar { impl DefaultIsZeroes for Scalar {} -impl DebugSecret for Scalar {} +// impl DebugSecret for Scalar {} impl CloneableSecret for Scalar {} diff --git a/synedrion/src/paillier/keys.rs b/synedrion/src/paillier/keys.rs index aeb21285..9189084c 100644 --- a/synedrion/src/paillier/keys.rs +++ b/synedrion/src/paillier/keys.rs @@ -1,7 +1,7 @@ use core::fmt::{self, Debug}; use rand_core::CryptoRngCore; -use secrecy::DebugSecret; +// use secrecy::DebugSecret; use serde::{Deserialize, Serialize}; use zeroize::ZeroizeOnDrop; @@ -12,19 +12,19 @@ use crate::uint::{ RandomPrimeWithRng, Retrieve, Signed, UintLike, UintModLike, }; -#[derive(Clone, Serialize, Deserialize, ZeroizeOnDrop)] +#[derive(Clone, Serialize, Deserialize, ZeroizeOnDrop, Debug)] pub(crate) struct SecretKeyPaillier { p: P::HalfUint, q: P::HalfUint, } -impl DebugSecret for SecretKeyPaillier

{} +// impl DebugSecret for SecretKeyPaillier

{} -impl Debug for SecretKeyPaillier

{ - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { - Self::debug_secret(f) - } -} +// impl Debug for SecretKeyPaillier

{ +// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { +// Self::debug_secret(f) +// } +// } impl SecretKeyPaillier

{ pub fn random(rng: &mut impl CryptoRngCore) -> Self { diff --git a/synedrion/src/www02/entities.rs b/synedrion/src/www02/entities.rs index 4cdee12d..25c556f5 100644 --- a/synedrion/src/www02/entities.rs +++ b/synedrion/src/www02/entities.rs @@ -1,3 +1,4 @@ +use alloc::boxed::Box; use alloc::collections::{BTreeMap, BTreeSet}; use alloc::vec::Vec; use core::fmt::Debug; @@ -6,7 +7,7 @@ use core::marker::PhantomData; use bip32::{DerivationPath, PrivateKey, PrivateKeyBytes, PublicKey}; use k256::ecdsa::{SigningKey, VerifyingKey}; use rand_core::CryptoRngCore; -use secrecy::{ExposeSecret, Secret}; +use secrecy::{ExposeSecret, SecretBox}; use serde::{Deserialize, Serialize}; use crate::cggmp21::{KeyShare, SchemeParams}; @@ -22,7 +23,7 @@ use crate::tools::sss::{ pub struct ThresholdKeyShare { pub(crate) owner: I, pub(crate) threshold: u32, - pub(crate) secret_share: Secret, + pub(crate) secret_share: SecretBox, pub(crate) share_ids: BTreeMap, pub(crate) public_shares: BTreeMap, // TODO (#27): this won't be needed when Scalar/Point are a part of `P` @@ -74,7 +75,7 @@ impl ThresholdKeyShare ThresholdKeyShare>(); - let secret_share = Secret::new( + let secret_share = SecretBox::new(Box::new( self.secret_share.expose_secret() * &interpolation_coeff(share_ids.values(), &share_id), - ); + )); let public_shares = ids .iter() .map(|id| { @@ -144,12 +145,12 @@ impl ThresholdKeyShare>(); - let secret_share = Secret::new( + let secret_share = SecretBox::new(Box::new( key_share.secret_share.expose_secret() * &interpolation_coeff(share_ids.values(), &share_ids[key_share.owner()]) .invert() .unwrap(), - ); + )); let public_shares = ids .iter() .map(|id| { @@ -182,10 +183,9 @@ impl ThresholdKeyShare FinalizableToResult for Round1< .iter() .map(|id| (payloads[id].old_share_id, payloads[id].subshare)) .collect::>(); - let secret_share = Secret::new(shamir_join_scalars(subshares.iter())); + let secret_share = SecretBox::new(Box::new(shamir_join_scalars(subshares.iter()))); // Generate the public shares of all the new holders. let public_shares = self From 88f5fc0e9fd7294ec8ef70c76d343c4190765304 Mon Sep 17 00:00:00 2001 From: Hernando Castano Date: Wed, 31 Jul 2024 12:15:25 -0700 Subject: [PATCH 3/7] RustFmt --- synedrion/src/cggmp21/entities.rs | 12 +++++++----- synedrion/src/cggmp21/protocols/aux_gen.rs | 2 +- synedrion/src/cggmp21/protocols/key_init.rs | 2 +- synedrion/src/cggmp21/protocols/key_refresh.rs | 2 +- synedrion/src/cggmp21/protocols/presigning.rs | 2 +- synedrion/src/www02/key_resharing.rs | 2 +- 6 files changed, 12 insertions(+), 10 deletions(-) diff --git a/synedrion/src/cggmp21/entities.rs b/synedrion/src/cggmp21/entities.rs index edcabd63..56e360fa 100644 --- a/synedrion/src/cggmp21/entities.rs +++ b/synedrion/src/cggmp21/entities.rs @@ -1,5 +1,5 @@ -use alloc::collections::{BTreeMap, BTreeSet}; use alloc::boxed::Box; +use alloc::collections::{BTreeMap, BTreeSet}; use alloc::vec::Vec; use core::fmt::Debug; use core::marker::PhantomData; @@ -130,9 +130,9 @@ impl KeyShare { // TODO (#68): check that party_idx is the same for both, and the number of parties is the same assert_eq!(self.owner, change.owner); - let secret_share = SecretBox::new( - Box::new(self.secret_share.expose_secret() + change.secret_share_change.expose_secret()), - ); + let secret_share = SecretBox::new(Box::new( + self.secret_share.expose_secret() + change.secret_share_change.expose_secret(), + )); let public_shares = self .public_shares .iter() @@ -407,7 +407,9 @@ impl PresigningData { PresigningData { nonce, ephemeral_scalar_share: SecretBox::new(Box::new(k_i)), - product_share: SecretBox::new(Box::new(P::scalar_from_signed(&product_share_nonreduced))), + product_share: SecretBox::new(Box::new(P::scalar_from_signed( + &product_share_nonreduced, + ))), product_share_nonreduced, cap_k: all_cap_k[&id_i].clone(), values, diff --git a/synedrion/src/cggmp21/protocols/aux_gen.rs b/synedrion/src/cggmp21/protocols/aux_gen.rs index 288918f2..92a84dea 100644 --- a/synedrion/src/cggmp21/protocols/aux_gen.rs +++ b/synedrion/src/cggmp21/protocols/aux_gen.rs @@ -1,9 +1,9 @@ //! AuxGen protocol, a part of the paper's Auxiliary Info. & Key Refresh in Three Rounds (Fig. 6) //! that only generates the auxiliary data. +use alloc::boxed::Box; use alloc::collections::{BTreeMap, BTreeSet}; use alloc::string::String; -use alloc::boxed::Box; use core::fmt::Debug; use core::marker::PhantomData; diff --git a/synedrion/src/cggmp21/protocols/key_init.rs b/synedrion/src/cggmp21/protocols/key_init.rs index a463a037..5813918d 100644 --- a/synedrion/src/cggmp21/protocols/key_init.rs +++ b/synedrion/src/cggmp21/protocols/key_init.rs @@ -2,8 +2,8 @@ //! Note that this protocol only generates the key itself which is not enough to perform signing; //! auxiliary parameters need to be generated as well (during the KeyRefresh protocol). -use alloc::collections::{BTreeMap, BTreeSet}; use alloc::boxed::Box; +use alloc::collections::{BTreeMap, BTreeSet}; use core::fmt::Debug; use core::marker::PhantomData; diff --git a/synedrion/src/cggmp21/protocols/key_refresh.rs b/synedrion/src/cggmp21/protocols/key_refresh.rs index 3a14ddf5..487cee9a 100644 --- a/synedrion/src/cggmp21/protocols/key_refresh.rs +++ b/synedrion/src/cggmp21/protocols/key_refresh.rs @@ -2,8 +2,8 @@ //! This protocol generates an update to the secret key shares and new auxiliary parameters //! for ZK proofs (e.g. Paillier keys). -use alloc::collections::{BTreeMap, BTreeSet}; use alloc::boxed::Box; +use alloc::collections::{BTreeMap, BTreeSet}; use alloc::string::String; use alloc::vec::Vec; use core::fmt::Debug; diff --git a/synedrion/src/cggmp21/protocols/presigning.rs b/synedrion/src/cggmp21/protocols/presigning.rs index ba09c97f..7005b002 100644 --- a/synedrion/src/cggmp21/protocols/presigning.rs +++ b/synedrion/src/cggmp21/protocols/presigning.rs @@ -1,7 +1,7 @@ //! Presigning protocol, in the paper ECDSA Pre-Signing (Fig. 7). -use alloc::collections::{BTreeMap, BTreeSet}; use alloc::boxed::Box; +use alloc::collections::{BTreeMap, BTreeSet}; use alloc::string::String; use alloc::vec::Vec; use core::fmt::Debug; diff --git a/synedrion/src/www02/key_resharing.rs b/synedrion/src/www02/key_resharing.rs index a151021a..fffb4a6f 100644 --- a/synedrion/src/www02/key_resharing.rs +++ b/synedrion/src/www02/key_resharing.rs @@ -5,8 +5,8 @@ //! //! (Specifically, REDIST protocol). -use alloc::collections::{BTreeMap, BTreeSet}; use alloc::boxed::Box; +use alloc::collections::{BTreeMap, BTreeSet}; use alloc::vec::Vec; use core::fmt::Debug; use core::marker::PhantomData; From 4aa6870339669ec753c718fe7f8cbb1b0f5d56df Mon Sep 17 00:00:00 2001 From: Hernando Castano Date: Wed, 31 Jul 2024 12:19:14 -0700 Subject: [PATCH 4/7] Clean up some warnings --- synedrion/src/curve/arithmetic.rs | 4 +--- synedrion/src/paillier/keys.rs | 12 ++---------- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/synedrion/src/curve/arithmetic.rs b/synedrion/src/curve/arithmetic.rs index b9031b65..9e7fc492 100644 --- a/synedrion/src/curve/arithmetic.rs +++ b/synedrion/src/curve/arithmetic.rs @@ -24,7 +24,7 @@ use k256::{ Secp256k1, }; use rand_core::CryptoRngCore; -use secrecy::{CloneableSecret, SecretBox, SerializableSecret}; +use secrecy::{CloneableSecret, SerializableSecret}; use serde::{Deserialize, Deserializer, Serialize, Serializer}; use zeroize::DefaultIsZeroes; @@ -164,8 +164,6 @@ impl<'de> Deserialize<'de> for Scalar { impl DefaultIsZeroes for Scalar {} -// impl DebugSecret for Scalar {} - impl CloneableSecret for Scalar {} impl SerializableSecret for Scalar {} diff --git a/synedrion/src/paillier/keys.rs b/synedrion/src/paillier/keys.rs index 9189084c..cb4d2809 100644 --- a/synedrion/src/paillier/keys.rs +++ b/synedrion/src/paillier/keys.rs @@ -1,4 +1,4 @@ -use core::fmt::{self, Debug}; +use core::fmt::Debug; use rand_core::CryptoRngCore; // use secrecy::DebugSecret; @@ -12,20 +12,12 @@ use crate::uint::{ RandomPrimeWithRng, Retrieve, Signed, UintLike, UintModLike, }; -#[derive(Clone, Serialize, Deserialize, ZeroizeOnDrop, Debug)] +#[derive(Clone, Debug, Serialize, Deserialize, ZeroizeOnDrop)] pub(crate) struct SecretKeyPaillier { p: P::HalfUint, q: P::HalfUint, } -// impl DebugSecret for SecretKeyPaillier

{} - -// impl Debug for SecretKeyPaillier

{ -// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { -// Self::debug_secret(f) -// } -// } - impl SecretKeyPaillier

{ pub fn random(rng: &mut impl CryptoRngCore) -> Self { let p = P::HalfUint::generate_safe_prime_with_rng(rng, Some(P::PRIME_BITS)); From 9c161a190eba877ca70a85cc0ea1777022baf6bc Mon Sep 17 00:00:00 2001 From: Hernando Castano Date: Wed, 31 Jul 2024 12:22:46 -0700 Subject: [PATCH 5/7] Missed a comment --- synedrion/src/paillier/keys.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/synedrion/src/paillier/keys.rs b/synedrion/src/paillier/keys.rs index cb4d2809..e63cb02a 100644 --- a/synedrion/src/paillier/keys.rs +++ b/synedrion/src/paillier/keys.rs @@ -1,7 +1,6 @@ use core::fmt::Debug; use rand_core::CryptoRngCore; -// use secrecy::DebugSecret; use serde::{Deserialize, Serialize}; use zeroize::ZeroizeOnDrop; From a993172f25d38de06fb383bd25d531c7bed16fe4 Mon Sep 17 00:00:00 2001 From: Hernando Castano Date: Thu, 1 Aug 2024 21:05:37 -0400 Subject: [PATCH 6/7] Use `standard` config instead of `legacy` config We don't need to keep compatibilty with `bincode@1.x`, so we can move away from using the legacy config. --- synedrion/src/sessions/type_erased.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/synedrion/src/sessions/type_erased.rs b/synedrion/src/sessions/type_erased.rs index 0b1efe7f..6a8e0514 100644 --- a/synedrion/src/sessions/type_erased.rs +++ b/synedrion/src/sessions/type_erased.rs @@ -18,7 +18,7 @@ use crate::rounds::{ }; pub(crate) fn serialize_message(message: &impl Serialize) -> Result, LocalError> { - bincode::serde::encode_to_vec(message, bincode::config::legacy()) + bincode::serde::encode_to_vec(message, bincode::config::standard()) .map(|serialized| serialized.into_boxed_slice()) .map_err(|err| LocalError(format!("Failed to serialize: {err:?}"))) } @@ -26,7 +26,7 @@ pub(crate) fn serialize_message(message: &impl Serialize) -> Result, L pub(crate) fn deserialize_message Deserialize<'de>>( message_bytes: &[u8], ) -> Result { - bincode::serde::decode_borrowed_from_slice(message_bytes, bincode::config::legacy()) + bincode::serde::decode_borrowed_from_slice(message_bytes, bincode::config::standard()) .map_err(|err| err.to_string()) } From f5a5f159882aecb01fa2692ee95ce3260e4dfe5f Mon Sep 17 00:00:00 2001 From: Hernando Castano Date: Fri, 2 Aug 2024 13:56:01 -0400 Subject: [PATCH 7/7] Use manual `Debug` implementation for `SecretKeyPaillier` This should match the previous implementation provided by the `DebugSecret` crate. --- synedrion/src/paillier/keys.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/synedrion/src/paillier/keys.rs b/synedrion/src/paillier/keys.rs index e63cb02a..2a134134 100644 --- a/synedrion/src/paillier/keys.rs +++ b/synedrion/src/paillier/keys.rs @@ -11,12 +11,20 @@ use crate::uint::{ RandomPrimeWithRng, Retrieve, Signed, UintLike, UintModLike, }; -#[derive(Clone, Debug, Serialize, Deserialize, ZeroizeOnDrop)] +#[derive(Clone, Serialize, Deserialize, ZeroizeOnDrop)] pub(crate) struct SecretKeyPaillier { p: P::HalfUint, q: P::HalfUint, } +impl Debug for SecretKeyPaillier

{ + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> Result<(), core::fmt::Error> { + f.write_str("[REDACTED ")?; + f.write_str(core::any::type_name::())?; + f.write_str("]") + } +} + impl SecretKeyPaillier

{ pub fn random(rng: &mut impl CryptoRngCore) -> Self { let p = P::HalfUint::generate_safe_prime_with_rng(rng, Some(P::PRIME_BITS));