Skip to content

Commit

Permalink
feature: introduce refreshing api in ferveo
Browse files Browse the repository at this point in the history
  • Loading branch information
piotr-roslaniec committed Mar 19, 2024
1 parent cfa8c99 commit 4713848
Show file tree
Hide file tree
Showing 16 changed files with 819 additions and 222 deletions.
9 changes: 5 additions & 4 deletions ferveo-common/src/keypair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ use ark_std::{
rand::{prelude::StdRng, RngCore, SeedableRng},
UniformRand,
};
use generic_array::{typenum::U96, GenericArray};
use generic_array::{
typenum::{Unsigned, U96},
GenericArray,
};
use serde::*;
use serde_with::serde_as;

Expand Down Expand Up @@ -55,7 +58,7 @@ impl<E: Pairing> PublicKey<E> {
}

pub fn serialized_size() -> usize {
96
U96::to_usize()
}
}

Expand Down Expand Up @@ -106,7 +109,6 @@ impl<E: Pairing> Ord for Keypair<E> {

impl<E: Pairing> Keypair<E> {
/// Returns the public session key for the publicly verifiable DKG participant

pub fn public_key(&self) -> PublicKey<E> {
PublicKey::<E> {
encryption_key: E::G2Affine::generator()
Expand All @@ -116,7 +118,6 @@ impl<E: Pairing> Keypair<E> {
}

/// Creates a new ephemeral session key for participating in the DKG

pub fn new<R: RngCore>(rng: &mut R) -> Self {
Self {
decryption_key: E::ScalarField::rand(rng),
Expand Down
1 change: 1 addition & 0 deletions ferveo-python/ferveo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@
DuplicatedShareIndex,
NoTranscriptsToAggregate,
InvalidAggregateVerificationParameters,
UnknownValidator,
)
3 changes: 3 additions & 0 deletions ferveo-python/ferveo/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,6 @@ class NoTranscriptsToAggregate(Exception):

class InvalidAggregateVerificationParameters(Exception):
pass

class UnknownValidator(Exception):
pass
2 changes: 1 addition & 1 deletion ferveo-tdec/benches/tpke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ pub fn bench_decryption_share_validity_checks(c: &mut Criterion) {
// for &shares_num in NUM_SHARES_CASES.iter() {
// let setup = SetupSimple::new(shares_num, msg_size, rng);
// let threshold = setup.shared.threshold;
// let polynomial = make_random_polynomial_with_root::<E>(
// let polynomial = create_random_polynomial_with_root::<E>(
// threshold - 1,
// &Fr::zero(),
// rng,
Expand Down
2 changes: 0 additions & 2 deletions ferveo-tdec/src/combine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ pub fn prepare_combine_fast<E: Pairing>(
.collect::<Vec<_>>()
}

// TODO: Combine `tpke::prepare_combine_simple` and `tpke::share_combine_simple` into
// one function and expose it in the tpke::api?
pub fn prepare_combine_simple<E: Pairing>(
domain: &[E::ScalarField],
) -> Vec<E::ScalarField> {
Expand Down
3 changes: 0 additions & 3 deletions ferveo-tdec/src/decryption.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ impl<E: Pairing> ValidatorShareChecksum<E> {
// C_i = dk_i^{-1} * U
let checksum = ciphertext_header
.commitment
// TODO: Should we panic here? I think we should since that would mean that the decryption key is invalid.
// And so, the validator should not be able to create a decryption share.
// And so, the validator should remake their keypair.
.mul(
validator_decryption_key
.inverse()
Expand Down
11 changes: 9 additions & 2 deletions ferveo-tdec/src/key_share.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ use std::ops::Mul;
use ark_ec::{pairing::Pairing, AffineRepr, CurveGroup};
use ark_ff::One;
use ark_std::UniformRand;
use ferveo_common::serialization;
use rand_core::RngCore;
use zeroize::ZeroizeOnDrop;
use serde::{Deserialize, Serialize};
use serde_with::serde_as;
use zeroize::{Zeroize, ZeroizeOnDrop};

#[derive(Debug, Clone)]
// TODO: Should we rename it to PublicKey or SharedPublicKey?
Expand Down Expand Up @@ -49,9 +52,13 @@ impl<E: Pairing> BlindedKeyShare<E> {
}
}

#[derive(Debug, Clone, PartialEq, Eq, ZeroizeOnDrop)]
#[serde_as]
#[derive(
Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Zeroize, ZeroizeOnDrop,
)]
pub struct PrivateKeyShare<E: Pairing> {
// TODO: Replace with a tuple?
#[serde_as(as = "serialization::SerdeAs")]
pub private_key_share: E::G2Affine,
}

Expand Down
8 changes: 4 additions & 4 deletions ferveo-tdec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ pub mod test_common {
setup_simple::<E>(shares_num, shares_num, rng)
}

pub fn make_shared_secret<E: Pairing>(
pub fn create_shared_secret<E: Pairing>(
pub_contexts: &[PublicDecryptionContextSimple<E>],
decryption_shares: &[DecryptionShareSimple<E>],
) -> SharedSecret<E> {
Expand All @@ -308,7 +308,7 @@ mod tests {
use ark_std::{test_rng, UniformRand};
use ferveo_common::{FromBytes, ToBytes};

use crate::test_common::{make_shared_secret, setup_simple, *};
use crate::test_common::{create_shared_secret, setup_simple, *};

type E = ark_bls12_381::Bls12_381;
type TargetField = <E as Pairing>::TargetField;
Expand Down Expand Up @@ -481,7 +481,7 @@ mod tests {
let pub_contexts =
contexts[0].public_decryption_contexts[..threshold].to_vec();
let shared_secret =
make_shared_secret(&pub_contexts, &decryption_shares);
create_shared_secret(&pub_contexts, &decryption_shares);

test_ciphertext_validation_fails(
&msg,
Expand All @@ -495,7 +495,7 @@ mod tests {
let decryption_shares = decryption_shares[..threshold - 1].to_vec();
let pub_contexts = pub_contexts[..threshold - 1].to_vec();
let shared_secret =
make_shared_secret(&pub_contexts, &decryption_shares);
create_shared_secret(&pub_contexts, &decryption_shares);

let result =
decrypt_with_shared_secret(&ciphertext, aad, &shared_secret, g_inv);
Expand Down
Loading

0 comments on commit 4713848

Please sign in to comment.