From 6bec1cc17d705c5468a53f63a84d247d1bf03232 Mon Sep 17 00:00:00 2001 From: Nicholas Rodrigues Lordello Date: Mon, 28 Jul 2025 17:30:48 +0200 Subject: Compute `w^2` and `w^3` Only Once When twisting from E2 to E12, we need to compute `w` coefficients for the twisted coordinates. We now compute this only once, and resuse the value on every `twist` call. --- lib/curves.ml | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/curves.ml b/lib/curves.ml index 1459fcc..cb3d9f1 100644 --- a/lib/curves.ml +++ b/lib/curves.ml @@ -136,30 +136,30 @@ let g2 = "927553665492332455747201965776037880757740193453592970025027978793976877002675564980949289727957565575433344219582"; |] ) -let twist_coords (x, y) = - let open Fields in +let twist_coords = let w = - Fp12.of_coeffs - Fp. + Fields.Fp12.of_coeffs + Fields.Fp. [| zero; one; zero; zero; zero; zero; zero; zero; zero; zero; zero; zero; |] in - let w2 = Fp12.(w * w) in - let w3 = Fp12.(w2 * w) in - let w2inv = Fp12.inv w2 in - let w3inv = Fp12.inv w3 in + let w2 = Fields.Fp12.(w * w) in + let w3 = Fields.Fp12.(w2 * w) in + let w2inv = Fields.Fp12.inv w2 in + let w3inv = Fields.Fp12.inv w3 in let iso a = - let c = Fp2.to_coeffs a in - let c0' = Fp.(c.(0) - c.(1)) in - Fp12.of_coeffs - Fp. + let c = Fields.Fp2.to_coeffs a in + let c0' = Fields.Fp.(c.(0) - c.(1)) in + Fields.Fp12.of_coeffs + Fields.Fp. [| c0'; zero; zero; zero; zero; zero; c.(1); zero; zero; zero; zero; zero; |] in - let nx, ny = (iso x, iso y) in - Fp12.(nx * w2inv, ny * w3inv) + fun (x, y) -> + let nx, ny = (iso x, iso y) in + Fields.Fp12.(nx * w2inv, ny * w3inv) module E2 = Eimpl (struct module F = Fields.Fp2 -- cgit v1.2.3