Skip to content

Commit 5766a82

Browse files
committed
remove inversions from velu isogeny chain, still work to clean up
1 parent 16e85a0 commit 5766a82

File tree

6 files changed

+271
-86
lines changed

6 files changed

+271
-86
lines changed

src/elliptic/curve.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@ impl<Fq: FpTrait> Curve<Fq> {
2424
}
2525
}
2626

27+
/// Compute a curve from the projective coordinates of (A + 2) / 4 = (A24 : C24)
28+
#[inline]
29+
pub fn curve_from_A24_proj(A24: &Fq, C24: &Fq) -> Self {
30+
// Compute A from (A24 : C24)
31+
let mut A = (*A24) + (*A24);
32+
A -= *C24;
33+
A += A;
34+
A /= *C24;
35+
36+
Self::new(&A)
37+
}
38+
2739
/// Compute the j-invariant of the curve.
2840
pub fn j_invariant(&self) -> Fq {
2941
let mut j = self.A.square();

src/elliptic/three_isogeny_chain.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use super::{curve::Curve, point::PointX};
55
impl<Fq: FqTrait> Curve<Fq> {
66
/// Compute a curve from the projective coordinates of A^±_{24} = (A + 2C : A - 2C)
77
#[inline]
8-
fn curve_from_A_plus_minus(A24_plus: &Fq, A24_minus: &Fq) -> Curve<Fq> {
8+
fn curve_from_A_plus_minus(A24_plus: &Fq, A24_minus: &Fq) -> Self {
99
// Compute A from (A + 2C : A - 2C)
1010
let num = (*A24_plus + *A24_minus).mul2();
1111
let den = *A24_plus - *A24_minus;
@@ -103,7 +103,7 @@ impl<Fq: FqTrait> Curve<Fq> {
103103
kernel: &PointX<Fq>,
104104
n: usize,
105105
images: &mut [PointX<Fq>],
106-
) -> (Curve<Fq>, u32) {
106+
) -> (Self, u32) {
107107
// For codomain computation we track the constants (A + 2C : A - 2C)
108108
let mut A24_plus = self.A + Fq::TWO;
109109
let mut A24_minus = self.A - Fq::TWO;

src/elliptic/two_isogeny_chain.rs

Lines changed: 6 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,6 @@ use fp2::traits::Fp2 as FqTrait;
33
use super::{curve::Curve, point::PointX};
44

55
impl<Fq: FqTrait> Curve<Fq> {
6-
/// Compute a curve from the projective coordinates of (A + 2) / 4 = (A24 : C24)
7-
#[inline]
8-
fn curve_from_A24_proj(A24: &Fq, C24: &Fq) -> Curve<Fq> {
9-
// Compute A from (A24 : C24)
10-
let mut A = (*A24) + (*A24);
11-
A -= *C24;
12-
A += A;
13-
A /= *C24;
14-
15-
Curve::new(&A)
16-
}
17-
18-
/// Compute [2]P in place using projective (A + 2) / 4 = (A24 : C24)
19-
/// Cost: 2S + 4M
20-
#[inline(always)]
21-
fn xdbl_proj(A24: &Fq, C24: &Fq, P: &mut PointX<Fq>) {
22-
let mut t0 = P.X + P.Z;
23-
t0.set_square();
24-
let mut t1 = P.X - P.Z;
25-
t1.set_square();
26-
let t2 = t0 - t1;
27-
t1 *= *C24;
28-
P.X = t0 * t1;
29-
t0 = t2 * (*A24);
30-
t0 += t1;
31-
P.Z = t0 * t2;
32-
}
33-
34-
/// Compute \[2^n\]P in place using projective (A + 2) / 4 = (A24 : C24).
35-
/// Cost: n * (2S + 4M)
36-
fn xdbl_proj_iter(A24: &Fq, C24: &Fq, P: &mut PointX<Fq>, n: usize) {
37-
for _ in 0..n {
38-
Self::xdbl_proj(A24, C24, P);
39-
}
40-
}
41-
426
/// Compute the codomain of the 2-isogeny E -> E/<ker> for ker != (0 : 1)
437
fn two_isogeny_codomain(ker: &PointX<Fq>) -> (Fq, Fq) {
448
let mut A24 = ker.X.square();
@@ -144,7 +108,7 @@ impl<Fq: FqTrait> Curve<Fq> {
144108
n: usize,
145109
images: &mut [PointX<Fq>],
146110
allow_singular: bool,
147-
) -> (Curve<Fq>, u32) {
111+
) -> (Self, u32) {
148112
let mut A24 = self.A24;
149113
let mut C24 = Fq::ONE;
150114

@@ -162,7 +126,7 @@ impl<Fq: FqTrait> Curve<Fq> {
162126
if i == 0 {
163127
// First check if the kernel has the correct order.
164128
let mut inf = ker_step;
165-
Self::xdbl_proj(&A24, &C24, &mut inf);
129+
Self::xdbl_proj(&A24, &C24, &mut inf.X, &mut inf.Z);
166130
if (!ker_step.Z.is_zero() & inf.Z.is_zero()) != u32::MAX {
167131
return (*self, 0);
168132
}
@@ -212,7 +176,7 @@ impl<Fq: FqTrait> Curve<Fq> {
212176
kernel: &PointX<Fq>,
213177
n: usize,
214178
images: &mut [PointX<Fq>],
215-
) -> (Curve<Fq>, u32) {
179+
) -> (Self, u32) {
216180
// For 2-isogenies we represent (A + 2) / 4 projectively as (A24 : C24)
217181
let mut A24 = self.A24;
218182
let mut C24 = Fq::ONE;
@@ -257,13 +221,13 @@ impl<Fq: FqTrait> Curve<Fq> {
257221
let mut tmp = ker_step;
258222

259223
// Ensure that the [2]ker is not (0 : 1)
260-
Self::xdbl_proj(&A24, &C24, &mut tmp);
224+
Self::xdbl_proj(&A24, &C24, &mut tmp.X, &mut tmp.Z);
261225
ok &= !tmp.X.is_zero();
262226

263227
// Ensure that the kernel has exact order
264228
// [2]ker != 0 and [4]ker = 0
265229
ok &= !tmp.Z.is_zero();
266-
Self::xdbl_proj(&A24, &C24, &mut tmp);
230+
Self::xdbl_proj(&A24, &C24, &mut tmp.X, &mut tmp.Z);
267231
ok &= tmp.Z.is_zero();
268232
}
269233

@@ -294,7 +258,7 @@ impl<Fq: FqTrait> Curve<Fq> {
294258

295259
// Ensure the point has order exactly 2
296260
let mut tmp = ker_step;
297-
Self::xdbl_proj(&A24, &C24, &mut tmp);
261+
Self::xdbl_proj(&A24, &C24, &mut tmp.X, &mut tmp.Z);
298262
ok &= tmp.Z.is_zero();
299263

300264
// Compute the codomain from ker_step

0 commit comments

Comments
 (0)