]> git.codecow.com Git - nano25519.git/commitdiff
Eliminate extra tempvar.
authorChris Duncan <chris@codecow.com>
Sun, 1 Nov 2026 06:26:47 +0000 (23:26 -0700)
committerChris Duncan <chris@codecow.com>
Sun, 1 Nov 2026 06:26:47 +0000 (23:26 -0700)
src/assembly/crypto_verify.ts
src/assembly/ed25519/fe.ts
src/assembly/ed25519/ge.ts
src/assembly/ed25519/p.ts

index 25ed7dd732fa00e8bbff2d90657fdee249f64f4c..4c2baf768f96f74093b83439b912a7789255798d 100644 (file)
@@ -3,10 +3,10 @@
 
 import { BLOCKHASH_BYTELENGTH, KEY_BYTELENGTH } from './constants'
 import { Blake2b } from './ed25519/blake2b'
-import { ge_accept_small_order, ge_double_scalarmult_vartime_to_p3, ge_frombytes, ge_frombytes_negate, ge_is_canonical, ge_cache_odd_multiples, ge_reject_small_order } from './ed25519/ge'
-import { p_cached, p3, p3_sub_p3, p3_tobytes, p3_0 } from './ed25519/p'
+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_0, t_fe_1, t_fe_2, t_fe_3, t_fe_4, t_fe_5, t_fe_6 } from './ed25519/t'
+import { clear_t, t_fe_0, t_fe_1, t_fe_2, t_fe_3, t_fe_4, t_fe_5 } from './ed25519/t'
 import { equalbytes } from './ed25519/utils'
 
 // crypto_hash function
@@ -78,7 +78,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_fe_0, t_fe_1, t_fe_2, t_fe_3, t_fe_4, t_fe_5, t_fe_6)
+       p3_tobytes(check_r, sb_ah, t_fe_0, t_fe_1, t_fe_2, t_fe_3, t_fe_4, t_fe_5)
        clear_t()
 
        return equalbytes(sig, check_r, KEY_BYTELENGTH)
@@ -142,7 +142,7 @@ export function crypto_verify_strict (sig: StaticArray<u8>, M: StaticArray<u8>,
 
        ge_cache_odd_multiples(Ai, A, t_p3, t_fe_0)
        ge_double_scalarmult_vartime_to_p3(sb_ah, h, Ai, S)
-       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)
+       p3_tobytes(check_r, sb_ah, t_fe_0, t_fe_1, t_fe_2, t_fe_3, t_fe_4, t_fe_5)
        clear_t()
        return equalbytes(sig, check_r, KEY_BYTELENGTH)
 }
index 8709623b1933da5f182bc4c32b3b2c509f5e66b7..303d3ca1346586e78e8d14e207ee3c4cc999e197 100644 (file)
@@ -351,38 +351,38 @@ 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, 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_n(t_fe_1, t_fe_0, 2)
-       fe_mul(t_fe_1, z, t_fe_1)
-       fe_mul(t_fe_0, t_fe_0, t_fe_1)
+export function fe_invert (out: FieldElement, z: FieldElement, t_fe_0: FieldElement, t_fe_1: FieldElement, t_fe_2: FieldElement): void {
+       fe_sq(out, z)
+       fe_sq_n(t_fe_0, out, 2)
+       fe_mul(t_fe_0, z, t_fe_0)
+       fe_mul(out, out, t_fe_0)
 
-       fe_sq(t_fe_2, t_fe_0)
-       fe_mul(t_fe_1, t_fe_1, t_fe_2)
-
-       fe_sq_n(t_fe_2, t_fe_1, 5)
-       fe_mul(t_fe_1, t_fe_2, t_fe_1)
+       fe_sq(t_fe_1, out)
+       fe_mul(t_fe_0, t_fe_0, t_fe_1)
 
-       fe_sq_n(t_fe_2, t_fe_1, 10)
-       fe_mul(t_fe_2, t_fe_2, t_fe_1)
+       fe_sq_n(t_fe_1, t_fe_0, 5)
+       fe_mul(t_fe_0, t_fe_1, t_fe_0)
 
-       fe_sq_n(t_fe_3, t_fe_2, 20)
-       fe_mul(t_fe_2, t_fe_3, t_fe_2)
+       fe_sq_n(t_fe_1, t_fe_0, 10)
+       fe_mul(t_fe_1, t_fe_1, t_fe_0)
 
-       fe_sq_n(t_fe_2, t_fe_2, 10)
+       fe_sq_n(t_fe_2, t_fe_1, 20)
        fe_mul(t_fe_1, t_fe_2, t_fe_1)
 
-       fe_sq_n(t_fe_2, t_fe_1, 50)
-       fe_mul(t_fe_2, t_fe_2, t_fe_1)
+       fe_sq_n(t_fe_1, t_fe_1, 10)
+       fe_mul(t_fe_0, t_fe_1, t_fe_0)
 
-       fe_sq_n(t_fe_3, t_fe_2, 100)
-       fe_mul(t_fe_2, t_fe_3, t_fe_2)
+       fe_sq_n(t_fe_1, t_fe_0, 50)
+       fe_mul(t_fe_1, t_fe_1, t_fe_0)
 
-       fe_sq_n(t_fe_2, t_fe_2, 50)
+       fe_sq_n(t_fe_2, t_fe_1, 100)
        fe_mul(t_fe_1, t_fe_2, t_fe_1)
 
-       fe_sq_n(t_fe_1, t_fe_1, 5)
-       fe_mul(out, t_fe_1, t_fe_0)
+       fe_sq_n(t_fe_1, t_fe_1, 50)
+       fe_mul(t_fe_0, t_fe_1, t_fe_0)
+
+       fe_sq_n(t_fe_0, t_fe_0, 5)
+       fe_mul(out, t_fe_0, out)
 }
 
 /**
index 8a02417ad2763935cd7b19fa425615cd13c88b99..2eed48752c3b5b917eeaf5d031d8396d963410f7 100644 (file)
@@ -19,8 +19,8 @@
 */
 import { base } from './base'
 import { base2 } from './base2'
-import { FieldElement, fe, fe_1, fe_add, fe_addsub, fe_cmov, fe_frombytes, fe_isnegative, fe_iszero, fe_mul, fe_mul_sqrtm1, fe_mul_d, fe_mul_pair, fe_neg, fe_pow22523, fe_sq, fe_sub, fe_mul_pair_sqrtm1 } from './fe'
-import { p_cached, p1p1, p1p1_0, p1p1_to_p2, p1p1_to_p3, p2, p2_0, p2_dbl, p3, p3_0, p3_add_cached, p3_add_cached_to_cached, p3_add_precomp, p3_dbl, p3_dbl_to_p3, p3_sub_cached, p3_sub_precomp, p3_to_cached, p3_tobytes, p_precomp, precomp_0 } from './p'
+import { FieldElement, fe, fe_1, fe_add, fe_addsub, fe_cmov, fe_frombytes, fe_isnegative, fe_iszero, fe_mul, fe_mul_d, fe_mul_pair_sqrtm1, fe_mul_sqrtm1, fe_neg, fe_pow22523, fe_sq, fe_sub } from './fe'
+import { p1p1, p1p1_0, p1p1_to_p2, p1p1_to_p3, p2, p2_0, p2_dbl, p3, p3_0, p3_add_cached, p3_add_cached_to_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'
 
 function ge_cmov8_base (t: p_precomp, bp: usize, b: i8): void {
        const isbneg: i8 = (b >> 7) & 1 /* 0: positive; 1: negative */
@@ -303,7 +303,7 @@ export function ge_scalarmult_base_tobytes (S: StaticArray<u8>, a: StaticArray<u
                p1p1_to_p3(h, r)
        }
 
-       p3_tobytes(S, h, t_fe_0, t_fe_1, t_fe_2, t_fe_3, t_fe_4, t_fe_5, t_fe_6)
+       p3_tobytes(S, h, t_fe_0, t_fe_1, t_fe_2, t_fe_3, t_fe_4, t_fe_5)
 
        // clear sensitive data
        p1p1_0(r)
index 429eeea1a7ead125a71e3d380ca408b2cfd7c484..30a8233374d04fc825df94d9704618d509319086 100644 (file)
@@ -2,7 +2,7 @@
 //! SPDX-FileCopyrightText: 2026 Chris Duncan <chris@codecow.com>
 //! SPDX-License-Identifier: ISC
 
-import { FieldElement, fe, fe_0, fe_1, fe_add, fe_addsub, fe_copy, fe_dbl, fe_invert, fe_isnegative, fe_mul, fe_mul_pair_dbl_2d, fe_mul_2d, fe_mul_pair_dbl, fe_mul_pair, fe_mul_pair_2d, fe_sq_pair_dbl, fe_sq_pair, fe_sub, fe_tobytes } from './fe'
+import { FieldElement, fe, fe_0, fe_1, fe_add, fe_addsub, fe_copy, fe_dbl, fe_invert, fe_isnegative, fe_mul, fe_mul_2d, fe_mul_pair, fe_mul_pair_2d, fe_mul_pair_dbl, fe_mul_pair_dbl_2d, fe_sq_pair, fe_sq_pair_dbl, fe_sub, fe_tobytes } from './fe'
 
 /**
  * Base class for building branded subclasses of coordinate systems.
@@ -356,9 +356,9 @@ export function p3_sub_precomp (r: p1p1, p: p3, q: p_precomp): void {
 
 export function p3_tobytes (s: StaticArray<u8>, h: p3,
        reciprocal: FieldElement, x: FieldElement, y: FieldElement,
-       t_fe_0: FieldElement, t_fe_1: FieldElement, t_fe_2: FieldElement, t_fe_3: FieldElement
+       t_fe_0: FieldElement, t_fe_1: FieldElement, t_fe_2: FieldElement
 ): void {
-       fe_invert(reciprocal, h.Z, t_fe_0, t_fe_1, t_fe_2, t_fe_3)
+       fe_invert(reciprocal, h.Z, t_fe_0, t_fe_1, t_fe_2)
        fe_mul_pair(x, h.X, reciprocal, y, h.Y, reciprocal)
        fe_tobytes(s, y, t_fe_0)
        s[31] ^= fe_isnegative(x, t_fe_0) << 7