Skip to content

Commit

Permalink
fix after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
piotr-roslaniec committed Jan 20, 2023
1 parent 99d2b9c commit 26fe690
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 19 deletions.
6 changes: 4 additions & 2 deletions ferveo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ mod test_dkg_full {
&ciphertext,
aad,
&shared_secret,
);
)
.unwrap();
assert_eq!(plaintext, msg);
}

Expand Down Expand Up @@ -130,7 +131,8 @@ mod test_dkg_full {
&ciphertext,
aad,
&shared_secret,
);
)
.unwrap();
assert_eq!(plaintext, msg);
}
}
16 changes: 11 additions & 5 deletions ferveo/src/vss/pvss.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use ark_ec::PairingEngine;
use ark_ff::UniformRand;
use ark_serialize::*;
use ferveo_common::{Keypair, PublicKey};
use group_threshold_cryptography::Ciphertext;
use group_threshold_cryptography::{Ciphertext, DecryptionShareSimple};
use itertools::{zip_eq, Itertools};
use subproductdomain::fast_multiexp;

Expand Down Expand Up @@ -260,8 +260,8 @@ pub fn make_decryption_shares<E: PairingEngine>(
ciphertext: &Ciphertext<E>,
validator_keypairs: Vec<Keypair<E>>,
aggregate: Vec<E::G2Affine>,
) -> Vec<E::Fqk> {
let decryption_shares = aggregate
) -> Vec<DecryptionShareSimple<E>> {
aggregate
.iter()
.zip_eq(validator_keypairs.iter())
.map(|(encrypted_share, keypair)| {
Expand All @@ -271,8 +271,14 @@ pub fn make_decryption_shares<E: PairingEngine>(
let u = ciphertext.commitment;
E::pairing(u, z_i)
})
.collect::<Vec<_>>();
decryption_shares
.enumerate()
.map(
|(decrypter_index, decryption_share)| DecryptionShareSimple {
decrypter_index,
decryption_share,
},
)
.collect::<Vec<_>>()
}

#[cfg(test)]
Expand Down
1 change: 1 addition & 0 deletions tpke/benches/benchmarks.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

7 changes: 5 additions & 2 deletions tpke/benches/tpke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ impl SetupSimple {
.collect();

let pub_contexts = contexts[0].clone().public_decryption_contexts;
let lagrange = prepare_combine_simple::<E>(&pub_contexts);
let domain: Vec<Fr> = pub_contexts.iter().map(|c| c.domain).collect();
let lagrange = prepare_combine_simple::<E>(&domain);

let shared_secret =
share_combine_simple::<E>(&decryption_shares, &lagrange);
Expand Down Expand Up @@ -203,7 +204,9 @@ pub fn bench_share_prepare(c: &mut Criterion) {
};
let simple = {
let setup = SetupSimple::new(shares_num, msg_size, rng);
move || black_box(prepare_combine_simple(&setup.pub_contexts))
let domain: Vec<Fr> =
setup.pub_contexts.iter().map(|c| c.domain).collect();
move || black_box(prepare_combine_simple::<E>(&domain))
};

group.bench_function(
Expand Down
5 changes: 2 additions & 3 deletions tpke/src/combine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,11 @@ pub fn prepare_combine_fast<E: PairingEngine>(
}

pub fn prepare_combine_simple<E: PairingEngine>(
pub_contexts: &[PublicDecryptionContextSimple<E>],
domain: &[E::Fr],
) -> Vec<E::Fr> {
let shares_x: Vec<_> = pub_contexts.iter().map(|c| c.domain).collect();
// See https://en.wikipedia.org/wiki/Lagrange_polynomial#Optimal_algorithm
// In this formula x_i = 0, hence numerator is x_m
lagrange_basis_at::<E>(&shares_x, &E::Fr::zero())
lagrange_basis_at::<E>(domain, &E::Fr::zero())
}

/// Calculate lagrange coefficients using optimized formula
Expand Down
2 changes: 0 additions & 2 deletions tpke/src/decryption.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

use crate::*;

use ark_ec::ProjectiveCurve;

#[derive(Debug, Clone)]
pub struct DecryptionShareFast<E: PairingEngine> {
pub decrypter_index: usize,
Expand Down
14 changes: 9 additions & 5 deletions tpke/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,11 +482,14 @@ mod tests {
.iter()
.map(|c| c.create_share(&ciphertext))
.collect();
let lagrange = prepare_combine_simple::<E>(
&contexts[0].public_decryption_contexts,
);
let domain = contexts[0]
.public_decryption_contexts
.iter()
.map(|c| c.domain)
.collect::<Vec<_>>();
let lagrange = prepare_combine_simple::<E>(&domain);

let shared_secret =
let shared_secret =
share_combine_simple::<E>(&decryption_shares, &lagrange);

test_ciphertext_validation_fails(msg, aad, &ciphertext, &shared_secret);
Expand Down Expand Up @@ -549,7 +552,8 @@ mod tests {
pub_contexts: &[PublicDecryptionContextSimple<E>],
decryption_shares: &[DecryptionShareSimple<E>],
) -> E::Fqk {
let lagrange = prepare_combine_simple::<E>(pub_contexts);
let domain = pub_contexts.iter().map(|c| c.domain).collect::<Vec<_>>();
let lagrange = prepare_combine_simple::<E>(&domain);
share_combine_simple::<E>(decryption_shares, &lagrange)
}

Expand Down

0 comments on commit 26fe690

Please sign in to comment.