]> git.codecow.com Git - nano25519.git/commitdiff
Update tobytes names to to_bytes. Draft paired vartime double scalarmult.
authorChris Duncan <chris@codecow.com>
Mon, 9 Nov 2026 15:51:37 +0000 (07:51 -0800)
committerChris Duncan <chris@codecow.com>
Mon, 9 Nov 2026 15:51:37 +0000 (07:51 -0800)
AGENTS.md
src/assembly/crypto_derive.ts
src/assembly/crypto_sign.ts
src/assembly/ed25519/fe.ts
src/assembly/ed25519/ge/double_scalarmult.ts
src/assembly/ed25519/ge/index.ts
src/assembly/ed25519/ge/scalarmult_base.ts
src/assembly/ed25519/p.ts
src/lib/bytes.ts
test/arithmetic.mjs

index c895f058a2fa5b34828ba19bb7ded8b8249ebad9..7d8e5982ceec144b9e6fd112d929a15514984566 100644 (file)
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -74,8 +74,8 @@ removing the comparison would silently accept a mismatched keypair.
 
 What it costs is now the multiplication alone. Each fixed-base multiplication
 ends in an inversion to encode its point, ~5.1 µs of its ~16.5 µs, so
-`crypto_sign` calls `ge_scalarmult_base_tobytes_pair`, which computes `[s]B` and
-`[r]B` and encodes both with `p3_tobytes_pair`, sharing one inversion between
+`crypto_sign` calls `ge_scalarmult_base_to_bytes_pair`, which computes `[s]B` and
+`[r]B` and encodes both with `p3_to_bytes_pair`, sharing one inversion between
 them (Montgomery's trick). The private key is hashed once for both. Measured
 2026-11-08 at module level, best of 9, interleaved: `sign` went from 34.4 to
 29.3 µs, and the derivation's share is ~11 µs of it. The price is order: the
@@ -320,7 +320,7 @@ list in `test/node.mjs` patches both. The array is then frozen and returned as
 `test/node.mjs` asserts the freeze, and so does every patched run.
 
 **Host code that carries a secret is constant time.** A hex private key is
-decoded in `hexToBytes` by arithmetic on each character code, with no table
+decoded in `hexto_bytes` by arithmetic on each character code, with no table
 lookup and no early exit: validity accumulates and is checked once at the end,
 and the error never names the character. A `NIBBLE[char]` lookup measured
 fixed-vs-random |t| 5.5–8.6 against a null control ≤ 0.56. The arithmetic
@@ -472,9 +472,9 @@ length too; a scoped fill or a dropped throw-path scrub fails there.
 **Internal scratch holds key material too, and in shapes a scan will miss.**
 The gotcha above is about the *input* buffers of exported functions. The harder
 case is module-level scratch on a secret path: `ge_scalarmult_base` expands its
-scalar into 64 signed radix-16 digits in `ge_scalarmult_base_tobytes_e`, and
+scalar into 64 signed radix-16 digits in `ge_scalarmult_base_to_bytes_e`, and
 `ge_cmov8_base` copies the selected base-table entry into
-`ge_scalarmult_base_tobytes_t` (then called `minust`). Neither was
+`ge_scalarmult_base_to_bytes_t` (then called `minust`). Neither was
 cleared, so `derive` left the clamped secret scalar behind and `sign` left the
 nonce `r` — enough, with the signature, to recover the key and forge. Both are
 scrubbed now; the rule is that **any** static a secret passes through gets
@@ -492,7 +492,7 @@ Better still, **diff rather than search**. Build a probe with
 instances, call `clearMemory()`, and compare all of memory: every byte that
 differs is input-dependent, whatever its representation. That is how the last
 leftovers were found — the result point's projective coordinates in
-`ge_scalarmult_base_tobytes` and the inversion chain in `p3_tobytes` (then `ge_p3_tobytes`), twelve
+`ge_scalarmult_base_to_bytes` and the inversion chain in `p3_to_bytes` (then `ge_p3_to_bytes`), twelve
 field elements a byte search could never have named — and, after 53a72ed,
 verified gone: memory after `derive` and after `sign` was byte-identical across
 different keys on 2026-10-06, and again on 2026-10-09 after 3c9d8e6 moved the
@@ -511,7 +511,7 @@ and `t`, `scalarmult_base.ts` has `e`, `s`, `t`, `u` and `v`,
 named after it. A value held
 in a module's scratch is clobbered by any call back into that module, so a
 function may call *down* while holding its scratch but never into a function
-that uses the same buffers. `p3_tobytes` hands `t.Z` to `fe_invert` as its
+that uses the same buffers. `p3_to_bytes` hands `t.Z` to `fe_invert` as its
 output; that works only because the inversion runs on `z.ts`'s buffers, which
 is why it lives in a module of its own. Inside that module, `fe_invert`
 relies on `fe_pow22501` leaving `z¹¹` in `t`, while `fe_pow22523` overwrites it.
@@ -523,7 +523,7 @@ anything left there is residue: `fe_0(t_fe)`, `p3_0(t_p3)`, `z_0()`, and the
 `_0` calls at the end of `ge_scalarmult_base`. That function clears its own
 scratch but leaves its result point to the caller, which must clear it once
 encoded, so it is private to its module, and its two callers,
-`ge_scalarmult_base_tobytes` and `ge_scalarmult_base_tobytes_pair`, clear `u`
+`ge_scalarmult_base_to_bytes` and `ge_scalarmult_base_to_bytes_pair`, clear `u`
 and `v` after encoding; `test:module` reports the nonce point's 145 bytes if the
 pair's clear of `v` is dropped. When `t.ts` went, its
 `clear_t()` calls went with it, and nothing replaced them in what is now
index 2fa58aa586e0636b9ed081c9a41b171c76eb011b..ca41099136b4ca88d57511e534d4a79fb6fd4bd4 100644 (file)
@@ -2,7 +2,7 @@
 //! SPDX-License-Identifier: GPL-3.0-or-later
 
 import { Blake2b } from './ed25519/blake2b'
-import { ge_scalarmult_base_tobytes } from './ed25519/ge'
+import { ge_scalarmult_base_to_bytes } from './ed25519/ge'
 import { clamp } from './ed25519/utils'
 
 const PRIVATEKEY_BYTES: i32 = 32
@@ -39,6 +39,6 @@ export function crypto_derive (A: StaticArray<u8>, key: StaticArray<u8>): void {
        clamp(s)
 
        // Perform fixed-base scalar multiplication `[s]B`, output to public key `A`
-       ge_scalarmult_base_tobytes(A, s)
+       ge_scalarmult_base_to_bytes(A, s)
        s.fill(0)
 }
index 42c4c245d392a912aff781188369f7ab893af679..a65850edd82eaa62f1ca3b5e696801f7182737ef 100644 (file)
@@ -3,7 +3,7 @@
 
 import { KEY_BYTELENGTH } from './constants'
 import { Blake2b } from './ed25519/blake2b'
-import { ge_scalarmult_base_tobytes_pair } from './ed25519/ge'
+import { ge_scalarmult_base_to_bytes_pair } from './ed25519/ge'
 import { sc_muladd, sc_reduce } from './ed25519/sc'
 import { clamp } from './ed25519/utils'
 
@@ -64,7 +64,7 @@ export function crypto_sign (RS: StaticArray<u8>, M: StaticArray<u8>, mlen: i32,
 
        // Perform fixed-base scalar multiplications `[s]B` and `[r]B`, output to
        // public key `A` and nonce point `R`, sharing one inversion to encode them
-       ge_scalarmult_base_tobytes_pair(A, s, R, r)
+       ge_scalarmult_base_to_bytes_pair(A, s, R, r)
 
        // Compare `A` to public key
        let c = 0
index 7147a50c4c949f346d51f373a6f10e06c7a95bad..11413200ef1a7d502c5fcd79f8095c553aa043b8 100644 (file)
@@ -301,7 +301,7 @@ export function fe_isnegative (f: FieldElement): u8 {
  * |f| bounded by 1.1x2²⁶,1.1x2²⁵,1.1x2²⁶,1.1x2²⁵,etc.
  */
 export function fe_iszero (f: FieldElement): u8 {
-       fe_tobytes(t_u8x32, f)
+       fe_to_bytes(t_u8x32, f)
        const t_ptr: usize = changetype<usize>(t_u8x32)
        const t0 = v128.load(t_ptr, 0 << 4)
        const t1 = v128.load(t_ptr, 1 << 4)
@@ -1783,7 +1783,7 @@ 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): void {
+export function fe_to_bytes (s: StaticArray<u8>, h: FieldElement): void {
        fe_reduce(t_fe, h)
 
        const t_ptr: usize = changetype<usize>(t_fe)
index a361f8f77e5fc350f7c2245bd13ff09e0fd18da0..87191e534a1bf5556c50f80ae7f62bc7f5b6ce95 100644 (file)
  * - 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_0, p3_add_cached, p3_add_precomp, p3_sub_cached, p3_sub_precomp, p3_tobytes, 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_to_bytes, p3_to_bytes_pair, p_cached } from '../p'
 
 const aslide: StaticArray<i8> = new StaticArray<i8>(256)
 const bslide: StaticArray<i8> = new StaticArray<i8>(256)
 const t: p1p1 = new p1p1()
 const u: p3 = new p3()
+const v: p3 = new p3()
 
 /**
- * `r = enc(a[A] + b[B])`
+ * `S = enc(a[A] + b[B])`
  *
  * where `a = a[0]+256*a[1]+...+256^31 a[31]`
  *
@@ -41,10 +42,10 @@ const u: p3 = new p3()
  *
  * Variable-time; only used for signature verification.
  */
-export function ge_double_scalarmult_vartime_to_bytes (r: StaticArray<u8>, a: StaticArray<u8>, Ai: StaticArray<p_cached>, b: StaticArray<u8>): void {
+export function ge_double_scalarmult_vartime_to_bytes (S: 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(u, t)
-       p3_tobytes(r, u)
+       p3_to_bytes(S, u)
        p1p1_0(t)
        p3_0(u)
 }
@@ -55,6 +56,60 @@ export function ge_double_scalarmult_vartime_to_cached (r: p_cached, a: StaticAr
        p1p1_0(t)
 }
 
+/**
+ * `r = enc(a[A] + b[B])`
+ *
+ * where `a = a[0]+256*a[1]+...+256^31 a[31]`
+ *
+ * and `b = b[0]+256*b[1]+...+256^31 b[31]`
+ *
+ * `Ai` is a precomputed table of odd limb multiples of public key `A` and must
+ * be instantiated by calling `ge_cache_odd_multiples()`.
+ *
+ * `B` is the Ed25519 base point `(x, 4/5)` with `x` positive.
+ *
+ * `enc()` is the point-to-byte encoding algorithm
+ *
+ * Variable-time; only used for signature verification.
+ */
+/**
+ * `S₀ = enc(a₀[A] + b₀[B]); S₁ = enc(a₁[B] + b₁[B])`
+ *
+ * where `aₙ = aₙ[0] + 256aₙ[1] + ... + 256³¹aₙ[31]`
+ *
+ * and `bₙ = bₙ[0] + 256bₙ[1] + ... + 256³¹bₙ[31]`
+ *
+ * `Ai` is a precomputed table of odd limb multiples of public key `A` and must
+ * be instantiated by calling `ge_cache_odd_multiples()`.
+ *
+ * `B` is the Ed25519 base point `(x, 4/5)` with `x` positive.
+ *
+ * `enc()` is the point-to-byte encoding algorithm
+ *
+ * Variable-time; only used for signature verification.
+ *
+ * Two fixed-base scalar multiplications, encoded with one shared inversion. An
+ * encoding is about a third of the cost of one multiplication, nearly all of it
+ * the inversion, so this saves most of an encoding over two calls to
+ * `ge_scalarmult_base_to_bytes`. See `ge_scalarmult_base` and `p3_to_bytes_pair`.
+ *
+ * @param S_0 32-byte output buffer for first scalar * base point
+ * @param a_0 32-byte input buffer for first scalar
+ * @param S_1 32-byte output buffer for second scalar * base point
+ * @param a_1 32-byte input buffer for second scalar
+ */
+export function ge_double_scalarmult_vartime_to_bytes_pair (S_0: StaticArray<u8>, a_0: StaticArray<u8>, Ai: StaticArray<p_cached>, b_0: StaticArray<u8>, S_1: StaticArray<u8>, a_1: StaticArray<u8>, b_1: StaticArray<u8>): void {
+       ge_double_scalarmult_vartime_to_p1p1(t, a_0, Ai, b_0)
+       p1p1_to_p3(u, t)
+       ge_double_scalarmult_vartime_to_p1p1(t, a_1, Ai, b_1)
+       p1p1_to_p3(v, t)
+
+       p3_to_bytes_pair(S_0, u, S_1, v)
+       p1p1_0(t)
+       p3_0(u)
+       p3_0(v)
+}
+
 function ge_double_scalarmult_vartime_to_p1p1 (r: p1p1, a: StaticArray<u8>, Ai: StaticArray<p_cached>, b: StaticArray<u8>): void {
        p1p1_0(r)
 
index 60ff7334e41d1c726ebe1babb4cf60642664a0a6..83c84989340dfc554ec903fdf38e752f1d79a41b 100644 (file)
@@ -19,4 +19,4 @@
 */
 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, ge_scalarmult_base_tobytes_pair } from './scalarmult_base'
+export { ge_scalarmult_base_to_bytes, ge_scalarmult_base_to_bytes_pair } from './scalarmult_base'
index cb39376ae1fa216607cb68c0a6e1974d45d76456..17474e409d459c95dd4e96a3a5b734f99fa4bb21 100644 (file)
@@ -3,7 +3,7 @@
 //! SPDX-License-Identifier: ISC
 
 import { base } from '../constants/base'
-import { p2, p2_0, p2_dbl_to_p2, p2_dbl_to_p3, p3, p3_0, p3_add_precomp_to_p3, p3_dbl_to_p2, p3_tobytes, p3_tobytes_pair, p_precomp, precomp_0 } from '../p'
+import { p2, p2_0, p2_dbl_to_p2, p2_dbl_to_p3, p3, p3_0, p3_add_precomp_to_p3, p3_dbl_to_p2, p3_to_bytes, p3_to_bytes_pair, p_precomp, precomp_0 } from '../p'
 
 const e: usize = changetype<usize>(new StaticArray<i8>(64))
 const s: p2 = new p2()
@@ -87,9 +87,9 @@ function ge_scalarmult_base (h: p3, a: StaticArray<u8>): void {
  * @param S 32-byte output buffer for scalar * base point
  * @param a 32-byte input buffer for scalar
  */
-export function ge_scalarmult_base_tobytes (S: StaticArray<u8>, a: StaticArray<u8>): void {
+export function ge_scalarmult_base_to_bytes (S: StaticArray<u8>, a: StaticArray<u8>): void {
        ge_scalarmult_base(u, a)
-       p3_tobytes(S, u)
+       p3_to_bytes(S, u)
        p3_0(u)
 }
 
@@ -99,17 +99,17 @@ export function ge_scalarmult_base_tobytes (S: StaticArray<u8>, a: StaticArray<u
  * Two fixed-base scalar multiplications, encoded with one shared inversion. An
  * encoding is about a third of the cost of one multiplication, nearly all of it
  * the inversion, so this saves most of an encoding over two calls to
- * `ge_scalarmult_base_tobytes`. See `ge_scalarmult_base` and `p3_tobytes_pair`.
+ * `ge_scalarmult_base_to_bytes`. See `ge_scalarmult_base` and `p3_to_bytes_pair`.
  *
  * @param S_0 32-byte output buffer for first scalar * base point
  * @param a_0 32-byte input buffer for first scalar
  * @param S_1 32-byte output buffer for second scalar * base point
  * @param a_1 32-byte input buffer for second scalar
  */
-export function ge_scalarmult_base_tobytes_pair (S_0: StaticArray<u8>, a_0: StaticArray<u8>, S_1: StaticArray<u8>, a_1: StaticArray<u8>): void {
+export function ge_scalarmult_base_to_bytes_pair (S_0: StaticArray<u8>, a_0: StaticArray<u8>, S_1: StaticArray<u8>, a_1: StaticArray<u8>): void {
        ge_scalarmult_base(u, a_0)
        ge_scalarmult_base(v, a_1)
-       p3_tobytes_pair(S_0, u, S_1, v)
+       p3_to_bytes_pair(S_0, u, S_1, v)
        p3_0(u)
        p3_0(v)
 }
index 86faca0f43129b5f1db1df051f35806ba5b45ce0..f2d0e36e53970b5142756b57db279d5f9f9ab757 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_isnegative, fe_mul, fe_mul_2d, fe_mul_pair, fe_mul_pair_2d, fe_mul_pair_dbl, fe_sq_pair, fe_sq_pair_dbl, fe_sub, fe_tobytes } from './fe'
+import { FieldElement, fe, fe_0, fe_1, fe_add, fe_addsub, fe_copy, fe_dbl, fe_isnegative, fe_mul, fe_mul_2d, fe_mul_pair, fe_mul_pair_2d, fe_mul_pair_dbl, fe_sq_pair, fe_sq_pair_dbl, fe_sub, fe_to_bytes } from './fe'
 import { fe_invert } from './z'
 
 /**
@@ -406,10 +406,10 @@ export function p3_sub_precomp (r: p1p1, p: p3, q: p_precomp): void {
  * s = y + 2²⁵⁵(x mod 2)
  * ```
  */
-export function p3_tobytes (s: StaticArray<u8>, p: p3): void {
+export function p3_to_bytes (s: StaticArray<u8>, p: p3): void {
        fe_invert(t.Z, p.Z)
        fe_mul_pair(t.X, p.X, t.Z, t.Y, p.Y, t.Z)
-       fe_tobytes(s, t.Y)
+       fe_to_bytes(s, t.Y)
        s[31] ^= fe_isnegative(t.X) << 7
        p1p1_0(t)
 }
@@ -434,17 +434,17 @@ export function p3_tobytes (s: StaticArray<u8>, p: p3): void {
  * x₁ = X₁Z₀u, y₁ = Y₁Z₀u
  * ```
  */
-export function p3_tobytes_pair (s_0: StaticArray<u8>, p_0: p3, s_1: StaticArray<u8>, p_1: p3): void {
+export function p3_to_bytes_pair (s_0: StaticArray<u8>, p_0: p3, s_1: StaticArray<u8>, p_1: p3): void {
        fe_mul(t.T, p_0.Z, p_1.Z) // T = Z₀Z₁
        fe_invert(t.Z, t.T) // Z = (Z₀Z₁)⁻¹
        fe_mul_pair(t.X, t.Z, p_1.Z, t.Y, t.Z, p_0.Z) // X = Z₀⁻¹, Y = Z₁⁻¹
 
        fe_mul_pair(t.Z, p_0.X, t.X, t.T, p_0.Y, t.X) // Z = x₀, T = y₀
-       fe_tobytes(s_0, t.T)
+       fe_to_bytes(s_0, t.T)
        s_0[31] ^= fe_isnegative(t.Z) << 7
 
        fe_mul_pair(t.Z, p_1.X, t.Y, t.T, p_1.Y, t.Y) // Z = x₁, T = y₁
-       fe_tobytes(s_1, t.T)
+       fe_to_bytes(s_1, t.T)
        s_1[31] ^= fe_isnegative(t.Z) << 7
 
        p1p1_0(t) // Critical since this function is called in a secret context
index 961576565e6e11d4001f0b7d771c78be42766808..0c042cf467165339cd52c7a24a7d37a85fed6b2f 100644 (file)
@@ -157,7 +157,7 @@ export function bytesToHex (bytes: Uint8Array): string {
 /**
  * Decodes hex string to Bytes.
  */
-function hexToBytes (out: Bytes, hex: string): void {
+function hexto_bytes (out: Bytes, hex: string): void {
        const length = hex.length
        if (length & 1) {
                throw new Nano25519TypeError(`Invalid hexadecimal length ${length}`)
@@ -198,7 +198,7 @@ export function normalize (name: string, byteLengthMin: number, byteLengthMax: n
                        throw new Nano25519TypeError(`Invalid hexadecimal length ${value.length} for ${name}`)
                }
                if (typeof out === 'undefined') out = allocate(value.length >> 1)
-               hexToBytes(out, value)
+               hexto_bytes(out, value)
                return out
        }
 
index b8e3596e800c8b569e7b94a39a1988ca157765bc..993e41cb27936a36ece4276e05abc182cf3c7b54 100644 (file)
@@ -66,9 +66,9 @@ const asc = new URL('node_modules/assemblyscript/bin/asc.js', root).pathname
 /** Wrappers over dedicated buffers, compiled as the probe's entry file. */
 const HARNESS = `
 import './env'
-import { FieldElement, fe, fe_0, fe_1, fe_add, fe_addsub, fe_cmov, fe_copy, fe_dbl, fe_frombytes, fe_isnegative, fe_iszero, fe_mul, fe_mul_2d, fe_mul_d, fe_mul_pair, fe_mul_pair_2d, fe_mul_pair_dbl, fe_mul_pair_dbl_2d, fe_mul_pair_sqrtm1, fe_mul_sqrtm1, fe_neg, fe_reduce, fe_sq, fe_sq_n, fe_sq_pair, fe_sq_pair_dbl, fe_sub, fe_tobytes } from './ed25519/fe'
-import { ge_cache_odd_multiples, ge_double_scalarmult_vartime_to_bytes, ge_double_scalarmult_vartime_to_cached, ge_frombytes, ge_frombytes_negate, ge_accept_small_order, ge_reject_small_order, ge_is_canonical, ge_scalarmult_base_tobytes, ge_scalarmult_base_tobytes_pair } from './ed25519/ge'
-import { p1p1, p1p1_0, p1p1_dbl_to_p1p1, p1p1_to_cached, p1p1_to_p2, p1p1_to_p3, p2, p2_0, p2_dbl_to_p2, p2_dbl_to_p3, p3, p3_0, p3_add_cached, p3_add_cached_to_cached, p3_add_precomp, p3_dbl_to_p2, p3_dbl_to_p3, p3_sub_cached, p3_sub_cached_to_p3, p3_sub_precomp, p3_to_cached, p3_tobytes, p3_tobytes_pair, p_cached, p_precomp, precomp_0 } from './ed25519/p'
+import { FieldElement, fe, fe_0, fe_1, fe_add, fe_addsub, fe_cmov, fe_copy, fe_dbl, fe_frombytes, fe_isnegative, fe_iszero, fe_mul, fe_mul_2d, fe_mul_d, fe_mul_pair, fe_mul_pair_2d, fe_mul_pair_dbl, fe_mul_pair_dbl_2d, fe_mul_pair_sqrtm1, fe_mul_sqrtm1, fe_neg, fe_reduce, fe_sq, fe_sq_n, fe_sq_pair, fe_sq_pair_dbl, fe_sub, fe_to_bytes } from './ed25519/fe'
+import { ge_cache_odd_multiples, ge_double_scalarmult_vartime_to_bytes, ge_double_scalarmult_vartime_to_cached, ge_frombytes, ge_frombytes_negate, ge_accept_small_order, ge_reject_small_order, ge_is_canonical, ge_scalarmult_base_to_bytes, ge_scalarmult_base_to_bytes_pair } from './ed25519/ge'
+import { p1p1, p1p1_0, p1p1_dbl_to_p1p1, p1p1_to_cached, p1p1_to_p2, p1p1_to_p3, p2, p2_0, p2_dbl_to_p2, p2_dbl_to_p3, p3, p3_0, p3_add_cached, p3_add_cached_to_cached, p3_add_precomp, p3_dbl_to_p2, p3_dbl_to_p3, p3_sub_cached, p3_sub_cached_to_p3, p3_sub_precomp, p3_to_cached, p3_to_bytes, p3_to_bytes_pair, p_cached, p_precomp, precomp_0 } from './ed25519/p'
 import { fe_invert, fe_pow22523 } from './ed25519/z'
 import { sc_is_canonical, sc_muladd, sc_reduce } from './ed25519/sc'
 import { verify_pubkey, verify_signature } from './crypto_verify'
@@ -148,7 +148,7 @@ export function ptr (id: i32): usize {
        return 0
 }
 export function fe_frombytes_ (): void { fe_frombytes(FH, U8A) }
-export function fe_tobytes_ (): void { fe_tobytes(U8A, FA) }
+export function fe_to_bytes_ (): void { fe_to_bytes(U8A, FA) }
 export function fe_reduce_ (): void { fe_reduce(FH, FA) }
 export function fe_iszero_ (): i32 { return fe_iszero(FA) }
 export function fe_isnegative_ (): i32 { return fe_isnegative(FA) }
@@ -184,12 +184,12 @@ export function ge_frombytes_ (): i32 { return ge_frombytes(PA, U8A) }
 export function ge_frombytes_negate_ (): i32 { return ge_frombytes_negate(PA, U8A) }
 export function ge_accept_small_order_ (): i32 { return ge_accept_small_order(PA) }
 export function ge_reject_small_order_ (): i32 { return ge_reject_small_order(PA) }
-export function p3_tobytes_ (): void { p3_tobytes(U8B, PA) }
+export function p3_to_bytes_ (): void { p3_to_bytes(U8B, PA) }
 // with alias set, both points are the same buffer
-export function p3_tobytes_pair_ (alias: i32): void { p3_tobytes_pair(U8B, PA, U8C, alias ? PA : PB) }
-export function ge_scalarmult_base_tobytes_ (): void { ge_scalarmult_base_tobytes(U8B, U8A) }
+export function p3_to_bytes_pair_ (alias: i32): void { p3_to_bytes_pair(U8B, PA, U8C, alias ? PA : PB) }
+export function ge_scalarmult_base_to_bytes_ (): void { ge_scalarmult_base_to_bytes(U8B, U8A) }
 // with alias set, both scalars are the same buffer
-export function ge_scalarmult_base_tobytes_pair_ (alias: i32): void { ge_scalarmult_base_tobytes_pair(U8B, U8A, U8C, alias ? U8A : U8D) }
+export function ge_scalarmult_base_to_bytes_pair_ (alias: i32): void { ge_scalarmult_base_to_bytes_pair(U8B, U8A, U8C, alias ? U8A : U8D) }
 // the table of odd multiples is left in AI for the caller to check, as crypto_verify builds it
 export function ge_double_scalarmult_ (): void {
        p3_dbl_to_p3(A2, PA)
@@ -693,8 +693,8 @@ try {
 
        for (const l of [...tightInputs, ...shapes.filter(([s]) => s <= 1.1).map(([, l]) => l)]) {
                const v = mod(value(l))
-               set(FA, l); x.fe_tobytes_()
-               note('fe_tobytes', toLE(bytes(U8A)) === v, l)
+               set(FA, l); x.fe_to_bytes_()
+               note('fe_to_bytes', toLE(bytes(U8A)) === v, l)
                set(FA, l); x.fe_reduce_()
                const r = get(FH)
                note('fe_reduce', value(r) === v && r.slice(0, 10).every((q, i) => q >= 0 && q < 2 ** WIDTH[i]) && padded(FH), l)
@@ -851,8 +851,8 @@ try {
                setProjective(PA, p.map(c => mod(c * lambda)))
                note('ge_reject_small_order on projective points', x.ge_reject_small_order_() === (isSmall(p) ? -1 : 0), k)
                setProjective(PA, p.map(c => mod(c * lambda)))
-               x.p3_tobytes_()
-               note('p3_tobytes', toLE(bytes(U8B)) === toLE(encode(p)), k)
+               x.p3_to_bytes_()
+               note('p3_to_bytes', toLE(bytes(U8B)) === toLE(encode(p)), k)
        }
        // two points sharing one inversion, each in its own scaling, so a swapped
        // Z₀⁻¹ and Z₁⁻¹ cannot cancel, and once the same point in the same buffer.
@@ -866,11 +866,11 @@ try {
                        const [l0, l1] = [scale(), scale()]
                        setProjective(PA, p0.map(c => mod(c * l0)))
                        setProjective(PB, p1.map(c => mod(c * l1)))
-                       x.p3_tobytes_pair_(0)
-                       note('p3_tobytes_pair', toLE(bytes(U8B)) === toLE(encode(p0)) && toLE(bytes(U8C)) === toLE(encode(p1)), k)
+                       x.p3_to_bytes_pair_(0)
+                       note('p3_to_bytes_pair', toLE(bytes(U8B)) === toLE(encode(p0)) && toLE(bytes(U8C)) === toLE(encode(p1)), k)
                        setProjective(PA, p0.map(c => mod(c * l0)))
-                       x.p3_tobytes_pair_(1)
-                       note('p3_tobytes_pair of one point twice', toLE(bytes(U8B)) === toLE(encode(p0)) && toLE(bytes(U8C)) === toLE(encode(p0)), k)
+                       x.p3_to_bytes_pair_(1)
+                       note('p3_to_bytes_pair of one point twice', toLE(bytes(U8B)) === toLE(encode(p0)) && toLE(bytes(U8C)) === toLE(encode(p0)), k)
                }
        }
        // fixed-base multiplication over every signed radix-16 digit at every position
@@ -880,8 +880,8 @@ try {
        for (let k = 0; k < 200; k++) scalars.push(((randomBig(32) & ((1n << 254n) - 8n)) | (1n << 254n)))
        for (const a of scalars) {
                bytes(U8A).set(fromLE(a))
-               x.ge_scalarmult_base_tobytes_()
-               note('ge_scalarmult_base_tobytes', toLE(bytes(U8B)) === toLE(encode(mul(B, a))), a)
+               x.ge_scalarmult_base_to_bytes_()
+               note('ge_scalarmult_base_to_bytes', toLE(bytes(U8B)) === toLE(encode(mul(B, a))), a)
        }
        // the pair, each scalar beside another from the same list, and once with
        // both read from one buffer, since the two multiplications share the digit
@@ -890,10 +890,10 @@ try {
                const a1 = scalars[(i * 7 + 3) % scalars.length]
                bytes(U8A).set(fromLE(a0))
                bytes(U8D).set(fromLE(a1))
-               x.ge_scalarmult_base_tobytes_pair_(0)
-               note('ge_scalarmult_base_tobytes_pair', toLE(bytes(U8B)) === toLE(encode(mul(B, a0))) && toLE(bytes(U8C)) === toLE(encode(mul(B, a1))), [a0, a1])
-               x.ge_scalarmult_base_tobytes_pair_(1)
-               note('ge_scalarmult_base_tobytes_pair of one scalar twice', toLE(bytes(U8B)) === toLE(encode(mul(B, a0))) && toLE(bytes(U8C)) === toLE(encode(mul(B, a0))), a0)
+               x.ge_scalarmult_base_to_bytes_pair_(0)
+               note('ge_scalarmult_base_to_bytes_pair', toLE(bytes(U8B)) === toLE(encode(mul(B, a0))) && toLE(bytes(U8C)) === toLE(encode(mul(B, a1))), [a0, a1])
+               x.ge_scalarmult_base_to_bytes_pair_(1)
+               note('ge_scalarmult_base_to_bytes_pair of one scalar twice', toLE(bytes(U8B)) === toLE(encode(mul(B, a0))) && toLE(bytes(U8C)) === toLE(encode(mul(B, a0))), a0)
        }
        doubleScalarmult(h, note, 400)
        preconditions(h, note)