Skip to content

Commit

Permalink
Hide secrecy
Browse files Browse the repository at this point in the history
  • Loading branch information
fjarri committed Dec 1, 2024
1 parent b820863 commit 1fcfe3c
Show file tree
Hide file tree
Showing 21 changed files with 12 additions and 41 deletions.
1 change: 0 additions & 1 deletion synedrion/src/cggmp21/interactive_signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use manul::protocol::{
ReceiveError, Round, RoundId, Serializer,
};
use rand_core::CryptoRngCore;
use secrecy::ExposeSecret;
use serde::{Deserialize, Serialize};

use super::{
Expand Down
2 changes: 0 additions & 2 deletions synedrion/src/cggmp21/key_refresh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use manul::protocol::{
ReceiveError, Round, RoundId, Serializer,
};
use rand_core::CryptoRngCore;
use secrecy::ExposeSecret;
use serde::{Deserialize, Serialize};

use super::{
Expand Down Expand Up @@ -787,7 +786,6 @@ mod tests {
session::signature::Keypair,
};
use rand_core::OsRng;
use secrecy::ExposeSecret;

use super::KeyRefresh;
use crate::{cggmp21::TestParams, curve::Scalar};
Expand Down
1 change: 0 additions & 1 deletion synedrion/src/cggmp21/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use core::fmt::Debug;
// So as long as that is the case, `k256` `Uint` is separate
// from the one used throughout the crate.
use k256::elliptic_curve::bigint::Uint as K256Uint;
use secrecy::{ExposeSecret, ExposeSecretMut};
use serde::{Deserialize, Serialize};

use crate::{
Expand Down
1 change: 0 additions & 1 deletion synedrion/src/cggmp21/sigma/aff_g.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Paillier Affine Operation with Group Commitment in Range ($\Pi^{aff-g}$, Section 6.2, Fig. 15)
use rand_core::CryptoRngCore;
use secrecy::ExposeSecret;
use serde::{Deserialize, Serialize};

use super::super::{
Expand Down
2 changes: 0 additions & 2 deletions synedrion/src/cggmp21/sigma/dec.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Paillier decryption modulo $q$ ($\Pi^{dec}$, Section C.6, Fig. 30)
use rand_core::CryptoRngCore;
use secrecy::ExposeSecret;
use serde::{Deserialize, Serialize};

use super::super::{
Expand Down Expand Up @@ -170,7 +169,6 @@ impl<P: SchemeParams> DecProof<P> {
#[cfg(test)]
mod tests {
use rand_core::OsRng;
use secrecy::ExposeSecret;

use super::DecProof;
use crate::{
Expand Down
1 change: 0 additions & 1 deletion synedrion/src/cggmp21/sigma/enc.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Paillier encryption in range ($\Pi^{enc}$, Section 6.1, Fig. 14)
use rand_core::CryptoRngCore;
use secrecy::ExposeSecret;
use serde::{Deserialize, Serialize};

use super::super::SchemeParams;
Expand Down
1 change: 0 additions & 1 deletion synedrion/src/cggmp21/sigma/fac.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! No small factor proof ($\Pi^{fac}$, Section C.5, Fig. 28)
use rand_core::CryptoRngCore;
use secrecy::ExposeSecret;
use serde::{Deserialize, Serialize};

use super::super::SchemeParams;
Expand Down
1 change: 0 additions & 1 deletion synedrion/src/cggmp21/sigma/log_star.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Knowledge of Exponent vs Paillier Encryption ($\Pi^{log*}$, Section C.2, Fig. 25)
use rand_core::CryptoRngCore;
use secrecy::ExposeSecret;
use serde::{Deserialize, Serialize};

use super::super::{
Expand Down
1 change: 0 additions & 1 deletion synedrion/src/cggmp21/sigma/mod_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use alloc::vec::Vec;

use crypto_bigint::Square;
use rand_core::CryptoRngCore;
use secrecy::ExposeSecret;
use serde::{Deserialize, Serialize};

use super::super::SchemeParams;
Expand Down
1 change: 0 additions & 1 deletion synedrion/src/cggmp21/sigma/mul.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Paillier multiplication ($\Pi^{mul}$, Section C.6, Fig. 29)
use rand_core::CryptoRngCore;
use secrecy::ExposeSecret;
use serde::{Deserialize, Serialize};

use super::super::SchemeParams;
Expand Down
1 change: 0 additions & 1 deletion synedrion/src/cggmp21/sigma/mul_star.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Multiplication Paillier vs Group ($\Pi^{mul}$, Section C.6, Fig. 31)
use rand_core::CryptoRngCore;
use secrecy::ExposeSecret;
use serde::{Deserialize, Serialize};

use super::super::{
Expand Down
1 change: 0 additions & 1 deletion synedrion/src/cggmp21/sigma/prm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use alloc::{vec, vec::Vec};

use digest::XofReader;
use rand_core::CryptoRngCore;
use secrecy::ExposeSecret;
use serde::{Deserialize, Serialize};

use super::super::SchemeParams;
Expand Down
4 changes: 1 addition & 3 deletions synedrion/src/cggmp21/sigma/sch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
//! where $g$ is a EC generator.
use rand_core::CryptoRngCore;
use secrecy::ExposeSecret;
use serde::{Deserialize, Serialize};
use zeroize::ZeroizeOnDrop;

use crate::{
curve::{Point, Scalar},
Expand All @@ -19,7 +17,7 @@ use crate::{
const HASH_TAG: &[u8] = b"P_sch";

/// Secret data the proof is based on (~ signing key)
#[derive(Debug, Clone, ZeroizeOnDrop)]
#[derive(Debug, Clone)]
pub(crate) struct SchSecret(
/// `\alpha`
Secret<Scalar>,
Expand Down
1 change: 0 additions & 1 deletion synedrion/src/curve/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ use k256::{
Secp256k1,
};
use rand_core::CryptoRngCore;
use secrecy::ExposeSecret;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use serde_encoded_bytes::{Hex, SliceLike};
use zeroize::Zeroize;
Expand Down
2 changes: 0 additions & 2 deletions synedrion/src/paillier/encryption.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use core::{

use crypto_bigint::{subtle::ConstantTimeGreater, Monty, ShrVartime};
use rand_core::CryptoRngCore;
use secrecy::ExposeSecret;
use serde::{Deserialize, Serialize};
use zeroize::ZeroizeOnDrop;

Expand Down Expand Up @@ -505,7 +504,6 @@ impl<'a, P: PaillierParams> Mul<&'a Secret<Bounded<P::Uint>>> for &Ciphertext<P>
mod tests {
use crypto_bigint::{Encoding, Integer, ShrVartime, WrappingSub};
use rand_core::OsRng;
use secrecy::ExposeSecret;

use super::{
super::{params::PaillierTest, PaillierParams, SecretKeyPaillierWire},
Expand Down
1 change: 0 additions & 1 deletion synedrion/src/paillier/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use core::{

use crypto_bigint::{InvMod, Monty, Odd, ShrVartime, Square, WrappingAdd};
use rand_core::CryptoRngCore;
use secrecy::{ExposeSecret, ExposeSecretMut};
use serde::{Deserialize, Serialize};

use super::{
Expand Down
1 change: 0 additions & 1 deletion synedrion/src/paillier/ring_pedersen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use core::ops::Mul;

use crypto_bigint::{Monty, NonZero, RandomMod, ShrVartime};
use rand_core::CryptoRngCore;
use secrecy::ExposeSecret;
use serde::{Deserialize, Serialize};

use super::{
Expand Down
1 change: 0 additions & 1 deletion synedrion/src/paillier/rsa.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crypto_bigint::{CheckedSub, Gcd, Integer, Monty, NonZero, Odd, RandomMod, Square};
use crypto_primes::RandomPrimeWithRng;
use rand_core::CryptoRngCore;
use secrecy::ExposeSecret;
use serde::{Deserialize, Serialize};

use super::params::PaillierParams;
Expand Down
26 changes: 11 additions & 15 deletions synedrion/src/tools/secret.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use core::{
fmt::Debug,
ops::{Add, AddAssign, Deref, DerefMut, Div, DivAssign, Mul, MulAssign, Neg, Rem, RemAssign, Sub, SubAssign},
ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Rem, RemAssign, Sub, SubAssign},
};

use crypto_bigint::{
Expand All @@ -25,6 +25,16 @@ use crate::{
/// - Safe serialization/deserialization (down to `serde` API; what happens there we cannot control)
pub(crate) struct Secret<T: Zeroize>(SecretBox<T>);

impl<T: Zeroize> Secret<T> {
pub fn expose_secret(&self) -> &T {
self.0.expose_secret()
}

pub fn expose_secret_mut(&mut self) -> &mut T {
self.0.expose_secret_mut()
}
}

impl<T: Zeroize + Clone> Secret<T> {
pub fn init_with(ctr: impl FnOnce() -> T) -> Self {
Self(SecretBox::init_with(ctr))
Expand Down Expand Up @@ -112,20 +122,6 @@ where
}
}

impl<T: Zeroize> Deref for Secret<T> {
type Target = SecretBox<T>;

fn deref(&self) -> &Self::Target {
&self.0
}
}

impl<T: Zeroize> DerefMut for Secret<T> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}

// Addition

impl<'a, T: Zeroize + AddAssign<&'a T>> AddAssign<&'a T> for Secret<T> {
Expand Down
2 changes: 0 additions & 2 deletions synedrion/src/tools/sss.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use alloc::{
use core::ops::{Add, Mul};

use rand_core::CryptoRngCore;
use secrecy::ExposeSecret;
use serde::{Deserialize, Serialize};

use crate::{
Expand Down Expand Up @@ -137,7 +136,6 @@ pub(crate) fn shamir_join_points(pairs: &BTreeMap<ShareId, Point>) -> Point {
#[cfg(test)]
mod tests {
use rand_core::OsRng;
use secrecy::ExposeSecret;

use super::{evaluate_polynomial, shamir_evaluation_points, shamir_join_scalars, shamir_split};
use crate::{curve::Scalar, tools::Secret};
Expand Down
1 change: 0 additions & 1 deletion synedrion/src/www02/entities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,6 @@ mod tests {
session::signature::Keypair,
};
use rand_core::OsRng;
use secrecy::ExposeSecret;

use super::ThresholdKeyShare;
use crate::{cggmp21::TestParams, curve::Scalar};
Expand Down

0 comments on commit 1fcfe3c

Please sign in to comment.