]> git.codecow.com Git - nano25519.git/commitdiff
Move temporary buffers into module-scoped variables.
authorChris Duncan <chris@codecow.com>
Tue, 3 Nov 2026 07:43:01 +0000 (23:43 -0800)
committerChris Duncan <chris@codecow.com>
Tue, 3 Nov 2026 07:43:01 +0000 (23:43 -0800)
src/assembly/crypto_derive.ts
src/assembly/crypto_sign.ts
src/assembly/crypto_verify.ts
src/assembly/ed25519/fe.ts
src/assembly/ed25519/ge.ts
src/assembly/ed25519/p.ts
src/assembly/ed25519/t.ts [deleted file]
src/assembly/ed25519/utils.ts
src/assembly/tests.ts

index 4742d9839ef98db88ae57b8caba20483c4229172..2fa58aa586e0636b9ed081c9a41b171c76eb011b 100644 (file)
@@ -3,7 +3,6 @@
 
 import { Blake2b } from './ed25519/blake2b'
 import { ge_scalarmult_base_tobytes } from './ed25519/ge'
-import { clear_t, t_p3 } from './ed25519/t'
 import { clamp } from './ed25519/utils'
 
 const PRIVATEKEY_BYTES: i32 = 32
@@ -40,7 +39,6 @@ export function crypto_derive (A: StaticArray<u8>, key: StaticArray<u8>): void {
        clamp(s)
 
        // Perform fixed-base scalar multiplication `[s]B`, output to public key `A`
-       ge_scalarmult_base_tobytes(A, s, t_p3)
+       ge_scalarmult_base_tobytes(A, s)
        s.fill(0)
-       clear_t()
 }
index c8ad63488efac88684bad0d0268da1c39359fa15..3f8b7113cfbc6fe8302e166ce63c9c31a5262916 100644 (file)
@@ -6,7 +6,6 @@ import { crypto_derive } from './crypto_derive'
 import { Blake2b } from './ed25519/blake2b'
 import { ge_scalarmult_base_tobytes } from './ed25519/ge'
 import { sc_muladd, sc_reduce } from './ed25519/sc'
-import { clear_t, t_p3 } from './ed25519/t'
 import { clamp } from './ed25519/utils'
 
 // crypto_hash function
@@ -72,8 +71,7 @@ export function crypto_sign (RS: StaticArray<u8>, M: StaticArray<u8>, mlen: i32,
        sc_reduce(r)
 
        // Perform fixed-base scalar multiplication `[r]B`, output to point `R`
-       ge_scalarmult_base_tobytes(R, r, t_p3)
-       clear_t()
+       ge_scalarmult_base_tobytes(R, r)
 
        // Compute challenge hash `blake2b(R || A || M)`, output to `k`
        blake2b.init().update(R, 32).update(A, 32).update(M, mlen).digest(k)
index 714c099a3d0c85a5f0528bb5c870c4e3f3a94e33..e4ae787bacea1b7505fec99a0fc336b500cc3cbf 100644 (file)
@@ -6,7 +6,6 @@ import { Blake2b } from './ed25519/blake2b'
 import { ge_accept_small_order, ge_cache_odd_multiples, ge_double_scalarmult_vartime_to_p3, ge_frombytes, ge_frombytes_negate, ge_is_canonical, ge_reject_small_order } from './ed25519/ge'
 import { p3, p3_0, p3_sub_p3, p3_tobytes, p_cached } from './ed25519/p'
 import { sc_is_canonical, sc_reduce } from './ed25519/sc'
-import { clear_t, t_fe } from './ed25519/t'
 import { equalbytes } from './ed25519/utils'
 
 // crypto_hash function
@@ -31,8 +30,6 @@ const h = new StaticArray<u8>(64)
 const sb_ah = new p3()
 const check = new p3()
 const check_r = new StaticArray<u8>(32)
-const t_p3 = new p3()
-const t_u8x32 = new StaticArray<u8>(32)
 
 /**
  * Verify public key `pub` can be decoded to point `A`. If so, builds a cache
@@ -40,13 +37,12 @@ const t_u8x32 = new StaticArray<u8>(32)
  * @returns null if public key fails to decode, else return pointer to Ai
  */
 export function crypto_verify_decodepubkey (pub: StaticArray<u8>): StaticArray<p_cached> | null {
-       const b = ge_frombytes_negate(A, pub, t_fe, t_u8x32)
-       clear_t()
+       const b = ge_frombytes_negate(A, pub)
        if (b != 0) {
                p3_0(A)
                return null
        }
-       ge_cache_odd_multiples(Ai, A, t_p3, t_fe)
+       ge_cache_odd_multiples(Ai, A)
        return Ai
 }
 
@@ -78,8 +74,7 @@ export function crypto_verify_donna (sig: StaticArray<u8>, M: StaticArray<u8>, A
        sc_reduce(h)
 
        ge_double_scalarmult_vartime_to_p3(sb_ah, h, Ai, S)
-       p3_tobytes(check_r, sb_ah, t_p3)
-       clear_t()
+       p3_tobytes(check_r, sb_ah)
 
        return equalbytes(sig, check_r, KEY_BYTELENGTH)
 }
@@ -105,14 +100,13 @@ export function crypto_verify_sodium (sig: StaticArray<u8>, M: StaticArray<u8>,
        blake2b.init().update(sig, 32).update(pub, 32).update(M, mlen).digest(h)
        sc_reduce(h)
 
-       ge_cache_odd_multiples(Ai, A, t_p3, t_fe)
+       ge_cache_odd_multiples(Ai, A)
        ge_double_scalarmult_vartime_to_p3(sb_ah, h, Ai, S)
-       p3_sub_p3(check, expected_r, sb_ah, t_fe)
+       p3_sub_p3(check, expected_r, sb_ah)
 
        // after cofactoring, `check` should be small order and not malformed in order
        // to pass, unlike `verify_pubkey()` and `verify_signature()` below
-       const b = ge_accept_small_order(check, t_fe, t_u8x32)
-       clear_t()
+       const b = ge_accept_small_order(check)
        if (b != 0) return 0
 
        return 1
@@ -140,10 +134,9 @@ export function crypto_verify_strict (sig: StaticArray<u8>, M: StaticArray<u8>,
        blake2b.init().update(sig, 32).update(pub, 32).update(M, mlen).digest(h)
        sc_reduce(h)
 
-       ge_cache_odd_multiples(Ai, A, t_p3, t_fe)
+       ge_cache_odd_multiples(Ai, A)
        ge_double_scalarmult_vartime_to_p3(sb_ah, h, Ai, S)
-       p3_tobytes(check_r, sb_ah, t_p3)
-       clear_t()
+       p3_tobytes(check_r, sb_ah)
        return equalbytes(sig, check_r, KEY_BYTELENGTH)
 }
 
@@ -162,20 +155,17 @@ export function verify_pubkey (pub: StaticArray<u8>): boolean {
        }
 
        // fail if public key cannot be decoded
-       if (ge_frombytes_negate(A, pub, t_fe, t_u8x32) != 0) {
+       if (ge_frombytes_negate(A, pub) != 0) {
                p3_0(A)
-               clear_t()
                return false
        }
 
        // fail if public key `k` is small order
-       if (ge_reject_small_order(A, t_fe, t_u8x32) != 0) {
+       if (ge_reject_small_order(A) != 0) {
                p3_0(A)
-               clear_t()
                return false
        }
 
-       clear_t()
        return true
 }
 
@@ -200,17 +190,14 @@ export function verify_signature (sig: StaticArray<u8>): boolean {
        }
 
        // fail if nonce `R` does not decode to a valid curve point
-       if (ge_frombytes(expected_r, sig, t_fe, t_u8x32) != 0) {
-               clear_t()
+       if (ge_frombytes(expected_r, sig) != 0) {
                return false
        }
 
        // fail if nonce `R` is small order
-       if (ge_reject_small_order(expected_r, t_fe, t_u8x32) != 0) {
-               clear_t()
+       if (ge_reject_small_order(expected_r) != 0) {
                return false
        }
 
-       clear_t()
        return true
 }
index 0a608ab9799d085a96a897ef92aea9ca82f8433f..0a84e6d58c44f3aa74231f03501bc5be345df3a6 100644 (file)
@@ -17,6 +17,9 @@
  */
 import { load_3, load_4 } from './utils'
 
+const t_fe = fe()
+const t_u8x32 = new StaticArray<u8>(32)
+
 /**
  * Ed25519 curve constant √-1
  *   = 2⁽ᵖ⁻¹⁾⸍⁴ mod `p`
@@ -392,9 +395,11 @@ export function fe_invert (out: FieldElement, z: FieldElement, t_fe_0: FieldElem
  * Preconditions:
  * |f| bounded by 1.1x2²⁶,1.1x2²⁵,1.1x2²⁶,1.1x2²⁵,etc.
  */
-export function fe_isnegative (f: FieldElement, t: FieldElement): u8 {
-       fe_reduce(t, f)
-       return u8(load<i32>(changetype<usize>(t), 0) & 1)
+export function fe_isnegative (f: FieldElement): u8 {
+       fe_reduce(t_fe, f)
+       const isNeg = u8(load<i32>(changetype<usize>(t_fe), 0) & 1)
+       fe_0(t_fe)
+       return isNeg
 }
 
 /**
@@ -404,12 +409,14 @@ export function fe_isnegative (f: FieldElement, t: FieldElement): u8 {
  * Preconditions:
  * |f| bounded by 1.1x2²⁶,1.1x2²⁵,1.1x2²⁶,1.1x2²⁵,etc.
  */
-export function fe_iszero (f: FieldElement, t_fe: FieldElement, t_u8x32: StaticArray<u8>): u8 {
-       fe_tobytes(t_u8x32, f, t_fe)
+export function fe_iszero (f: FieldElement): u8 {
+       fe_tobytes(t_u8x32, f)
        const t_ptr: usize = changetype<usize>(t_u8x32)
        const t0 = v128.load(t_ptr, 0 << 4)
        const t1 = v128.load(t_ptr, 1 << 4)
        const d = v128.or(t0, t1)
+       v128.store(t_ptr, i64x2.splat(0), 0 << 4)
+       v128.store(t_ptr, i64x2.splat(0), 1 << 4)
        return u8(v128.any_true(d)) ^ 1
 }
 
@@ -1885,7 +1892,7 @@ export function fe_sub (h: FieldElement, f: FieldElement, g: FieldElement): void
  *
  * Goal: Output h0+...+2²³⁰ h9.
  */
-export function fe_tobytes (s: StaticArray<u8>, h: FieldElement, t_fe: FieldElement): void {
+export function fe_tobytes (s: StaticArray<u8>, h: FieldElement): void {
        fe_reduce(t_fe, h)
 
        const t_ptr: usize = changetype<usize>(t_fe)
@@ -1900,6 +1907,8 @@ export function fe_tobytes (s: StaticArray<u8>, h: FieldElement, t_fe: FieldElem
        const t8 = load<i32>(t_ptr, 8 << 2)
        const t9 = load<i32>(t_ptr, 9 << 2)
 
+       fe_0(t_fe)
+
        const s_ptr: usize = changetype<usize>(s)
        store<u8>(s_ptr, t0 >> 0, 0)
        store<u8>(s_ptr, t0 >> 8, 1)
index a4c05c213dfb5bb0860fc2ed7e00f7f55e03d3f2..832146472f393c992aae05460ec24a5ad1a0dec8 100644 (file)
@@ -23,6 +23,8 @@ import { FieldElement, fe, fe_1, fe_add, fe_addsub, fe_cmov, fe_frombytes, fe_is
 import { p1p1, p1p1_0, p1p1_to_p2, p1p1_to_p3, p2, p2_0, p2_dbl, p3, p3_0, p3_add_cached, p3_add_cached_output_cached, p3_add_precomp, p3_dbl, p3_dbl_to_p3, p3_sub_cached, p3_sub_precomp, p3_to_cached, p3_tobytes, p_cached, p_precomp, precomp_0 } from './p'
 import { fe_pow22523 } from './pow22523'
 
+const t_p3 = new p3()
+
 function ge_cmov8_base (t: p_precomp, bp: usize, b: i8): void {
        const isbneg: i8 = (b >> 7) & 1 /* 0: positive; 1: negative */
        const babs: i8 = b - (((-isbneg) & b) * (i8(1) << 1))
@@ -84,7 +86,7 @@ const ge_frombytes_x_sqrtm1: FieldElement = fe()
  *
  * @returns {i32} 0 if `s` decodes to a valid point, else -1
  */
-export function ge_frombytes (h: p3, s: StaticArray<u8>, t_fe_0: FieldElement, t_u8x32: StaticArray<u8>): i32 {
+export function ge_frombytes (h: p3, s: StaticArray<u8>): i32 {
        const u = ge_frombytes_u
        const v = ge_frombytes_v
        const vx2 = ge_frombytes_vx2
@@ -123,8 +125,8 @@ export function ge_frombytes (h: p3, s: StaticArray<u8>, t_fe_0: FieldElement, t
        // p = vx²+u
        // m = vx²-u
        fe_addsub(p_root_check, m_root_check, vx2, u)
-       has_p_root = fe_iszero(p_root_check, t_fe_0, t_u8x32)
-       has_m_root = fe_iszero(m_root_check, t_fe_0, t_u8x32)
+       has_p_root = fe_iszero(p_root_check)
+       has_m_root = fe_iszero(m_root_check)
 
        // x = x√-1 if vx² = -u, else x
        fe_cmov(h.X, x_sqrtm1, 1 - has_m_root)
@@ -132,7 +134,7 @@ export function ge_frombytes (h: p3, s: StaticArray<u8>, t_fe_0: FieldElement, t
        // negx = -x
        fe_neg(negx, h.X)
        // x = |x|
-       fe_cmov(h.X, negx, fe_isnegative(h.X, t_fe_0) ^ (s[31] >> 7))
+       fe_cmov(h.X, negx, fe_isnegative(h.X) ^ (s[31] >> 7))
 
        // Create point projection
        fe_mul(h.T, h.X, h.Y)
@@ -145,8 +147,8 @@ export function ge_frombytes (h: p3, s: StaticArray<u8>, t_fe_0: FieldElement, t
  *
  * @returns {i32} 0 if `s` decodes to a valid point, else -1
  */
-export function ge_frombytes_negate (h: p3, s: StaticArray<u8>, t_fe_0: FieldElement, t_u8x32: StaticArray<u8>): i32 {
-       const check = ge_frombytes(h, s, t_fe_0, t_u8x32)
+export function ge_frombytes_negate (h: p3, s: StaticArray<u8>): i32 {
+       const check = ge_frombytes(h, s)
        fe_neg(h.X, h.X)
        fe_neg(h.T, h.T)
        return check
@@ -156,10 +158,10 @@ export function ge_frombytes_negate (h: p3, s: StaticArray<u8>, t_fe_0: FieldEle
  * @param {p3} p
  * @returns 1 if `p` is malformed (`Z = 0`, or `X = Y = 0`), else 0
  */
-function ge_is_malformed (p: p3, t_fe: FieldElement, t_u8x32: StaticArray<u8>): i32 {
-       const x_iszero = fe_iszero(p.X, t_fe, t_u8x32)
-       const y_iszero = fe_iszero(p.Y, t_fe, t_u8x32)
-       const z_iszero = fe_iszero(p.Z, t_fe, t_u8x32)
+function ge_is_malformed (p: p3): i32 {
+       const x_iszero = fe_iszero(p.X)
+       const y_iszero = fe_iszero(p.Y)
+       const z_iszero = fe_iszero(p.Z)
        return ((x_iszero & y_iszero) | z_iszero)
 }
 
@@ -169,18 +171,18 @@ const ge_has_small_order_c: FieldElement = fe()
  * @param {p3} p
  * @returns 1 if `p` has small order, else 0
  */
-function ge_has_small_order (p: p3, t_fe: FieldElement, t_u8x32: StaticArray<u8>): i32 {
+function ge_has_small_order (p: p3): i32 {
        const y_sqrtm1 = ge_has_small_order_y_sqrtm1
        const c = ge_has_small_order_c
 
-       const x_iszero = fe_iszero(p.X, t_fe, t_u8x32)
-       const y_iszero = fe_iszero(p.Y, t_fe, t_u8x32)
+       const x_iszero = fe_iszero(p.X)
+       const y_iszero = fe_iszero(p.Y)
 
        fe_mul_sqrtm1(y_sqrtm1, p.Y)
        fe_sub(c, y_sqrtm1, p.X)
-       const y_sqrtm1_minusx = fe_iszero(c, t_fe, t_u8x32)
+       const y_sqrtm1_minusx = fe_iszero(c)
        fe_add(c, y_sqrtm1, p.X)
-       const y_sqrtm1_plusx = fe_iszero(c, t_fe, t_u8x32)
+       const y_sqrtm1_plusx = fe_iszero(c)
 
        return x_iszero | y_iszero | y_sqrtm1_minusx | y_sqrtm1_plusx
 }
@@ -191,9 +193,9 @@ function ge_has_small_order (p: p3, t_fe: FieldElement, t_u8x32: StaticArray<u8>
  * @param {p3} p
  * @returns 0 if `p` is not malformed and has small order, else -1
  */
-export function ge_accept_small_order (p: p3, t_fe: FieldElement, t_u8x32: StaticArray<u8>): i32 {
-       const malformed = ge_is_malformed(p, t_fe, t_u8x32)
-       const small_order = ge_has_small_order(p, t_fe, t_u8x32)
+export function ge_accept_small_order (p: p3): i32 {
+       const malformed = ge_is_malformed(p)
+       const small_order = ge_has_small_order(p)
        return 0 - (malformed | (small_order ^ 1))
 }
 
@@ -203,9 +205,9 @@ export function ge_accept_small_order (p: p3, t_fe: FieldElement, t_u8x32: Stati
  * @param {p3} p
  * @returns 0 if `p` is not malformed and not small order, else -1
  */
-export function ge_reject_small_order (p: p3, t_fe: FieldElement, t_u8x32: StaticArray<u8>): i32 {
-       const malformed = ge_is_malformed(p, t_fe, t_u8x32)
-       const small_order = ge_has_small_order(p, t_fe, t_u8x32)
+export function ge_reject_small_order (p: p3): i32 {
+       const malformed = ge_is_malformed(p)
+       const small_order = ge_has_small_order(p)
        return 0 - (malformed | small_order)
 }
 
@@ -249,7 +251,7 @@ const ge_scalarmult_base_tobytes_t: p_precomp = new p_precomp()
  * @param S 32-byte output buffer for scalar * base point
  * @param a 32-byte input buffer for scalar
  */
-export function ge_scalarmult_base_tobytes (S: StaticArray<u8>, a: StaticArray<u8>, t_p3: p3): void {
+export function ge_scalarmult_base_tobytes (S: StaticArray<u8>, a: StaticArray<u8>): void {
        const h = ge_scalarmult_base_tobytes_h
        const e = ge_scalarmult_base_tobytes_e
        const r = ge_scalarmult_base_tobytes_r
@@ -298,7 +300,7 @@ export function ge_scalarmult_base_tobytes (S: StaticArray<u8>, a: StaticArray<u
                p1p1_to_p3(h, r)
        }
 
-       p3_tobytes(S, h, t_p3)
+       p3_tobytes(S, h)
 
        // clear sensitive data
        p1p1_0(r)
@@ -312,13 +314,14 @@ export function ge_scalarmult_base_tobytes (S: StaticArray<u8>, a: StaticArray<u
  * Computes a lookup table for multiples of the odd limbs of an extended
  * projective point so it can be cached and reused for performance.
  */
-export function ge_cache_odd_multiples (Ai: StaticArray<p_cached>, A: p3, t_p3: p3, t_fe: FieldElement): void {
+export function ge_cache_odd_multiples (Ai: StaticArray<p_cached>, A: p3): void {
        p3_to_cached(Ai[0], A)
-       p3_dbl_to_p3(t_p3, A, t_fe)
+       p3_dbl_to_p3(t_p3, A)
 
        for (let i = 0; i < 7; i++) {
-               p3_add_cached_output_cached(Ai[i + 1], t_p3, Ai[i], t_fe)
+               p3_add_cached_output_cached(Ai[i + 1], t_p3, Ai[i])
        }
+       p3_0(t_p3)
 }
 
 const ge_double_scalarmult_vartime_aslide: StaticArray<i8> = new StaticArray<i8>(256)
index afb4b7f59ffd368f985b7051536bedd31998ad23..d58ac26e910f2897fd5405acdc92870afb050319 100644 (file)
@@ -56,6 +56,9 @@ export class p_precomp {
        xy2d: FieldElement = fe()
 }
 
+const t_fe = fe()
+const t_p3 = new p3()
+
 export function p2_0 (h: p2): void {
        fe_0(h.X)
        fe_1(h.Y)
@@ -194,7 +197,7 @@ export function p3_add_p3 (r: p3, p: p3, q: p3, t_fe: FieldElement): void {
  * T = 2Z₁² - (Y₁²-X₁²)
  * ```
  */
-export function p3_dbl_to_p3 (r: p3, p: p3, t_fe: FieldElement): void {
+export function p3_dbl_to_p3 (r: p3, p: p3): void {
        fe_add(r.X, p.X, p.Y)
        fe_sq_pair_dbl(r.X, r.X, r.T, p.Z)
        fe_sq_pair(r.Z, p.X, r.Y, p.Y)
@@ -204,6 +207,8 @@ export function p3_dbl_to_p3 (r: p3, p: p3, t_fe: FieldElement): void {
 
        fe_mul_pair(r.X, r.X, t_fe, r.T, r.X, r.Y)
        fe_mul_pair(r.Y, r.Y, r.Z, r.Z, r.Z, t_fe)
+
+       fe_0(t_fe)
 }
 
 /**
@@ -262,7 +267,7 @@ export function p3_add_cached (r: p1p1, p: p3, q: p_cached): void {
  * T2d = 2X₁Y₁d
  * ```
  */
-export function p3_add_cached_output_cached (r: p_cached, p: p3, q: p_cached, t_fe: FieldElement): void {
+export function p3_add_cached_output_cached (r: p_cached, p: p3, q: p_cached): void {
        // p3 + cached
        fe_addsub(r.YplusX, r.YminusX, p.Y, p.X)
        fe_mul_pair(r.YplusX, r.YplusX, q.YplusX, r.YminusX, r.YminusX, q.YminusX)
@@ -274,6 +279,8 @@ export function p3_add_cached_output_cached (r: p_cached, p: p3, q: p_cached, t_
        fe_mul_pair_2d(r.YminusX, r.YminusX, t_fe, r.T2d, r.YminusX, r.YplusX)
        fe_mul_pair(r.YplusX, r.YplusX, r.Z, r.Z, r.Z, t_fe)
        fe_addsub(r.YplusX, r.YminusX, r.YplusX, r.YminusX)
+
+       fe_0(t_fe)
 }
 
 /**
@@ -305,7 +312,7 @@ export function p3_add_precomp (r: p1p1, p: p3, q: p_precomp): void {
  * T = X₃Y₃ = ((Y₁+X₁)(Y₂-X₂) - (Y₁-X₁)(Y₂+X₂))((Y₁+X₁)(Y₂-X₂) + (Y₁-X₁)(Y₂+X₂))
  * ```
  */
-export function p3_sub_p3 (r: p3, p: p3, q: p3, t_fe: FieldElement): void {
+export function p3_sub_p3 (r: p3, p: p3, q: p3): 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_pair(r.X, r.X, r.T, r.Y, r.Y, r.Z) // X = (Y₁+X₁)(Y₂-X₂), Y = (Y₁-X₁)(Y₂+X₂)
@@ -315,6 +322,8 @@ export function p3_sub_p3 (r: p3, p: p3, q: p3, t_fe: FieldElement): void {
 
        fe_mul_pair(r.Y, r.Y, r.Z, r.T, r.X, r.Y)
        fe_mul_pair(r.X, r.X, t_fe, r.Z, r.Z, t_fe)
+
+       fe_0(t_fe)
 }
 
 /**
@@ -354,9 +363,10 @@ export function p3_sub_precomp (r: p1p1, p: p3, q: p_precomp): void {
        fe_addsub(r.T, r.Z, r.Z, r.T)
 }
 
-export function p3_tobytes (s: StaticArray<u8>, h: p3, t_p3: p3): void {
+export function p3_tobytes (s: StaticArray<u8>, h: p3): void {
        fe_invert(t_p3.T, h.Z, t_p3.X, t_p3.Y, t_p3.Z)
        fe_mul_pair(t_p3.X, h.X, t_p3.T, t_p3.Y, h.Y, t_p3.T)
-       fe_tobytes(s, t_p3.Y, t_p3.T)
-       s[31] ^= fe_isnegative(t_p3.X, t_p3.T) << 7
+       fe_tobytes(s, t_p3.Y)
+       s[31] ^= fe_isnegative(t_p3.X) << 7
+       p3_0(t_p3)
 }
diff --git a/src/assembly/ed25519/t.ts b/src/assembly/ed25519/t.ts
deleted file mode 100644 (file)
index a14821c..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-//! SPDX-FileCopyrightText: 2026 Chris Duncan <chris@codecow.com>
-//! SPDX-License-Identifier: GPL-3.0-or-later
-
-/**
- * Shared buffers for holding temporary values. Only import in `crypto_derive`,
- * `crypto_sign`, and `crypto_verify`; they pass scratch buffers to lower
- * functions as `t_` parameters, and they clear all buffers when done with them.
- *
- * Beware nested calls. `crypto_sign` calls `crypto_derive` which overwrites all
- * temporary buffers; this specific call is OK because they never use the
- * buffers at the same time. However, never pass a buffer to a called function
- * if it presently holds a value in the current function.
- */
-import { fe, fe_0 } from './fe'
-import { p3, p3_0 } from './p'
-
-export const t_fe = fe()
-export const t_p3 = new p3()
-
-export function clear_t (): void {
-       fe_0(t_fe)
-       p3_0(t_p3)
-}
index 423479ffa28335290447e7160c0823846f4f69f2..89ffb8af25917a46d1ad445e61cb96176b9b2688 100644 (file)
@@ -1,6 +1,11 @@
 //! SPDX-FileCopyrightText: 2013-2026 Frank Denis <j@pureftpd.org>
 //! SPDX-FileCopyrightText: 2026 Chris Duncan <chris@codecow.com>
 //! SPDX-License-Identifier: ISC
+/**
+ * Functions intended for use by any other arbitrary module in this Ed25519
+ * implementation. As such, it should never contain any imports to avoid any
+ * circular dependencies.
+ */
 
 /**
  * Clears the 3 least significant bits to guarantee multiple of 8 and prevent
index e968c811b500f8679df7811531a56492454896e6..260c9a317bc00c4e0d62884591b380fd0be29e14 100644 (file)
@@ -192,8 +192,6 @@ const FE_ONE: i32 = 2 // byte i set to m
 const FE_PAIR: i32 = 3 // bytes i and j both set to m
 
 const check_fe_iszero_f = fe()
-const check_fe_iszero_t_fe = fe()
-const check_fe_iszero_t_u8x32 = new StaticArray<u8>(KEY_BYTELENGTH)
 
 function fe_case (shape: i32, m: i32, i: i32 = 0, j: i32 = 0): i32 {
        return m | (i << 8) | (j << 13) | (shape << 18)
@@ -218,7 +216,7 @@ function check_fe_iszero (c: i32, zero: bool): void {
                fe_frombytes(check_fe_iszero_f, actual)
        }
 
-       const result = fe_iszero(check_fe_iszero_f, check_fe_iszero_t_fe, check_fe_iszero_t_u8x32)
+       const result = fe_iszero(check_fe_iszero_f)
        if (zero && result != 1) {
                raise(ERROR_FE_ISZERO_SELFTEST_XPASS, c, result)
        }