]> git.codecow.com Git - nano25519.git/commitdiff
Move up scratch buffers and develop initial naming conventions.
authorChris Duncan <chris@codecow.com>
Fri, 9 Oct 2026 06:23:42 +0000 (23:23 -0700)
committerChris Duncan <chris@codecow.com>
Fri, 9 Oct 2026 06:23:42 +0000 (23:23 -0700)
src/assembly/crypto_verify.ts
src/assembly/ed25519/fe.ts
src/assembly/ed25519/ge.ts
src/assembly/ed25519/p.ts

index 7a04c8d8826ada4b1dff27373fe54a73433ced50..2977e746a298a52f380e8c27f8c4af2daf0935ba 100644 (file)
@@ -31,7 +31,7 @@ const t_fe = StaticArray.fromArray<FieldElement>([fe(), fe(), fe(), fe(), fe(),
  */
 export function crypto_verify_decodepubkey (pub: StaticArray<u8>): ge_p3 | null {
        // fail if public key cannot be decoded
-       return (ge_frombytes_negate_vartime(A, pub) != 0) ? null : A
+       return (ge_frombytes_negate_vartime(A, pub, t_u8x32, t_fe[0], t_fe[1], t_fe[2]) != 0) ? null : A
 }
 
 /**
@@ -61,7 +61,7 @@ export function crypto_verify_donna (sig: StaticArray<u8>, M: StaticArray<u8>, A
        blake2b.init().update(sig, 32).update(pub, KEY_BYTELENGTH).update(M, BLOCKHASH_BYTELENGTH).digest(h)
        sc_reduce(h)
 
-       ge_double_scalarmult_vartime_to_p3(sb_ah, h, A, S)
+       ge_double_scalarmult_vartime_to_p3(sb_ah, h, A, S, t_fe[0])
        ge_p3_tobytes(check_r, sb_ah, t_fe[0], t_fe[1], t_fe[2], t_fe[3], t_fe[4], t_fe[5], t_fe[6])
 
        return equalbytes(sig, check_r, KEY_BYTELENGTH)
@@ -88,7 +88,7 @@ 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_double_scalarmult_vartime_to_p3(sb_ah, h, A, S)
+       ge_double_scalarmult_vartime_to_p3(sb_ah, h, A, S, t_fe[0])
        ge_sub_p3(check, expected_r, sb_ah, t_fe[0], t_ge_cached, t_ge_p1p1)
 
        return ge_has_small_order(check, t_fe[0], t_u8x32)
@@ -116,7 +116,7 @@ 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_double_scalarmult_vartime_to_p3(sb_ah, h, A, S)
+       ge_double_scalarmult_vartime_to_p3(sb_ah, h, A, S, t_fe[0])
        ge_sub_p3(check, expected_r, sb_ah, t_fe[0], t_ge_cached, t_ge_p1p1)
 
        ge_p3_tobytes(check_r, sb_ah, t_fe[0], t_fe[1], t_fe[2], t_fe[3], t_fe[4], t_fe[5], t_fe[6])
@@ -134,7 +134,7 @@ function verify_pubkey (pub: StaticArray<u8>): boolean {
        if (ge_is_canonical(pub) != 0) return false
 
        // fail if public key cannot be decoded
-       if (ge_frombytes_negate_vartime(A, pub) != 0) return false
+       if (ge_frombytes_negate_vartime(A, pub, t_u8x32, t_fe[0], t_fe[1], t_fe[2]) != 0) return false
 
        // fail if public key `k` is small order
        if (ge_has_small_order(A, t_fe[0], t_u8x32) != 0) return false
index 0c00f9c6ae4382ad5ecb3c2b63c93d605dfd7e3b..b8913f37df39f0db3ddba640e282d92ae5dce80a 100644 (file)
@@ -181,51 +181,51 @@ export function fe_frombytes (h: FieldElement, s: StaticArray<u8>): void {
 /**
  * Inversion - sets `out` = 0 if `z` == 0
  */
-export function fe_invert (out: FieldElement, z: FieldElement, t0: FieldElement, t1: FieldElement, t2: FieldElement, t3: FieldElement): void {
-       fe_sq(t0, z)
-       fe_sq(t1, t0)
-       fe_sq(t1, t1)
-       fe_mul(t1, z, t1)
-       fe_mul(t0, t0, t1)
-       fe_sq(t2, t0)
-       fe_mul(t1, t1, t2)
-       fe_sq(t2, t1)
+export function fe_invert (out: FieldElement, z: FieldElement, t_fe_0: FieldElement, t_fe_1: FieldElement, t_fe_2: FieldElement, t_fe_3: FieldElement): void {
+       fe_sq(t_fe_0, z)
+       fe_sq(t_fe_1, t_fe_0)
+       fe_sq(t_fe_1, t_fe_1)
+       fe_mul(t_fe_1, z, t_fe_1)
+       fe_mul(t_fe_0, t_fe_0, t_fe_1)
+       fe_sq(t_fe_2, t_fe_0)
+       fe_mul(t_fe_1, t_fe_1, t_fe_2)
+       fe_sq(t_fe_2, t_fe_1)
        for (let i = 1; i < 5; ++i) {
-               fe_sq(t2, t2)
+               fe_sq(t_fe_2, t_fe_2)
        }
-       fe_mul(t1, t2, t1)
-       fe_sq(t2, t1)
+       fe_mul(t_fe_1, t_fe_2, t_fe_1)
+       fe_sq(t_fe_2, t_fe_1)
        for (let i = 1; i < 10; ++i) {
-               fe_sq(t2, t2)
+               fe_sq(t_fe_2, t_fe_2)
        }
-       fe_mul(t2, t2, t1)
-       fe_sq(t3, t2)
+       fe_mul(t_fe_2, t_fe_2, t_fe_1)
+       fe_sq(t_fe_3, t_fe_2)
        for (let i = 1; i < 20; ++i) {
-               fe_sq(t3, t3)
+               fe_sq(t_fe_3, t_fe_3)
        }
-       fe_mul(t2, t3, t2)
+       fe_mul(t_fe_2, t_fe_3, t_fe_2)
        for (let i = 1; i < 11; ++i) {
-               fe_sq(t2, t2)
+               fe_sq(t_fe_2, t_fe_2)
        }
-       fe_mul(t1, t2, t1)
-       fe_sq(t2, t1)
+       fe_mul(t_fe_1, t_fe_2, t_fe_1)
+       fe_sq(t_fe_2, t_fe_1)
        for (let i = 1; i < 50; ++i) {
-               fe_sq(t2, t2)
+               fe_sq(t_fe_2, t_fe_2)
        }
-       fe_mul(t2, t2, t1)
-       fe_sq(t3, t2)
+       fe_mul(t_fe_2, t_fe_2, t_fe_1)
+       fe_sq(t_fe_3, t_fe_2)
        for (let i = 1; i < 100; ++i) {
-               fe_sq(t3, t3)
+               fe_sq(t_fe_3, t_fe_3)
        }
-       fe_mul(t2, t3, t2)
+       fe_mul(t_fe_2, t_fe_3, t_fe_2)
        for (let i = 1; i < 51; ++i) {
-               fe_sq(t2, t2)
+               fe_sq(t_fe_2, t_fe_2)
        }
-       fe_mul(t1, t2, t1)
+       fe_mul(t_fe_1, t_fe_2, t_fe_1)
        for (let i = 1; i < 6; ++i) {
-               fe_sq(t1, t1)
+               fe_sq(t_fe_1, t_fe_1)
        }
-       fe_mul(out, t1, t0)
+       fe_mul(out, t_fe_1, t_fe_0)
 }
 
 /**
@@ -247,11 +247,11 @@ 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, u8x32_scratch: StaticArray<u8>, t: FieldElement): u8 {
-       fe_tobytes(u8x32_scratch, f, t)
+export function fe_iszero (f: FieldElement, t_u8x32: StaticArray<u8>, t: FieldElement): u8 {
+       fe_tobytes(t_u8x32, f, t)
        let d: i32 = 0
        for (let i: i32 = 0; i < 32; i++) {
-               d |= u8x32_scratch[i]
+               d |= t_u8x32[i]
        }
        d &= 255
        return u8(((d - 1) >> 8) & 1)
@@ -529,50 +529,50 @@ export function fe_neg (h: FieldElement, f: FieldElement): void {
  * returns z^((p-5)/8) = z^(2²⁵²-3)
  * used to compute square roots since we have p=5 (mod 8); see Cohen and Frey.
  */
-export function fe_pow22523 (out: FieldElement, z: FieldElement, t0: FieldElement, t1: FieldElement, t2: FieldElement): void {
-       fe_sq(t0, z)
-       fe_sq(t1, t0)
-       fe_sq(t1, t1)
-       fe_mul(t1, z, t1)
-       fe_mul(t0, t0, t1)
-       fe_sq(t0, t0)
-       fe_mul(t0, t1, t0)
-       fe_sq(t1, t0)
+export function fe_pow22523 (out: FieldElement, z: FieldElement, t_fe_0: FieldElement, t_fe_1: FieldElement, t_fe_2: FieldElement): void {
+       fe_sq(t_fe_0, z)
+       fe_sq(t_fe_1, t_fe_0)
+       fe_sq(t_fe_1, t_fe_1)
+       fe_mul(t_fe_1, z, t_fe_1)
+       fe_mul(t_fe_0, t_fe_0, t_fe_1)
+       fe_sq(t_fe_0, t_fe_0)
+       fe_mul(t_fe_0, t_fe_1, t_fe_0)
+       fe_sq(t_fe_1, t_fe_0)
        for (let i = 1; i < 5; ++i) {
-               fe_sq(t1, t1)
+               fe_sq(t_fe_1, t_fe_1)
        }
-       fe_mul(t0, t1, t0)
-       fe_sq(t1, t0)
+       fe_mul(t_fe_0, t_fe_1, t_fe_0)
+       fe_sq(t_fe_1, t_fe_0)
        for (let i = 1; i < 10; ++i) {
-               fe_sq(t1, t1)
+               fe_sq(t_fe_1, t_fe_1)
        }
-       fe_mul(t1, t1, t0)
-       fe_sq(t2, t1)
+       fe_mul(t_fe_1, t_fe_1, t_fe_0)
+       fe_sq(t_fe_2, t_fe_1)
        for (let i = 1; i < 20; ++i) {
-               fe_sq(t2, t2)
+               fe_sq(t_fe_2, t_fe_2)
        }
-       fe_mul(t1, t2, t1)
+       fe_mul(t_fe_1, t_fe_2, t_fe_1)
        for (let i = 1; i < 11; ++i) {
-               fe_sq(t1, t1)
+               fe_sq(t_fe_1, t_fe_1)
        }
-       fe_mul(t0, t1, t0)
-       fe_sq(t1, t0)
+       fe_mul(t_fe_0, t_fe_1, t_fe_0)
+       fe_sq(t_fe_1, t_fe_0)
        for (let i = 1; i < 50; ++i) {
-               fe_sq(t1, t1)
+               fe_sq(t_fe_1, t_fe_1)
        }
-       fe_mul(t1, t1, t0)
-       fe_sq(t2, t1)
+       fe_mul(t_fe_1, t_fe_1, t_fe_0)
+       fe_sq(t_fe_2, t_fe_1)
        for (let i = 1; i < 100; ++i) {
-               fe_sq(t2, t2)
+               fe_sq(t_fe_2, t_fe_2)
        }
-       fe_mul(t1, t2, t1)
+       fe_mul(t_fe_1, t_fe_2, t_fe_1)
        for (let i = 1; i < 51; ++i) {
-               fe_sq(t1, t1)
+               fe_sq(t_fe_1, t_fe_1)
        }
-       fe_mul(t0, t1, t0)
-       fe_sq(t0, t0)
-       fe_sq(t0, t0)
-       fe_mul(out, t0, z)
+       fe_mul(t_fe_0, t_fe_1, t_fe_0)
+       fe_sq(t_fe_0, t_fe_0)
+       fe_sq(t_fe_0, t_fe_0)
+       fe_mul(out, t_fe_0, z)
 }
 
 /**
@@ -1086,9 +1086,9 @@ 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: FieldElement): void {
-       fe_reduce(t, h)
-       const t_ptr: usize = changetype<usize>(t)
+export function fe_tobytes (s: StaticArray<u8>, h: FieldElement, t_fe: FieldElement): void {
+       fe_reduce(t_fe, h)
+       const t_ptr: usize = changetype<usize>(t_fe)
        const t0 = load<i32>(t_ptr, 0)
        const t1 = load<i32>(t_ptr, 4)
        const t2 = load<i32>(t_ptr, 8)
index 06f669d9c049dfe9bfb1e933eb8a27bf44e01346..5cda5ae3935bd2591eb4160055fcc7a394f1b204 100644 (file)
@@ -91,10 +91,6 @@ const ge_frombytes_negate_vartime_v3: FieldElement = fe()
 const ge_frombytes_negate_vartime_vxx: FieldElement = fe()
 const ge_frombytes_negate_vartime_m_root_check: FieldElement = fe()
 const ge_frombytes_negate_vartime_p_root_check: FieldElement = fe()
-const ge_frombytes_negate_vartime_u8x32_scratch = new StaticArray<u8>(32)
-const ge_frombytes_negate_vartime_fe_scratch_0: FieldElement = fe()
-const ge_frombytes_negate_vartime_fe_scratch_1: FieldElement = fe()
-const ge_frombytes_negate_vartime_fe_scratch_2: FieldElement = fe()
 /**
  * Variable-time point negation converted from byte representation.
  *
@@ -102,7 +98,9 @@ const ge_frombytes_negate_vartime_fe_scratch_2: FieldElement = fe()
  *
  * @returns {i32} 0 if `s` decodes to a valid point, else -1
  */
-export function ge_frombytes_negate_vartime (h: ge_p3, s: StaticArray<u8>): i32 {
+export function ge_frombytes_negate_vartime (h: ge_p3, s: StaticArray<u8>,
+       t_u8x32: StaticArray<u8>, t_fe_0: FieldElement, t_fe_1: FieldElement, t_fe_2: FieldElement
+): i32 {
        const u = ge_frombytes_negate_vartime_u
        const v = ge_frombytes_negate_vartime_v
        const v3 = ge_frombytes_negate_vartime_v3
@@ -110,11 +108,6 @@ export function ge_frombytes_negate_vartime (h: ge_p3, s: StaticArray<u8>): i32
        const m_root_check = ge_frombytes_negate_vartime_m_root_check
        const p_root_check = ge_frombytes_negate_vartime_p_root_check
 
-       const u8x32_scratch = ge_frombytes_negate_vartime_u8x32_scratch
-       const fe_scratch_0 = ge_frombytes_negate_vartime_fe_scratch_0
-       const fe_scratch_1 = ge_frombytes_negate_vartime_fe_scratch_1
-       const fe_scratch_2 = ge_frombytes_negate_vartime_fe_scratch_2
-
        fe_frombytes(h.Y, s)
        fe_1(h.Z)
 
@@ -135,7 +128,7 @@ export function ge_frombytes_negate_vartime (h: ge_p3, s: StaticArray<u8>): i32
        fe_mul(h.X, h.X, u)
 
        // x = (uv⁷)^((q-5)/8)
-       fe_pow22523(h.X, h.X, fe_scratch_0, fe_scratch_1, fe_scratch_2)
+       fe_pow22523(h.X, h.X, t_fe_0, t_fe_1, t_fe_2)
 
        // x = uv³((uv⁷)^((q-5)/8))
        fe_mul(h.X, h.X, v3)
@@ -147,16 +140,16 @@ export function ge_frombytes_negate_vartime (h: ge_p3, s: StaticArray<u8>): i32
 
        // m = vx²-u
        fe_sub(m_root_check, vxx, u)
-       if (fe_iszero(m_root_check, u8x32_scratch, fe_scratch_0) == 0) {
+       if (fe_iszero(m_root_check, t_u8x32, t_fe_0) == 0) {
                // p = vx²+u
                fe_add(p_root_check, vxx, u)
-               if (fe_iszero(p_root_check, u8x32_scratch, fe_scratch_0) == 0) {
+               if (fe_iszero(p_root_check, t_u8x32, t_fe_0) == 0) {
                        return -1
                }
                fe_mul(h.X, h.X, fe_sqrtm1)
        }
 
-       if (fe_isnegative(h.X, fe_scratch_0) == (s[31] >> 7)) {
+       if (fe_isnegative(h.X, t_fe_0) == (s[31] >> 7)) {
                fe_neg(h.X, h.X)
        }
        fe_mul(h.T, h.X, h.Y)
@@ -177,7 +170,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: ge_p3, s: StaticArray<u8>,
-       t0_fe: FieldElement, t1_fe: FieldElement, t2_fe: FieldElement, t_u8x32: StaticArray<u8>
+       t_fe_0: FieldElement, t_fe_1: FieldElement, t_fe_2: FieldElement, t_u8x32: StaticArray<u8>
 ): i32 {
        const u = ge_frombytes_u
        const v = ge_frombytes_v
@@ -202,7 +195,7 @@ export function ge_frombytes (h: ge_p3, s: StaticArray<u8>,
 
        /* x = u((uv)^((q-5)/8)) */
        fe_mul(h.X, u, v)
-       fe_pow22523(h.X, h.X, t0_fe, t1_fe, t2_fe)
+       fe_pow22523(h.X, h.X, t_fe_0, t_fe_1, t_fe_2)
        fe_mul(h.X, u, h.X)
 
        // vxx = vx²
@@ -211,18 +204,18 @@ export function ge_frombytes (h: ge_p3, s: StaticArray<u8>,
 
        // m = vx²-u
        fe_sub(m_root_check, vxx, u)
-       has_m_root = fe_iszero(m_root_check, t_u8x32, t0_fe)
+       has_m_root = fe_iszero(m_root_check, t_u8x32, t_fe_0)
 
        // p = vx²+u
        fe_add(p_root_check, vxx, u)
-       has_p_root = fe_iszero(p_root_check, t_u8x32, t0_fe)
+       has_p_root = fe_iszero(p_root_check, t_u8x32, t_fe_0)
 
        // x√-1
        fe_mul(x_sqrtm1, h.X, fe_sqrtm1)
        fe_cmov(h.X, x_sqrtm1, 1 - has_m_root)
 
        fe_neg(negx, h.X)
-       fe_cmov(h.X, negx, fe_isnegative(h.X, t0_fe) ^ (s[31] >> 7))
+       fe_cmov(h.X, negx, fe_isnegative(h.X, t_fe_0) ^ (s[31] >> 7))
        fe_mul(h.T, h.X, h.Y)
 
        return i32(has_m_root | has_p_root) - 1
@@ -293,7 +286,7 @@ const ge_scalarmult_base_tobytes_t: ge_precomp = new ge_precomp()
  * @param a 32-byte input buffer for scalar
  */
 export function ge_scalarmult_base_tobytes (S: StaticArray<u8>, a: StaticArray<u8>,
-       t0: FieldElement, t1: FieldElement, t2: FieldElement, t3: FieldElement, t4: FieldElement, t5: FieldElement, t6: FieldElement
+       t_fe_0: FieldElement, t_fe_1: FieldElement, t_fe_2: FieldElement, t_fe_3: FieldElement, t_fe_4: FieldElement, t_fe_5: FieldElement, t_fe_6: FieldElement
 ): void {
        const h = ge_scalarmult_base_tobytes_h
        const e = ge_scalarmult_base_tobytes_e
@@ -327,13 +320,13 @@ export function ge_scalarmult_base_tobytes (S: StaticArray<u8>, a: StaticArray<u
                ge_p1p1_to_p3(h, r)
        }
 
-       ge_p3_dbl(r, h, t0)
+       ge_p3_dbl(r, h, t_fe_0)
        ge_p1p1_to_p2(s, r)
-       ge_p2_dbl(r, s, t0)
+       ge_p2_dbl(r, s, t_fe_0)
        ge_p1p1_to_p2(s, r)
-       ge_p2_dbl(r, s, t0)
+       ge_p2_dbl(r, s, t_fe_0)
        ge_p1p1_to_p2(s, r)
-       ge_p2_dbl(r, s, t0)
+       ge_p2_dbl(r, s, t_fe_0)
        ge_p1p1_to_p3(h, r)
 
        // base pointer offset = 4 bytes * 12 values * 3 fe * 8 ge = 1152 bytes
@@ -344,7 +337,7 @@ export function ge_scalarmult_base_tobytes (S: StaticArray<u8>, a: StaticArray<u
        }
 
        ge_p3_tobytes(S, h,
-               t0, t1, t2, t3, t4, t5, t6
+               t_fe_0, t_fe_1, t_fe_2, t_fe_3, t_fe_4, t_fe_5, t_fe_6
        )
 
        // clear sensitive data
@@ -353,13 +346,13 @@ export function ge_scalarmult_base_tobytes (S: StaticArray<u8>, a: StaticArray<u
        ge_precomp_0(t)
        ge_p3_0(h)
        e.fill(0)
-       t0.fill(0)
-       t1.fill(0)
-       t2.fill(0)
-       t3.fill(0)
-       t4.fill(0)
-       t5.fill(0)
-       t6.fill(0)
+       t_fe_0.fill(0)
+       t_fe_1.fill(0)
+       t_fe_2.fill(0)
+       t_fe_3.fill(0)
+       t_fe_4.fill(0)
+       t_fe_5.fill(0)
+       t_fe_6.fill(0)
 }
 
 const ge_double_scalarmult_vartime_aslide: StaticArray<i8> = new StaticArray<i8>(256)
@@ -378,7 +371,6 @@ const ge_double_scalarmult_vartime_p: ge_p2 = new ge_p2()
 const ge_double_scalarmult_vartime_t: ge_p1p1 = new ge_p1p1()
 const ge_double_scalarmult_vartime_u: ge_p3 = new ge_p3()
 const ge_double_scalarmult_vartime_A2: ge_p3 = new ge_p3()
-const ge_double_scalarmult_vartime_fe_scratch: FieldElement = fe()
 /**
  * `r = a[A] + b[B]`
  *
@@ -390,7 +382,7 @@ const ge_double_scalarmult_vartime_fe_scratch: FieldElement = fe()
  *
  * Variable-time; only used for signature verification.
  */
-export function ge_double_scalarmult_vartime_to_p3 (r: ge_p3, a: StaticArray<u8>, A: ge_p3, b: StaticArray<u8>): void {
+export function ge_double_scalarmult_vartime_to_p3 (r: ge_p3, a: StaticArray<u8>, A: ge_p3, b: StaticArray<u8>, t_fe: FieldElement): void {
        const Bi = base2
        const aslide = ge_double_scalarmult_vartime_aslide
        const bslide = ge_double_scalarmult_vartime_bslide
@@ -399,7 +391,6 @@ export function ge_double_scalarmult_vartime_to_p3 (r: ge_p3, a: StaticArray<u8>
        const t = ge_double_scalarmult_vartime_t
        const u = ge_double_scalarmult_vartime_u
        const A2 = ge_double_scalarmult_vartime_A2
-       const fe_scratch = ge_double_scalarmult_vartime_fe_scratch
        let i: i32 = 0
 
        slide_vartime(aslide, a)
@@ -407,34 +398,34 @@ export function ge_double_scalarmult_vartime_to_p3 (r: ge_p3, a: StaticArray<u8>
 
        ge_p3_to_cached(Ai[0], A)
 
-       ge_p3_dbl(t, A, fe_scratch)
+       ge_p3_dbl(t, A, t_fe)
        ge_p1p1_to_p3(A2, t)
 
-       ge_add_cached(t, A2, Ai[0], fe_scratch)
+       ge_add_cached(t, A2, Ai[0], t_fe)
        ge_p1p1_to_p3(u, t)
        ge_p3_to_cached(Ai[1], u)
 
-       ge_add_cached(t, A2, Ai[1], fe_scratch)
+       ge_add_cached(t, A2, Ai[1], t_fe)
        ge_p1p1_to_p3(u, t)
        ge_p3_to_cached(Ai[2], u)
 
-       ge_add_cached(t, A2, Ai[2], fe_scratch)
+       ge_add_cached(t, A2, Ai[2], t_fe)
        ge_p1p1_to_p3(u, t)
        ge_p3_to_cached(Ai[3], u)
 
-       ge_add_cached(t, A2, Ai[3], fe_scratch)
+       ge_add_cached(t, A2, Ai[3], t_fe)
        ge_p1p1_to_p3(u, t)
        ge_p3_to_cached(Ai[4], u)
 
-       ge_add_cached(t, A2, Ai[4], fe_scratch)
+       ge_add_cached(t, A2, Ai[4], t_fe)
        ge_p1p1_to_p3(u, t)
        ge_p3_to_cached(Ai[5], u)
 
-       ge_add_cached(t, A2, Ai[5], fe_scratch)
+       ge_add_cached(t, A2, Ai[5], t_fe)
        ge_p1p1_to_p3(u, t)
        ge_p3_to_cached(Ai[6], u)
 
-       ge_add_cached(t, A2, Ai[6], fe_scratch)
+       ge_add_cached(t, A2, Ai[6], t_fe)
        ge_p1p1_to_p3(u, t)
        ge_p3_to_cached(Ai[7], u)
 
@@ -447,11 +438,11 @@ export function ge_double_scalarmult_vartime_to_p3 (r: ge_p3, a: StaticArray<u8>
        }
 
        for (; i >= 0; --i) {
-               ge_p2_dbl(t, p, fe_scratch)
+               ge_p2_dbl(t, p, t_fe)
 
                if (aslide[i] > 0) {
                        ge_p1p1_to_p3(u, t)
-                       ge_add_cached(t, u, Ai[aslide[i] / 2], fe_scratch)
+                       ge_add_cached(t, u, Ai[aslide[i] / 2], t_fe)
                } else if (aslide[i] < 0) {
                        ge_p1p1_to_p3(u, t)
                        ge_sub_cached(t, u, Ai[(-aslide[i]) / 2])
index 655509ff1899ec2c80ec1ee92edc31d58ed49ccc..9f2176f506d8ba6926a9e31871916f3b6baf691e 100644 (file)
@@ -224,11 +224,11 @@ export function ge_sub_precomp (r: ge_p1p1, p: ge_p3, q: ge_precomp): void {
 
 export function ge_p3_tobytes (s: StaticArray<u8>, h: ge_p3,
        reciprocal: FieldElement, x: FieldElement, y: FieldElement,
-       t0: FieldElement, t1: FieldElement, t2: FieldElement, t3: FieldElement
+       t_fe_0: FieldElement, t_fe_1: FieldElement, t_fe_2: FieldElement, t_fe_3: FieldElement
 ): void {
-       fe_invert(reciprocal, h.Z, t0, t1, t2, t3)
+       fe_invert(reciprocal, h.Z, t_fe_0, t_fe_1, t_fe_2, t_fe_3)
        fe_mul(x, h.X, reciprocal)
        fe_mul(y, h.Y, reciprocal)
-       fe_tobytes(s, y, t0)
-       s[31] ^= fe_isnegative(x, t0) << 7
+       fe_tobytes(s, y, t_fe_0)
+       s[31] ^= fe_isnegative(x, t_fe_0) << 7
 }