]> git.codecow.com Git - nano25519.git/commitdiff
Merge byte conversion into output and rename to reflect new output type.
authorChris Duncan <chris@codecow.com>
Mon, 9 Nov 2026 05:17:54 +0000 (21:17 -0800)
committerChris Duncan <chris@codecow.com>
Mon, 9 Nov 2026 05:17:54 +0000 (21:17 -0800)
src/assembly/crypto_verify.ts
src/assembly/ed25519/ge/double_scalarmult.ts
src/assembly/ed25519/ge/index.ts

index 3bdbb302b0ae123affa92360e3ae4b57964c02f1..11ae07dfd6f73e3c55703a8b53cb8018157a3cc6 100644 (file)
@@ -3,9 +3,8 @@
 
 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 { ge_double_scalarmult_vartime_to_cached } from './ed25519/ge/double_scalarmult'
-import { p3, p3_0, p3_dbl_to_p3, p3_sub_cached_to_p3, p3_tobytes, p_cached } from './ed25519/p'
+import { ge_accept_small_order, ge_cache_odd_multiples, ge_double_scalarmult_vartime_to_bytes, ge_double_scalarmult_vartime_to_cached, ge_frombytes, ge_frombytes_negate, ge_is_canonical, ge_reject_small_order } from './ed25519/ge'
+import { p3, p3_0, p3_dbl_to_p3, p3_sub_cached_to_p3, p_cached } from './ed25519/p'
 import { sc_is_canonical, sc_reduce } from './ed25519/sc'
 import { equalbytes } from './ed25519/utils'
 
@@ -29,8 +28,7 @@ const Ai: StaticArray<p_cached> = StaticArray.fromArray<p_cached>([
 const S = new StaticArray<u8>(32)
 const expected_r = new p3()
 const h = new StaticArray<u8>(64)
-const sb_ah = new p3()
-const sb_ah_cached = new p_cached()
+const sb_ah = new p_cached()
 const check = new p3()
 const check_r = new StaticArray<u8>(32)
 
@@ -77,8 +75,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, Ai, S)
-       p3_tobytes(check_r, sb_ah)
+       ge_double_scalarmult_vartime_to_bytes(check_r, h, Ai, S)
 
        return equalbytes(sig, check_r, KEY_BYTELENGTH)
 }
@@ -106,8 +103,8 @@ export function crypto_verify_sodium (sig: StaticArray<u8>, M: StaticArray<u8>,
 
        p3_dbl_to_p3(A2, A)
        ge_cache_odd_multiples(Ai, A2, A)
-       ge_double_scalarmult_vartime_to_cached(sb_ah_cached, h, Ai, S)
-       p3_sub_cached_to_p3(check, expected_r, sb_ah_cached)
+       ge_double_scalarmult_vartime_to_cached(sb_ah, h, Ai, S)
+       p3_sub_cached_to_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
@@ -141,8 +138,7 @@ export function crypto_verify_strict (sig: StaticArray<u8>, M: StaticArray<u8>,
 
        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)
+       ge_double_scalarmult_vartime_to_bytes(check_r, h, Ai, S)
        return equalbytes(sig, check_r, KEY_BYTELENGTH)
 }
 
index c397a41404b5f2edd3f768cfb56ef1dd2908996f..f3857d901b5b6a09d46fd9405747d614b5395dfa 100644 (file)
@@ -18,7 +18,7 @@
  * - precomp (Duif): (y+x,y-x,2dxy)
 */
 import { base2 as Bi } from '../constants/base2'
-import { p1p1, p1p1_0, p1p1_dbl_to_p1p1, p1p1_to_cached, p1p1_to_p3, p3, p3_add_cached, p3_add_precomp, p3_sub_cached, p3_sub_precomp, p_cached } from '../p'
+import { p1p1, p1p1_0, p1p1_dbl_to_p1p1, p1p1_to_cached, p1p1_to_p3, p3, p3_0, p3_add_cached, p3_add_precomp, p3_sub_cached, p3_sub_precomp, p3_tobytes, p_cached } from '../p'
 
 const aslide: StaticArray<i8> = new StaticArray<i8>(256)
 const bslide: StaticArray<i8> = new StaticArray<i8>(256)
@@ -39,10 +39,12 @@ const u: p3 = new p3()
  *
  * Variable-time; only used for signature verification.
  */
-export function ge_double_scalarmult_vartime_to_p3 (r: p3, a: StaticArray<u8>, Ai: StaticArray<p_cached>, b: StaticArray<u8>): void {
+export function ge_double_scalarmult_vartime_to_bytes (r: StaticArray<u8>, a: StaticArray<u8>, Ai: StaticArray<p_cached>, b: StaticArray<u8>): void {
        ge_double_scalarmult_vartime_to_p1p1(t, a, Ai, b)
-       p1p1_to_p3(r, t)
+       p1p1_to_p3(u, t)
+       p3_tobytes(r, u)
        p1p1_0(t)
+       p3_0(u)
 }
 
 export function ge_double_scalarmult_vartime_to_cached (r: p_cached, a: StaticArray<u8>, Ai: StaticArray<p_cached>, b: StaticArray<u8>): void {
index 0720fbf8e4ce3bc02cc28ea6edf598dbfa7fb21f..892cac9184ffa0ddfbd7ef25b3b8f1c66659583f 100644 (file)
@@ -17,6 +17,6 @@
  * - p1p1 (completed): ((X:Z),(Y:T)) satisfying x=X/Z, y=Y/T
  * - precomp (Duif): (y+x,y-x,2dxy)
 */
-export { ge_double_scalarmult_vartime_to_p3 } from './double_scalarmult'
+export { ge_double_scalarmult_vartime_to_bytes, ge_double_scalarmult_vartime_to_cached } from './double_scalarmult'
 export { ge_accept_small_order, ge_cache_odd_multiples, ge_frombytes, ge_frombytes_negate, ge_is_canonical, ge_reject_small_order } from './ge'
 export { ge_scalarmult_base_tobytes } from './scalarmult_base'