Skip to content

Commit

Permalink
refactor: rename public key share to public key
Browse files Browse the repository at this point in the history
  • Loading branch information
piotr-roslaniec committed Feb 20, 2024
1 parent f746edf commit 5f15891
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 30 deletions.
2 changes: 1 addition & 1 deletion ferveo-tdec/benches/tpke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct SetupShared {
shares_num: usize,
msg: Vec<u8>,
aad: Vec<u8>,
pubkey: PublicKeyShare<E>,
pubkey: PublicKey<E>,
privkey: PrivateKeyShare<E>,
ciphertext: Ciphertext<E>,
shared_secret: SharedSecret<E>,
Expand Down
4 changes: 2 additions & 2 deletions ferveo-tdec/src/ciphertext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use sha2::{digest::Digest, Sha256};
use zeroize::ZeroizeOnDrop;

use crate::{
htp_bls12381_g2, Error, PrivateKeyShare, PublicKeyShare, Result, SecretBox,
htp_bls12381_g2, Error, PrivateKeyShare, PublicKey, Result, SecretBox,
SharedSecret,
};

Expand Down Expand Up @@ -98,7 +98,7 @@ impl<E: Pairing> CiphertextHeader<E> {
pub fn encrypt<E: Pairing>(
message: SecretBox<Vec<u8>>,
aad: &[u8],
pubkey: &PublicKeyShare<E>,
pubkey: &PublicKey<E>,
rng: &mut impl rand::Rng,
) -> Result<Ciphertext<E>> {
// r
Expand Down
6 changes: 3 additions & 3 deletions ferveo-tdec/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ use ark_ec::{pairing::Pairing, CurveGroup};
use crate::{
prepare_combine_simple, BlindedKeyShare, Ciphertext, CiphertextHeader,
DecryptionShareFast, DecryptionSharePrecomputed, DecryptionShareSimple,
PrivateKeyShare, PublicKeyShare, Result,
PrivateKeyShare, PublicKey, Result,
};

#[derive(Clone, Debug)]
pub struct PublicDecryptionContextFast<E: Pairing> {
pub domain: E::ScalarField,
pub public_key_share: PublicKeyShare<E>,
pub public_key: PublicKey<E>,
pub blinded_key_share: BlindedKeyShare<E>,
// This decrypter's contribution to N(0), namely (-1)^|domain| * \prod_i omega_i
pub lagrange_n_0: E::ScalarField,
Expand All @@ -21,7 +21,7 @@ pub struct PublicDecryptionContextFast<E: Pairing> {
#[derive(Clone, Debug)]
pub struct PublicDecryptionContextSimple<E: Pairing> {
pub domain: E::ScalarField,
pub public_key_share: PublicKeyShare<E>,
pub public_key: PublicKey<E>,
pub blinded_key_share: BlindedKeyShare<E>,
pub h: E::G2Affine,
pub validator_public_key: E::G2,
Expand Down
10 changes: 4 additions & 6 deletions ferveo-tdec/src/key_share.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ use zeroize::{Zeroize, ZeroizeOnDrop};

#[serde_as]
#[derive(Debug, Copy, Clone, Serialize, Deserialize, PartialEq, Eq)]
// TODO: Should we rename it to PublicKey or SharedPublicKey?
pub struct PublicKeyShare<E: Pairing>(
pub struct PublicKey<E: Pairing>(
#[serde_as(as = "serialization::SerdeAs")] pub E::G1Affine, // A_{i, \omega_i}
);

Expand All @@ -25,15 +24,14 @@ pub struct BlindedKeyShare<E: Pairing> {
impl<E: Pairing> BlindedKeyShare<E> {
pub fn verify_blinding<R: RngCore>(
&self,
public_key_share: &PublicKeyShare<E>,
public_key: &PublicKey<E>,
rng: &mut R,
) -> bool {
let g = E::G1Affine::generator();
let alpha = E::ScalarField::rand(rng);

let alpha_a = E::G1Prepared::from(
g + public_key_share.0.mul(alpha).into_affine(),
);
let alpha_a =
E::G1Prepared::from(g + public_key.0.mul(alpha).into_affine());

// \sum_i(Y_i)
let alpha_z = E::G2Prepared::from(
Expand Down
14 changes: 7 additions & 7 deletions ferveo-tdec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub mod test_common {
shares_num: usize,
rng: &mut impl RngCore,
) -> (
PublicKeyShare<E>,
PublicKey<E>,
PrivateKeyShare<E>,
Vec<PrivateDecryptionContextFast<E>>,
) {
Expand Down Expand Up @@ -157,7 +157,7 @@ pub mod test_common {
});
public_contexts.push(PublicDecryptionContextFast::<E> {
domain: *domain,
public_key_share: PublicKeyShare::<E>(*public),
public_key: PublicKey::<E>(*public),
blinded_key_share: blinded_key_shares,
lagrange_n_0: *domain,
h_inv: E::G2Prepared::from(-h.into_group()),
Expand All @@ -168,7 +168,7 @@ pub mod test_common {
}

(
PublicKeyShare(pubkey.into()),
PublicKey(pubkey.into()),
PrivateKeyShare(privkey.into()),
private_contexts,
)
Expand All @@ -179,7 +179,7 @@ pub mod test_common {
shares_num: usize,
rng: &mut impl rand::Rng,
) -> (
PublicKeyShare<E>,
PublicKey<E>,
PrivateKeyShare<E>,
Vec<PrivateDecryptionContextSimple<E>>,
) {
Expand Down Expand Up @@ -245,7 +245,7 @@ pub mod test_common {
});
public_contexts.push(PublicDecryptionContextSimple::<E> {
domain: *domain,
public_key_share: PublicKeyShare::<E>(*public),
public_key: PublicKey::<E>(*public),
blinded_key_share,
h,
validator_public_key: h.mul(b),
Expand All @@ -256,7 +256,7 @@ pub mod test_common {
}

(
PublicKeyShare(pubkey.into()),
PublicKey(pubkey.into()),
PrivateKeyShare(privkey.into()),
private_contexts,
)
Expand All @@ -266,7 +266,7 @@ pub mod test_common {
shares_num: usize,
rng: &mut impl rand::Rng,
) -> (
PublicKeyShare<E>,
PublicKey<E>,
PrivateKeyShare<E>,
Vec<PrivateDecryptionContextSimple<E>>,
) {
Expand Down
12 changes: 6 additions & 6 deletions ferveo/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,13 @@ impl From<bindings_wasm::FerveoVariant> for FerveoVariant {
#[derive(Copy, Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
pub struct DkgPublicKey(
#[serde(bound(
serialize = "ferveo_tdec::PublicKeyShare<E>: Serialize",
deserialize = "ferveo_tdec::PublicKeyShare<E>: DeserializeOwned"
serialize = "ferveo_tdec::PublicKey<E>: Serialize",
deserialize = "ferveo_tdec::PublicKey<E>: DeserializeOwned"
))]
pub(crate) ferveo_tdec::PublicKeyShare<E>,
pub(crate) ferveo_tdec::PublicKey<E>,
);

// TODO: Consider moving these implementation details to ferveo_tdec::PublicKeyShare
// TODO: Consider moving these implementation details to ferveo_tdec::PublicKey
impl DkgPublicKey {
pub fn to_bytes(&self) -> Result<GenericArray<u8, U48>> {
let as_bytes = to_bytes(&self.0 .0)?;
Expand All @@ -166,7 +166,7 @@ impl DkgPublicKey {
)
})?;
let pk: G1Affine = from_bytes(&bytes)?;
Ok(DkgPublicKey(ferveo_tdec::PublicKeyShare(pk)))
Ok(DkgPublicKey(ferveo_tdec::PublicKey(pk)))
}

pub fn serialized_size() -> usize {
Expand All @@ -178,7 +178,7 @@ impl DkgPublicKey {
pub fn random() -> Self {
let mut rng = thread_rng();
let g1 = G1Affine::rand(&mut rng);
Self(ferveo_tdec::PublicKeyShare(g1))
Self(ferveo_tdec::PublicKey(g1))
}
}

Expand Down
8 changes: 4 additions & 4 deletions ferveo/src/pvss.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,10 +393,10 @@ pub struct AggregatedTranscript<E: Pairing> {
))]
pub aggregate: PubliclyVerifiableSS<E, Aggregated>,
#[serde(bound(
serialize = "ferveo_tdec::PublicKeyShare<E>: Serialize",
deserialize = "ferveo_tdec::PublicKeyShare<E>: DeserializeOwned"
serialize = "ferveo_tdec::PublicKey<E>: Serialize",
deserialize = "ferveo_tdec::PublicKey<E>: DeserializeOwned"
))]
pub public_key: ferveo_tdec::PublicKeyShare<E>,
pub public_key: ferveo_tdec::PublicKey<E>,
}

impl<E: Pairing> AggregatedTranscript<E> {
Expand All @@ -409,7 +409,7 @@ impl<E: Pairing> AggregatedTranscript<E> {
.map(|pvss| pvss.coeffs[0].into_group())
.sum::<E::G1>()
.into_affine();
let public_key = ferveo_tdec::PublicKeyShare::<E>(public_key);
let public_key = ferveo_tdec::PublicKey::<E>(public_key);
Ok(AggregatedTranscript {
aggregate,
public_key,
Expand Down
1 change: 0 additions & 1 deletion ferveo/src/refresh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ impl<E: Pairing> UpdatedPrivateKeyShare<E> {
}
}

// TODO: Replace with an into trait?
/// Trait for types that can be used to update a private key share.
pub trait PrivateKeyShareUpdate<E: Pairing> {
fn inner(&self) -> &InnerPrivateKeyShare<E>;
Expand Down

0 comments on commit 5f15891

Please sign in to comment.