Skip to content

Commit

Permalink
Nomalize naming for wire/expanded structures and conversion methods
Browse files Browse the repository at this point in the history
  • Loading branch information
fjarri committed Nov 27, 2024
1 parent 75f9772 commit 551cd54
Show file tree
Hide file tree
Showing 18 changed files with 671 additions and 692 deletions.
28 changes: 14 additions & 14 deletions synedrion/src/cggmp21/aux_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ use super::{
use crate::{
curve::{Point, Scalar},
paillier::{
PublicKeyPaillier, PublicKeyPaillierPrecomputed, RPParams, RPParamsMod, RPSecret, SecretKeyPaillier,
SecretKeyPaillierPrecomputed,
PublicKeyPaillier, PublicKeyPaillierWire, RPParams, RPParamsWire, RPSecret, SecretKeyPaillier,
SecretKeyPaillierWire,
},
tools::{
bitvec::BitVec,
Expand Down Expand Up @@ -133,7 +133,7 @@ impl<P: SchemeParams, I: PartyId> EntryPoint<I> for AuxGen<P, I> {
.finalize();

// $p_i$, $q_i$
let paillier_sk = SecretKeyPaillier::<P::Paillier>::random(rng);
let paillier_sk = SecretKeyPaillierWire::<P::Paillier>::random(rng);
// $N_i$
let paillier_pk = paillier_sk.public_key();

Expand All @@ -147,7 +147,7 @@ impl<P: SchemeParams, I: PartyId> EntryPoint<I> for AuxGen<P, I> {

let rp_secret = RPSecret::random(rng);
// Ring-Pedersen parameters ($s$, $t$) bundled in a single object.
let rp_params = RPParamsMod::random_with_secret(rng, &rp_secret);
let rp_params = RPParams::random_with_secret(rng, &rp_secret);

let aux = (&sid_hash, id);
let hat_psi = PrmProof::<P>::new(rng, &rp_secret, &rp_params, &aux);
Expand All @@ -159,7 +159,7 @@ impl<P: SchemeParams, I: PartyId> EntryPoint<I> for AuxGen<P, I> {
cap_y,
cap_b,
paillier_pk: paillier_pk.clone(),
rp_params: rp_params.retrieve(),
rp_params: rp_params.to_wire(),
hat_psi,
rho,
u,
Expand Down Expand Up @@ -191,8 +191,8 @@ impl<P: SchemeParams, I: PartyId> EntryPoint<I> for AuxGen<P, I> {
struct PublicData1<P: SchemeParams> {
cap_y: Point,
cap_b: SchCommitment,
paillier_pk: PublicKeyPaillier<P::Paillier>, // $N_i$
rp_params: RPParams<P::Paillier>, // $s_i$ and $t_i$
paillier_pk: PublicKeyPaillierWire<P::Paillier>, // $N_i$
rp_params: RPParamsWire<P::Paillier>, // $s_i$ and $t_i$
hat_psi: PrmProof<P>,
rho: BitVec,
u: BitVec,
Expand All @@ -201,13 +201,13 @@ struct PublicData1<P: SchemeParams> {
#[derive(Debug, Clone)]
struct PublicData1Precomp<P: SchemeParams> {
data: PublicData1<P>,
paillier_pk: PublicKeyPaillierPrecomputed<P::Paillier>,
rp_params: RPParamsMod<P::Paillier>,
paillier_pk: PublicKeyPaillier<P::Paillier>,
rp_params: RPParams<P::Paillier>,
}

#[derive(Debug)]
struct Context<P: SchemeParams, I> {
paillier_sk: SecretKeyPaillierPrecomputed<P::Paillier>,
paillier_sk: SecretKeyPaillier<P::Paillier>,
y: Scalar,
tau_y: SchSecret,
data_precomp: PublicData1Precomp<P>,
Expand Down Expand Up @@ -390,7 +390,7 @@ impl<P: SchemeParams, I: PartyId> Round<I> for Round2<P, I> {

let aux = (&self.context.sid_hash, &from);

let rp_params = normal_broadcast.data.rp_params.to_mod();
let rp_params = normal_broadcast.data.rp_params.to_precomputed();
if !normal_broadcast.data.hat_psi.verify(&rp_params, &aux) {
return Err(ReceiveError::protocol(AuxGenError(AuxGenErrorEnum::Round2(
"PRM verification failed".into(),
Expand Down Expand Up @@ -604,15 +604,15 @@ impl<P: SchemeParams, I: PartyId + Serialize> Round<I> for Round3<P, I> {
id,
PublicAuxInfo {
el_gamal_pk: data.data.cap_y,
paillier_pk: data.paillier_pk.into_minimal(),
rp_params: data.rp_params.retrieve(),
paillier_pk: data.paillier_pk.into_wire(),
rp_params: data.rp_params.to_wire(),
},
)
})
.collect();

let secret_aux = SecretAuxInfo {
paillier_sk: self.context.paillier_sk.into_minimal(),
paillier_sk: self.context.paillier_sk.into_wire(),
el_gamal_sk: SecretBox::new(Box::new(self.context.y)),
};

Expand Down
44 changes: 22 additions & 22 deletions synedrion/src/cggmp21/entities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use crate::{
cggmp21::SchemeParams,
curve::{Point, Scalar},
paillier::{
CiphertextMod, PaillierParams, PublicKeyPaillier, PublicKeyPaillierPrecomputed, RPParams, RPParamsMod,
Randomizer, SecretKeyPaillier, SecretKeyPaillierPrecomputed,
Ciphertext, PaillierParams, PublicKeyPaillier, PublicKeyPaillierWire, RPParams, RPParamsWire, RandomizerWire,
SecretKeyPaillier, SecretKeyPaillierWire,
},
uint::Signed,
};
Expand All @@ -40,22 +40,22 @@ pub struct AuxInfo<P: SchemeParams, I: Ord> {
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(bound(serialize = "SecretKeyPaillier<P::Paillier>: Serialize"))]
#[serde(bound(deserialize = "SecretKeyPaillier<P::Paillier>: for <'x> Deserialize<'x>"))]
#[serde(bound(serialize = "SecretKeyPaillierWire<P::Paillier>: Serialize"))]
#[serde(bound(deserialize = "SecretKeyPaillierWire<P::Paillier>: for <'x> Deserialize<'x>"))]
pub(crate) struct SecretAuxInfo<P: SchemeParams> {
pub(crate) paillier_sk: SecretKeyPaillier<P::Paillier>,
pub(crate) paillier_sk: SecretKeyPaillierWire<P::Paillier>,
pub(crate) el_gamal_sk: SecretBox<Scalar>, // `y_i`
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(bound(serialize = "PublicKeyPaillier<P::Paillier>: Serialize"))]
#[serde(bound(deserialize = "PublicKeyPaillier<P::Paillier>: for <'x> Deserialize<'x>"))]
#[serde(bound(serialize = "PublicKeyPaillierWire<P::Paillier>: Serialize"))]
#[serde(bound(deserialize = "PublicKeyPaillierWire<P::Paillier>: for <'x> Deserialize<'x>"))]
pub(crate) struct PublicAuxInfo<P: SchemeParams> {
pub(crate) el_gamal_pk: Point, // `Y_i`
/// The Paillier public key.
pub(crate) paillier_pk: PublicKeyPaillier<P::Paillier>,
pub(crate) paillier_pk: PublicKeyPaillierWire<P::Paillier>,
/// The ring-Pedersen parameters.
pub(crate) rp_params: RPParams<P::Paillier>, // `s_i` and `t_i`
pub(crate) rp_params: RPParamsWire<P::Paillier>, // `s_i` and `t_i`
}

#[derive(Debug, Clone)]
Expand All @@ -66,7 +66,7 @@ pub(crate) struct AuxInfoPrecomputed<P: SchemeParams, I> {

#[derive(Debug, Clone)]
pub(crate) struct SecretAuxInfoPrecomputed<P: SchemeParams> {
pub(crate) paillier_sk: SecretKeyPaillierPrecomputed<P::Paillier>,
pub(crate) paillier_sk: SecretKeyPaillier<P::Paillier>,
#[allow(dead_code)] // TODO (#36): this will be needed for the 6-round presigning protocol.
pub(crate) el_gamal_sk: SecretBox<Scalar>, // `y_i`
}
Expand All @@ -75,8 +75,8 @@ pub(crate) struct SecretAuxInfoPrecomputed<P: SchemeParams> {
pub(crate) struct PublicAuxInfoPrecomputed<P: SchemeParams> {
#[allow(dead_code)] // TODO (#36): this will be needed for the 6-round presigning protocol.
pub(crate) el_gamal_pk: Point,
pub(crate) paillier_pk: PublicKeyPaillierPrecomputed<P::Paillier>,
pub(crate) rp_params: RPParamsMod<P::Paillier>,
pub(crate) paillier_pk: PublicKeyPaillier<P::Paillier>,
pub(crate) rp_params: RPParams<P::Paillier>,
}

/// The result of the Auxiliary Info & Key Refresh protocol - the update to the key share.
Expand Down Expand Up @@ -105,7 +105,7 @@ pub(crate) struct PresigningData<P: SchemeParams, I> {
pub(crate) product_share_nonreduced: Signed<<P::Paillier as PaillierParams>::Uint>,

// $K_i$.
pub(crate) cap_k: CiphertextMod<P::Paillier>,
pub(crate) cap_k: Ciphertext<P::Paillier>,

// The values for $j$, $j != i$.
pub(crate) values: BTreeMap<I, PresigningValues<P>>,
Expand All @@ -114,14 +114,14 @@ pub(crate) struct PresigningData<P: SchemeParams, I> {
#[derive(Debug, Clone)]
pub(crate) struct PresigningValues<P: SchemeParams> {
pub(crate) hat_beta: SecretBox<Signed<<P::Paillier as PaillierParams>::Uint>>,
pub(crate) hat_r: Randomizer<P::Paillier>,
pub(crate) hat_s: Randomizer<P::Paillier>,
pub(crate) cap_k: CiphertextMod<P::Paillier>,
pub(crate) hat_r: RandomizerWire<P::Paillier>,
pub(crate) hat_s: RandomizerWire<P::Paillier>,
pub(crate) cap_k: Ciphertext<P::Paillier>,
/// Received $\hat{D}_{i,j}$.
pub(crate) hat_cap_d_received: CiphertextMod<P::Paillier>,
pub(crate) hat_cap_d_received: Ciphertext<P::Paillier>,
/// Sent $\hat{D}_{j,i}$.
pub(crate) hat_cap_d: CiphertextMod<P::Paillier>,
pub(crate) hat_cap_f: CiphertextMod<P::Paillier>,
pub(crate) hat_cap_d: Ciphertext<P::Paillier>,
pub(crate) hat_cap_f: Ciphertext<P::Paillier>,
}

impl<P: SchemeParams, I: Clone + Ord + PartialEq + Debug> KeyShare<P, I> {
Expand Down Expand Up @@ -215,7 +215,7 @@ impl<P: SchemeParams, I: Ord + Clone> AuxInfo<P, I> {
pub fn new_centralized(rng: &mut impl CryptoRngCore, ids: &BTreeSet<I>) -> BTreeMap<I, Self> {
let secret_aux = (0..ids.len())
.map(|_| SecretAuxInfo {
paillier_sk: SecretKeyPaillier::<P::Paillier>::random(rng),
paillier_sk: SecretKeyPaillierWire::<P::Paillier>::random(rng),
el_gamal_sk: SecretBox::new(Box::new(Scalar::random(rng))),
})
.collect::<Vec<_>>();
Expand All @@ -229,7 +229,7 @@ impl<P: SchemeParams, I: Ord + Clone> AuxInfo<P, I> {
PublicAuxInfo {
paillier_pk: secret.paillier_sk.public_key(),
el_gamal_pk: secret.el_gamal_sk.expose_secret().mul_by_generator(),
rp_params: RPParamsMod::random(rng).retrieve(),
rp_params: RPParams::random(rng).to_wire(),
},
)
})
Expand Down Expand Up @@ -266,7 +266,7 @@ impl<P: SchemeParams, I: Ord + Clone> AuxInfo<P, I> {
PublicAuxInfoPrecomputed {
el_gamal_pk: public_aux.el_gamal_pk,
paillier_pk: paillier_pk.clone(),
rp_params: public_aux.rp_params.to_mod(),
rp_params: public_aux.rp_params.to_precomputed(),
},
)
})
Expand Down
Loading

0 comments on commit 551cd54

Please sign in to comment.