]> git.codecow.com Git - nano25519.git/commitdiff
Start combining scratch buffers to migrate them to highest level possible and reduce...
authorChris Duncan <chris@zoso.dev>
Fri, 2 Oct 2026 08:32:06 +0000 (01:32 -0700)
committerChris Duncan <chris@zoso.dev>
Fri, 2 Oct 2026 08:32:06 +0000 (01:32 -0700)
src/assembly/ed25519/fe.ts
src/assembly/ed25519/p.ts

index adbd8028d90beb0d0f4622c7f2f81863860a49de..ec1adcda13427e419da7417b8a49d0612d9853a7 100644 (file)
@@ -247,6 +247,7 @@ export function fe_isnegative (f: FieldElement): u8 {
 }
 
 const fe_iszero_s = new StaticArray<u8>(32)
+const fe_iszero_t: FieldElement = fe()
 /**
  * return 1 if f == 0
  * return 0 if f != 0
@@ -256,7 +257,8 @@ const fe_iszero_s = new StaticArray<u8>(32)
  */
 export function fe_iszero (f: FieldElement): u8 {
        const s = fe_iszero_s
-       fe_tobytes(s, f)
+       const t = fe_iszero_t
+       fe_tobytes(s, f, t)
        return sodium_is_zero(s, 32)
 }
 
@@ -1065,7 +1067,6 @@ export function fe_sub (h: FieldElement, f: FieldElement, g: FieldElement): void
        v128.store_lane<i64>(h_ptr, v128.sub<i32>(v128.load(f_ptr, 32), v128.load(g_ptr, 32)), 0, 32)
 }
 
-const fe_tobytes_t: FieldElement = fe()
 /**
  * Goal: Output h0+...+2²⁵⁵ h10-2²⁵⁵ q, which is between 0 and 2²⁵⁵-20.
  * Have h0+...+2²³⁰ h9 between 0 and 2²⁵⁵-1;
@@ -1073,8 +1074,7 @@ const fe_tobytes_t: FieldElement = fe()
  *
  * Goal: Output h0+...+2²³⁰ h9.
  */
-export function fe_tobytes (s: StaticArray<u8>, h: FieldElement): void {
-       const t = fe_tobytes_t
+export function fe_tobytes (s: StaticArray<u8>, h: FieldElement, t: FieldElement): void {
        fe_reduce(t, h)
        const t_ptr: usize = changetype<usize>(t)
        const t0 = load<i32>(t_ptr, 0)
index 726306afddd0e0c7e8d33ad5d67b6b97195dcf0a..4ee65f455ad55e5b96b42df71c389de8238c86b1 100644 (file)
@@ -105,17 +105,19 @@ 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_t: 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 t = ge_p3_tobytes_t
        const recip = ge_p3_tobytes_recip
        const x = ge_p3_tobytes_x
        const y = ge_p3_tobytes_y
        fe_invert(recip, h.Z)
        fe_mul(x, h.X, recip)
        fe_mul(y, h.Y, recip)
-       fe_tobytes(s, y)
+       fe_tobytes(s, y, t)
        s[31] ^= fe_isnegative(x) << 7
 }