Skip to content

Commit

Permalink
formatting and clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
maurges committed Jan 25, 2023
1 parent 38691f7 commit 567eb59
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 60 deletions.
76 changes: 47 additions & 29 deletions src/paillier_affine_operation_in_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,10 @@ pub mod interactive {
let modulo_l_e = &two_to_l_e * &aux.rsa_modulo;

let alpha = BigNumber::from_rng(&two_to_l_e, &mut rng);
let beta = BigNumber::from_rng(&(BigNumber::one() << (security.l_y + security.epsilon + 1)), &mut rng);
let beta = BigNumber::from_rng(
&(BigNumber::one() << (security.l_y + security.epsilon + 1)),
&mut rng,
);
let r = gen_inversible(data.key0.n(), &mut rng);
let r_y = gen_inversible(data.key1.n(), &mut rng);
let gamma = BigNumber::from_rng(&modulo_l_e, &mut rng);
Expand Down Expand Up @@ -493,21 +496,21 @@ pub mod non_interactive {
use rand_core::SeedableRng;
let seed = shared_state
.chain_update(aux.s.to_bytes())
.chain_update(&aux.t.to_bytes())
.chain_update(&aux.rsa_modulo.to_bytes())
.chain_update(&data.key0.to_bytes())
.chain_update(&data.key1.to_bytes())
.chain_update(&data.c.to_bytes())
.chain_update(&data.d.to_bytes())
.chain_update(&data.y.to_bytes())
.chain_update(&data.x.to_bytes(true))
.chain_update(&commitment.a.to_bytes())
.chain_update(&commitment.b_x.to_bytes(true))
.chain_update(&commitment.b_y.to_bytes())
.chain_update(&commitment.e.to_bytes())
.chain_update(&commitment.s.to_bytes())
.chain_update(&commitment.f.to_bytes())
.chain_update(&commitment.t.to_bytes())
.chain_update(aux.t.to_bytes())
.chain_update(aux.rsa_modulo.to_bytes())
.chain_update(data.key0.to_bytes())
.chain_update(data.key1.to_bytes())
.chain_update(data.c.to_bytes())
.chain_update(data.d.to_bytes())
.chain_update(data.y.to_bytes())
.chain_update(data.x.to_bytes(true))
.chain_update(commitment.a.to_bytes())
.chain_update(commitment.b_x.to_bytes(true))
.chain_update(commitment.b_y.to_bytes())
.chain_update(commitment.e.to_bytes())
.chain_update(commitment.s.to_bytes())
.chain_update(commitment.f.to_bytes())
.chain_update(commitment.t.to_bytes())
.chain_update((security.l_x as u64).to_le_bytes())
.chain_update((security.l_y as u64).to_le_bytes())
.chain_update((security.epsilon as u64).to_le_bytes())
Expand Down Expand Up @@ -535,7 +538,13 @@ mod test {
Some(BigNumber::from_rng(n, rng))
}

fn run<R: rand_core::RngCore, C: Curve>(mut rng: R, security: super::SecurityParams, plaintext_orig: BigNumber, plaintext_mult: BigNumber, plaintext_add: BigNumber) -> Result<(), crate::common::InvalidProof>
fn run<R: rand_core::RngCore, C: Curve>(
mut rng: R,
security: super::SecurityParams,
plaintext_orig: BigNumber,
plaintext_mult: BigNumber,
plaintext_add: BigNumber,
) -> Result<(), crate::common::InvalidProof>
where
Scalar<C>: FromHash,
{
Expand All @@ -546,8 +555,12 @@ mod test {
let private_key1 = random_key(&mut rng).unwrap();
let key1 = libpaillier::EncryptionKey::from(&private_key1);
let g = generic_ec::Point::<C>::generator();
let (ciphertext, _) = key0.encrypt(affined.to_bytes(), nonce(&mut rng, key0.n())).unwrap();
let (ciphertext_orig, _) = key0.encrypt(plaintext_orig.to_bytes(), nonce(&mut rng, key0.n())).unwrap();
let (ciphertext, _) = key0
.encrypt(affined.to_bytes(), nonce(&mut rng, key0.n()))
.unwrap();
let (ciphertext_orig, _) = key0
.encrypt(plaintext_orig.to_bytes(), nonce(&mut rng, key0.n()))
.unwrap();
let ciphertext_mult = g * convert_scalar(&plaintext_mult);
let nonce_y = nonce(&mut rng, key1.n());
let (ciphertext_add, nonce_y) = key1.encrypt(plaintext_add.to_bytes(), nonce_y).unwrap();
Expand Down Expand Up @@ -599,14 +612,7 @@ mod test {
rng,
)
.unwrap();
super::non_interactive::verify(
shared_state,
&aux,
&data,
&commitment,
&security,
&proof,
)
super::non_interactive::verify(shared_state, &aux, &data, &commitment, &security, &proof)
}
fn passing_test<C: Curve>()
where
Expand Down Expand Up @@ -716,7 +722,13 @@ mod test {
let plaintext_orig = BigNumber::from(100);
let plaintext_mult = (BigNumber::from(1) << (security.l_x + 1)) - 1;
let plaintext_add = BigNumber::from(1) << (security.l_y / 2);
let r = run::<_, generic_ec_curves::rust_crypto::Secp256r1>(rng, security, plaintext_orig, plaintext_mult, plaintext_add);
let r = run::<_, generic_ec_curves::rust_crypto::Secp256r1>(
rng,
security,
plaintext_orig,
plaintext_mult,
plaintext_add,
);
match r {
Ok(()) => true,
Err(crate::common::InvalidProof::RangeCheckFailed(6)) => false,
Expand All @@ -743,7 +755,13 @@ mod test {
let plaintext_orig = BigNumber::from(100);
let plaintext_mult = BigNumber::from(1) << (security.l_x / 2);
let plaintext_add = (BigNumber::from(1) << (security.l_y + 1)) + 1;
let r = run::<_, generic_ec_curves::rust_crypto::Secp256r1>(rng, security, plaintext_orig, plaintext_mult, plaintext_add);
let r = run::<_, generic_ec_curves::rust_crypto::Secp256r1>(
rng,
security,
plaintext_orig,
plaintext_mult,
plaintext_add,
);
match r {
Ok(()) => true,
Err(crate::common::InvalidProof::RangeCheckFailed(7)) => false,
Expand Down
4 changes: 2 additions & 2 deletions src/paillier_blum_modulus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,8 @@ pub mod non_interactive {
for (i, y_ref) in ys.iter_mut().enumerate() {
let seed = shared_state
.clone()
.chain_update(&n.to_bytes())
.chain_update(&commitment.w.to_bytes())
.chain_update(n.to_bytes())
.chain_update(commitment.w.to_bytes())
.chain_update((i as u64).to_le_bytes())
.finalize();
let mut rng = rand_chacha::ChaCha20Rng::from_seed(seed.into());
Expand Down
24 changes: 12 additions & 12 deletions src/paillier_decryption_modulo_q.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ pub mod interactive {
mut rng: R,
) -> Result<(Commitment, PrivateCommitment), ProtocolError> {
let two_to_l_e = BigNumber::one() << (security.l + security.epsilon + 1);
let modulo_l = (BigNumber::one() << security.l + 1) * &aux.rsa_modulo;
let modulo_l = (BigNumber::one() << (security.l + 1)) * &aux.rsa_modulo;
let modulo_l_e = &two_to_l_e * &aux.rsa_modulo;

let alpha = BigNumber::from_rng(&two_to_l_e, &mut rng);
Expand Down Expand Up @@ -303,17 +303,17 @@ pub mod non_interactive {
{
use rand_core::SeedableRng;
let seed = shared_state
.chain_update(&aux.s.to_bytes())
.chain_update(&aux.t.to_bytes())
.chain_update(&aux.rsa_modulo.to_bytes())
.chain_update(&data.q.to_bytes())
.chain_update(&data.key.to_bytes())
.chain_update(&data.c.to_bytes())
.chain_update(&data.x.to_bytes())
.chain_update(&commitment.s.to_bytes())
.chain_update(&commitment.t.to_bytes())
.chain_update(&commitment.a.to_bytes())
.chain_update(&commitment.gamma.to_bytes())
.chain_update(aux.s.to_bytes())
.chain_update(aux.t.to_bytes())
.chain_update(aux.rsa_modulo.to_bytes())
.chain_update(data.q.to_bytes())
.chain_update(data.key.to_bytes())
.chain_update(data.c.to_bytes())
.chain_update(data.x.to_bytes())
.chain_update(commitment.s.to_bytes())
.chain_update(commitment.t.to_bytes())
.chain_update(commitment.a.to_bytes())
.chain_update(commitment.gamma.to_bytes())
.finalize();
let mut rng = rand_chacha::ChaCha20Rng::from_seed(seed.into());
let m = BigNumber::from(2) * &data.q;
Expand Down
31 changes: 14 additions & 17 deletions src/paillier_encryption_in_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,14 +300,14 @@ pub mod non_interactive {
{
use rand_core::SeedableRng;
let seed = shared_state
.chain_update(&aux.s.to_bytes())
.chain_update(&aux.t.to_bytes())
.chain_update(&aux.rsa_modulo.to_bytes())
.chain_update(&data.key.to_bytes())
.chain_update(&data.ciphertext.to_bytes())
.chain_update(&commitment.s.to_bytes())
.chain_update(&commitment.a.to_bytes())
.chain_update(&commitment.c.to_bytes())
.chain_update(aux.s.to_bytes())
.chain_update(aux.t.to_bytes())
.chain_update(aux.rsa_modulo.to_bytes())
.chain_update(data.key.to_bytes())
.chain_update(data.ciphertext.to_bytes())
.chain_update(commitment.s.to_bytes())
.chain_update(commitment.a.to_bytes())
.chain_update(commitment.c.to_bytes())
.finalize();
let mut rng = rand_chacha::ChaCha20Rng::from_seed(seed.into());
let m = BigNumber::from(2) * &security.q;
Expand Down Expand Up @@ -335,7 +335,11 @@ mod test {
use crate::common::InvalidProof;
use crate::unknown_order::BigNumber;

fn run_with<R: rand_core::RngCore>(rng: R, security: super::SecurityParams, plaintext: BigNumber) -> Result<(), crate::common::InvalidProof> {
fn run_with<R: rand_core::RngCore>(
rng: R,
security: super::SecurityParams,
plaintext: BigNumber,
) -> Result<(), crate::common::InvalidProof> {
let p = BigNumber::prime(1024);
let q = BigNumber::prime(1024);
let private_key = libpaillier::DecryptionKey::with_primes(&p, &q).unwrap();
Expand All @@ -362,14 +366,7 @@ mod test {
&security,
rng,
);
super::non_interactive::verify(
shared_state,
&aux,
&data,
&commitment,
&security,
&proof,
)
super::non_interactive::verify(shared_state, &aux, &data, &commitment, &security, &proof)
}

#[test]
Expand Down

0 comments on commit 567eb59

Please sign in to comment.