diff options
| author | Nicholas Rodrigues Lordello <[email protected]> | 2025-07-28 17:30:48 +0200 |
|---|---|---|
| committer | Nicholas Rodrigues Lordello <[email protected]> | 2025-07-28 17:30:48 +0200 |
| commit | 6bec1cc17d705c5468a53f63a84d247d1bf03232 (patch) | |
| tree | f7d26695dfe65e64ef41c2caf7f71dcec196ab31 | |
| parent | 96c1a864a7c3cdd5006cef5ae8e30cdca61d303a (diff) | |
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.
| -rw-r--r-- | lib/curves.ml | 28 |
1 files 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 |
