]> git.codecow.com Git - nano25519.git/commitdiff
Remove last temporary from group ops module.
authorChris Duncan <chris@codecow.com>
Tue, 3 Nov 2026 19:35:03 +0000 (11:35 -0800)
committerChris Duncan <chris@codecow.com>
Tue, 3 Nov 2026 19:35:03 +0000 (11:35 -0800)
src/assembly/crypto_verify.ts
src/assembly/ed25519/ge.ts

index e4ae787bacea1b7505fec99a0fc336b500cc3cbf..74276876e8a94bcdbc1d8ec48b231648f78b23d2 100644 (file)
@@ -4,7 +4,7 @@
 import { BLOCKHASH_BYTELENGTH, KEY_BYTELENGTH } from './constants'
 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 { p3, p3_0, p3_dbl_to_p3, p3_sub_p3, p3_tobytes, p_cached } from './ed25519/p'
 import { sc_is_canonical, sc_reduce } from './ed25519/sc'
 import { equalbytes } from './ed25519/utils'
 
@@ -13,6 +13,7 @@ const blake2b = new Blake2b()
 
 // algorithm variables
 const A = new p3()
+const A2 = new p3()
 /** A, 3A, 5A, 7A, 9A, 11A, 13A, 15A */
 const Ai: StaticArray<p_cached> = StaticArray.fromArray<p_cached>([
        new p_cached(),
@@ -42,7 +43,8 @@ export function crypto_verify_decodepubkey (pub: StaticArray<u8>): StaticArray<p
                p3_0(A)
                return null
        }
-       ge_cache_odd_multiples(Ai, A)
+       p3_dbl_to_p3(A2, A)
+       ge_cache_odd_multiples(Ai, A2, A)
        return Ai
 }
 
@@ -100,7 +102,8 @@ 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)
+       p3_dbl_to_p3(A2, A)
+       ge_cache_odd_multiples(Ai, A2, A)
        ge_double_scalarmult_vartime_to_p3(sb_ah, h, Ai, S)
        p3_sub_p3(check, expected_r, sb_ah)
 
@@ -134,7 +137,8 @@ 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)
+       p3_dbl_to_p3(A2, A)
+       ge_cache_odd_multiples(Ai, A2, A)
        ge_double_scalarmult_vartime_to_p3(sb_ah, h, Ai, S)
        p3_tobytes(check_r, sb_ah)
        return equalbytes(sig, check_r, KEY_BYTELENGTH)
index 745c6891991a8713e3fbcbd152ca7c7d9a8c5483..d42348dc7cc78a6ea37a75ff780e4e5b97579fec 100644 (file)
@@ -23,8 +23,6 @@ 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))
@@ -314,14 +312,11 @@ 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): void {
+export function ge_cache_odd_multiples (Ai: StaticArray<p_cached>, A2: p3, A: p3): void {
        p3_to_cached(Ai[0], A)
-       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])
+               p3_add_cached_output_cached(Ai[i + 1], A2, Ai[i])
        }
-       p3_0(t_p3)
 }
 
 const ge_double_scalarmult_vartime_aslide: StaticArray<i8> = new StaticArray<i8>(256)