const sb_ah = new ge_p3()
const check = new ge_p3()
const check_r = new StaticArray<u8>(32)
-const t_ge_cached = new ge_cached()
const t_ge_p1p1 = new ge_p1p1()
+const t_ge_p3 = new ge_p3()
const t_u8x32 = new StaticArray<u8>(32)
/**
ge_p3_cache_odd_multiples(Ai, A, t_ge_p1p1, t_fe_0)
ge_double_scalarmult_vartime_to_p3(sb_ah, h, Ai, S)
- ge_p3_sub_p3(check, expected_r, sb_ah, t_ge_cached, t_ge_p1p1)
+ ge_p3_sub_p3(check, expected_r, sb_ah, t_ge_p3, t_fe_0)
// after cofactoring, `check` should be small order and not malformed in order
// to pass, unlike `verify_pubkey()` and `verify_signature()` below
fe_sub(r.T, r.T, r.Z)
}
+/**
+ * r = p + q
+ *
+ * ```
+ * X = X₃T₃ = ((Y₁+X₁)(Y₂+X₂) - (Y₁-X₁)(Y₂-X₂))(2Z₁Z₂ - 2T₁T₂d)
+ * Y = Y₃Z₃ = ((Y₁+X₁)(Y₂+X₂) + (Y₁-X₁)(Y₂-X₂))(2Z₁Z₂ + 2T₁T₂d)
+ * Z = Z₃T₃ = (2Z₁Z₂ + 2T₁T₂d)(2Z₁Z₂ - 2T₁T₂d)
+ * T = X₃Y₃ = ((Y₁+X₁)(Y₂+X₂) - (Y₁-X₁)(Y₂-X₂))((Y₁+X₁)(Y₂+X₂) + (Y₁-X₁)(Y₂-X₂))
+ * ```
+ */
+export function ge_p3_add_p3 (r: ge_p3, p: ge_p3, q: ge_p3, t_fe: FieldElement): void {
+ fe_addsub(r.X, r.Y, p.Y, p.X) // X = Y₁+X₁, Y = Y₁-X₁
+ fe_addsub(r.Z, r.T, q.Y, q.X) // Z = Y₂+X₂, T = Y₂-X₂
+ fe_mul_dual(r.X, r.X, r.Z, r.Y, r.Y, r.T) // X = (Y₁+X₁)(Y₂+X₂), Y = (Y₁-X₁)(Y₂-X₂)
+ fe_mul(r.T, q.T, ed25519_d2) // T = 2T₂d
+ fe_mul2_dual(r.T, r.T, p.T, r.Z, p.Z, q.Z) // T = 2T₁T₂d, Z = 2Z₁Z₂
+ fe_addsub(r.Y, r.X, r.X, r.Y) // Y = (Y₁+X₁)(Y₂+X₂) + (Y₁-X₁)(Y₂-X₂), X = (Y₁+X₁)(Y₂+X₂) - (Y₁-X₁)(Y₂-X₂)
+ fe_addsub(r.Z, t_fe, r.Z, r.T) // Z = 2Z₁Z₂ + 2T₁T₂d, t = 2Z₁Z₂ - 2T₁T₂d
+
+ fe_mul_dual(r.Y, r.Y, r.Z, r.T, r.X, r.Y)
+ fe_mul_dual(r.X, r.X, t_fe, r.Z, r.Z, t_fe)
+}
+
/**
* `r = 2p`
*
/**
* `r = p - q`
*/
-export function ge_p3_sub_p3 (r: ge_p3, p: ge_p3, q: ge_p3, t_ge_cached: ge_cached, t_ge_p1p1: ge_p1p1): void {
- fe_neg(r.X, q.X)
- fe_copy(r.Y, q.Y)
- fe_copy(r.Z, q.Z)
- fe_neg(r.T, q.T)
+export function ge_p3_sub_p3 (r: ge_p3, p: ge_p3, q: ge_p3, t_p3: ge_p3, t_fe: FieldElement): void {
+ fe_neg(t_p3.X, q.X)
+ fe_copy(t_p3.Y, q.Y)
+ fe_copy(t_p3.Z, q.Z)
+ fe_neg(t_p3.T, q.T)
- ge_p3_to_cached(t_ge_cached, r)
- ge_p3_add_cached(t_ge_p1p1, p, t_ge_cached)
- ge_p1p1_to_p3(r, t_ge_p1p1)
+ ge_p3_add_p3(r, p, t_p3, t_fe)
}
/**