From 2aca4b22b35cd8e893ac2dc57093614ec752ec43 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Sat, 31 Oct 2026 23:26:47 -0700 Subject: [PATCH] Eliminate extra tempvar. --- src/assembly/crypto_verify.ts | 10 ++++---- src/assembly/ed25519/fe.ts | 44 +++++++++++++++++------------------ src/assembly/ed25519/ge.ts | 6 ++--- src/assembly/ed25519/p.ts | 6 ++--- 4 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/assembly/crypto_verify.ts b/src/assembly/crypto_verify.ts index 25ed7dd..4c2baf7 100644 --- a/src/assembly/crypto_verify.ts +++ b/src/assembly/crypto_verify.ts @@ -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, M: StaticArray, 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, M: StaticArray, 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) } diff --git a/src/assembly/ed25519/fe.ts b/src/assembly/ed25519/fe.ts index 8709623..303d3ca 100644 --- a/src/assembly/ed25519/fe.ts +++ b/src/assembly/ed25519/fe.ts @@ -351,38 +351,38 @@ export function fe_frombytes (h: FieldElement, s: StaticArray): 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) } /** diff --git a/src/assembly/ed25519/ge.ts b/src/assembly/ed25519/ge.ts index 8a02417..2eed487 100644 --- a/src/assembly/ed25519/ge.ts +++ b/src/assembly/ed25519/ge.ts @@ -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, a: StaticArray //! 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, 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 -- 2.52.0