Skip to content

Commit

Permalink
saving work on #54
Browse files Browse the repository at this point in the history
  • Loading branch information
ggkitsas committed Aug 10, 2021
1 parent 3e9eb73 commit 3b17b95
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
26 changes: 21 additions & 5 deletions tpke/src/decryption.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,34 @@ impl<E: PairingEngine> PrivateDecryptionContext<E> {

let mut sum_D_j = vec![E::G1Projective::zero(); num_shares];


println!("bp4");
use ark_ec::msm::VariableBaseMSM;
// sum_D_j = { [\sum_j \alpha_{i,j} ] D_i }
for (D, alpha_j) in izip!(shares.iter(), alpha_ij.iter()) {
for (sum_alpha_D_i, Dij, alpha) in izip!(sum_D_j.iter_mut(), D.iter(), alpha_j.iter()) {
*sum_alpha_D_i += Dij.decryption_share.mul(*alpha);
}
for (D, alpha_j, sum_alpha_D_i) in izip!(shares.iter(), alpha_ij.iter(), sum_D_j.iter_mut())
{
let Dj: Vec<E::G1Affine> = D.iter().map(|Dij| Dij.decryption_share).collect::<Vec<_>>();
let alpha_j: Vec<<<E as ark_ec::PairingEngine>::Fr as PrimeField>::BigInt> = alpha_j.iter().map(|a| a.into_repr()).collect::<Vec<_>>();
*sum_alpha_D_i = VariableBaseMSM::multi_scalar_mul(&Dj, &alpha_j);
}

// sum_D_j = { [\sum_j \alpha_{i,j} ] D_i }
// for (D, alpha_j) in izip!(shares.iter(), alpha_ij.iter()) {
// for (sum_alpha_D_i, Dij, alpha) in izip!(sum_D_j.iter_mut(), D.iter(), alpha_j.iter()) {
// *sum_alpha_D_i += Dij.decryption_share.mul(*alpha);
// }
// }

// e([\sum_j \alpha_{i,j} ] D_i, B_i)
for (D_i, B_i) in izip!(sum_D_j.iter(), blinding_keys.iter()) {
pairings.push((E::G1Prepared::from(D_i.into_affine()), B_i.clone()));
}

E::product_of_pairings(&pairings) == E::Fqk::one()
// E::product_of_pairings(&pairings) == E::Fqk::one()
println!("bp6");
let ret = E::product_of_pairings(&pairings) == E::Fqk::one();
println!("bp7, ret= {}", ret);
return ret;

}
}
20 changes: 20 additions & 0 deletions tpke/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,24 @@ mod tests {
let plaintext = decrypt_with_shared_secret(&ciphertext, &s);
assert!(plaintext == msg)
}

#[test]
fn batch_verify() {
let rng = &mut ark_std::test_rng();
let shares_num = 120;
let threshold = shares_num * 2 / 3;
let num_entities = 120;
let msg: &[u8] = "abc".as_bytes();

let (pubkey, _, contexts) = setup::<E>(threshold, shares_num, num_entities);
let ciphertext = encrypt::<_, E>(msg, pubkey, rng);
let mut shares: Vec<DecryptionShare<E>> = vec![];
for context in contexts.iter() {
shares.push(context.create_share(&ciphertext));
}
let ciphertext = (0..100).map(|_| ciphertext.clone()).collect::<Vec<_>>();
let shares = (0..100).map(|_| shares.clone()).collect::<Vec<_>>();
assert!(contexts[0].batch_verify_decryption_shares(&ciphertext, &shares, rng));
}

}

0 comments on commit 3b17b95

Please sign in to comment.