]> git.codecow.com Git - nano25519.git/commitdiff
Reorganize coordinates to bytes as the only p function with scratch buffers.
authorChris Duncan <chris@zoso.dev>
Fri, 2 Oct 2026 10:28:20 +0000 (03:28 -0700)
committerChris Duncan <chris@zoso.dev>
Fri, 2 Oct 2026 10:28:20 +0000 (03:28 -0700)
src/assembly/ed25519/p.ts

index c9d9f6c1f5081939d4cef354c8ae31e9c50845a8..8769b43d781c7e0bc98a94b824508925765ff4b8 100644 (file)
@@ -105,28 +105,6 @@ export function ge_p3_to_cached (r: ge_cached, p: ge_p3): void {
        fe_mul(r.T2d, p.T, ed25519_d2)
 }
 
-const ge_p3_tobytes_fe_scratch_0: FieldElement = fe()
-const ge_p3_tobytes_fe_scratch_1: FieldElement = fe()
-const ge_p3_tobytes_fe_scratch_2: FieldElement = fe()
-const ge_p3_tobytes_fe_scratch_3: FieldElement = fe()
-const ge_p3_tobytes_recip: FieldElement = fe()
-const ge_p3_tobytes_x: FieldElement = fe()
-const ge_p3_tobytes_y: FieldElement = fe()
-export function ge_p3_tobytes (s: StaticArray<u8>, h: ge_p3): void {
-       const fe_scratch_0 = ge_p3_tobytes_fe_scratch_0
-       const fe_scratch_1 = ge_p3_tobytes_fe_scratch_1
-       const fe_scratch_2 = ge_p3_tobytes_fe_scratch_2
-       const fe_scratch_3 = ge_p3_tobytes_fe_scratch_3
-       const recip = ge_p3_tobytes_recip
-       const x = ge_p3_tobytes_x
-       const y = ge_p3_tobytes_y
-       fe_invert(recip, h.Z, fe_scratch_0, fe_scratch_1, fe_scratch_2, fe_scratch_3)
-       fe_mul(x, h.X, recip)
-       fe_mul(y, h.Y, recip)
-       fe_tobytes(s, y, fe_scratch_0)
-       s[31] ^= fe_isnegative(x, fe_scratch_0) << 7
-}
-
 /**
  * r = 2 * p
  */
@@ -244,3 +222,18 @@ export function ge_sub_precomp (r: ge_p1p1, p: ge_p3, q: ge_precomp): void {
        fe_sub(r.Z, p.Z, r.T)
        fe_add(r.T, p.Z, r.T)
 }
+
+const fe_scratch_0: FieldElement = fe()
+const fe_scratch_1: FieldElement = fe()
+const fe_scratch_2: FieldElement = fe()
+const fe_scratch_3: FieldElement = fe()
+const recip: FieldElement = fe()
+const x: FieldElement = fe()
+const y: FieldElement = fe()
+export function ge_p3_tobytes (s: StaticArray<u8>, h: ge_p3): void {
+       fe_invert(recip, h.Z, fe_scratch_0, fe_scratch_1, fe_scratch_2, fe_scratch_3)
+       fe_mul(x, h.X, recip)
+       fe_mul(y, h.Y, recip)
+       fe_tobytes(s, y, fe_scratch_0)
+       s[31] ^= fe_isnegative(x, fe_scratch_0) << 7
+}