diff --git a/src/paillier_affine_operation_in_range.rs b/src/paillier_affine_operation_in_range.rs index 76f8bfd..626840c 100644 --- a/src/paillier_affine_operation_in_range.rs +++ b/src/paillier_affine_operation_in_range.rs @@ -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); @@ -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()) @@ -535,7 +538,13 @@ mod test { Some(BigNumber::from_rng(n, rng)) } - fn run(mut rng: R, security: super::SecurityParams, plaintext_orig: BigNumber, plaintext_mult: BigNumber, plaintext_add: BigNumber) -> Result<(), crate::common::InvalidProof> + fn run( + mut rng: R, + security: super::SecurityParams, + plaintext_orig: BigNumber, + plaintext_mult: BigNumber, + plaintext_add: BigNumber, + ) -> Result<(), crate::common::InvalidProof> where Scalar: FromHash, { @@ -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::::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(); @@ -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() where @@ -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, @@ -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, diff --git a/src/paillier_blum_modulus.rs b/src/paillier_blum_modulus.rs index 20282f9..ff462f8 100644 --- a/src/paillier_blum_modulus.rs +++ b/src/paillier_blum_modulus.rs @@ -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()); diff --git a/src/paillier_decryption_modulo_q.rs b/src/paillier_decryption_modulo_q.rs index bfab923..f7bb26e 100644 --- a/src/paillier_decryption_modulo_q.rs +++ b/src/paillier_decryption_modulo_q.rs @@ -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); @@ -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; diff --git a/src/paillier_encryption_in_range.rs b/src/paillier_encryption_in_range.rs index 55159fc..ef98aab 100644 --- a/src/paillier_encryption_in_range.rs +++ b/src/paillier_encryption_in_range.rs @@ -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; @@ -335,7 +335,11 @@ mod test { use crate::common::InvalidProof; use crate::unknown_order::BigNumber; - fn run_with(rng: R, security: super::SecurityParams, plaintext: BigNumber) -> Result<(), crate::common::InvalidProof> { + fn run_with( + 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(); @@ -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]