Skip to content

Commit e823d8a

Browse files
author
Michael Rosenberg
committed
Avoid repeated Elligator inversion computation
1 parent 5e1bc8c commit e823d8a

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

curve25519-dalek/src/lizard/lizard_ristretto.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use digest::{
44
Digest, HashMarker,
55
array::Array,
6-
consts::{U16, U32},
6+
consts::{U8, U16, U32},
77
};
88
use subtle::CtOption;
99

@@ -95,14 +95,15 @@ impl RistrettoPoint {
9595
let jcs = self.to_jacobi_quartic_ristretto();
9696

9797
// Compute the positive solution to e⁻¹ on every point and its dual
98-
let pos_invs = jcs
99-
.iter()
100-
.flat_map(|jc| [jc.e_inv_positive(), jc.dual().e_inv_positive()]);
98+
let pos_invs = Array::<_, U8>::from_iter(
99+
jcs.iter()
100+
.flat_map(|jc| [jc.e_inv_positive(), jc.dual().e_inv_positive()]),
101+
);
101102
// Compute the other solutions to e⁻¹, ie the negatives of the above solutions
102-
let neg_invs = pos_invs.clone().map(|mx| mx.map(|x| -&x));
103+
let neg_invs = pos_invs.iter().map(|mx| mx.map(|x| -&x));
103104
// This cannot panic because jcs is guaranteed to be size 4, and the above iterator expands
104105
// it to size 8
105-
Array::<_, U16>::from_iter(pos_invs.chain(neg_invs)).0
106+
Array::<_, U16>::from_iter(pos_invs.into_iter().chain(neg_invs)).0
106107
}
107108

108109
/// Find a point on the Jacobi quartic associated to each of the four

0 commit comments

Comments
 (0)