mirror of
https://github.com/Qortal/pirate-librustzcash.git
synced 2025-11-02 20:37:03 +00:00
Constant-time field inversion
WARNING: THIS IS NOT ACTUALLY CONSTANT TIME YET! The jubjub and bls12_381 crates will replace our constant-time usages, but we NEED to fix ff_derive because other users will expect it to implement the Field trait correctly.
This commit is contained in:
@@ -78,7 +78,7 @@ pub fn random_field_tests<F: Field>() {
|
||||
assert!(z.is_zero());
|
||||
}
|
||||
|
||||
assert!(F::zero().inverse().is_none());
|
||||
assert!(bool::from(F::zero().invert().is_none()));
|
||||
|
||||
// Multiplication by zero
|
||||
{
|
||||
@@ -222,11 +222,11 @@ fn random_squaring_tests<F: Field, R: RngCore>(rng: &mut R) {
|
||||
}
|
||||
|
||||
fn random_inversion_tests<F: Field, R: RngCore>(rng: &mut R) {
|
||||
assert!(F::zero().inverse().is_none());
|
||||
assert!(bool::from(F::zero().invert().is_none()));
|
||||
|
||||
for _ in 0..10000 {
|
||||
let mut a = F::random(rng);
|
||||
let b = a.inverse().unwrap(); // probablistically nonzero
|
||||
let b = a.invert().unwrap(); // probablistically nonzero
|
||||
a.mul_assign(&b);
|
||||
|
||||
assert_eq!(a, F::one());
|
||||
|
||||
Reference in New Issue
Block a user