]> git.codecow.com Git - nano25519.git/commitdiff
Shorten names of point ops and retain ge_ prefix for larger operations.
authorChris Duncan <chris@codecow.com>
Fri, 30 Oct 2026 02:30:03 +0000 (19:30 -0700)
committerChris Duncan <chris@codecow.com>
Fri, 30 Oct 2026 02:30:03 +0000 (19:30 -0700)
src/assembly/crypto_verify.ts
src/assembly/ed25519/base2.ts
src/assembly/ed25519/ge.ts
src/assembly/ed25519/p.ts

index 1ba0f274faee122eccd48d898bae39678ff91a29..fd5616185387a203ef1b675f316cb794010de3d5 100644 (file)
@@ -3,8 +3,8 @@
 
 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_vartime, ge_is_canonical, ge_p3_cache_odd_multiples, ge_reject_small_order } from './ed25519/ge'
-import { ge_cached, ge_p1p1, ge_p3, ge_p3_sub_p3, ge_p3_tobytes } from './ed25519/p'
+import { ge_accept_small_order, ge_double_scalarmult_vartime_to_p3, ge_frombytes, ge_frombytes_negate_vartime, ge_is_canonical, ge_cache_odd_multiples, ge_reject_small_order } from './ed25519/ge'
+import { p_cached, p3, p3_sub_p3, p3_tobytes } 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 { equalbytes } from './ed25519/utils'
@@ -13,37 +13,36 @@ import { equalbytes } from './ed25519/utils'
 const blake2b = new Blake2b()
 
 // algorithm variables
-const A = new ge_p3()
+const A = new p3()
 /** A, 3A, 5A, 7A, 9A, 11A, 13A, 15A */
-const Ai: StaticArray<ge_cached> = StaticArray.fromArray<ge_cached>([
-       new ge_cached(),
-       new ge_cached(),
-       new ge_cached(),
-       new ge_cached(),
-       new ge_cached(),
-       new ge_cached(),
-       new ge_cached(),
-       new ge_cached()
+const Ai: StaticArray<p_cached> = StaticArray.fromArray<p_cached>([
+       new p_cached(),
+       new p_cached(),
+       new p_cached(),
+       new p_cached(),
+       new p_cached(),
+       new p_cached(),
+       new p_cached(),
+       new p_cached()
 ])
 const S = new StaticArray<u8>(32)
-const expected_r = new ge_p3()
+const expected_r = new p3()
 const h = new StaticArray<u8>(64)
-const sb_ah = new ge_p3()
-const check = new ge_p3()
+const sb_ah = new p3()
+const check = new p3()
 const check_r = new StaticArray<u8>(32)
-const t_ge_p1p1 = new ge_p1p1()
-const t_ge_p3 = new ge_p3()
+const t_p3 = new p3()
 const t_u8x32 = new StaticArray<u8>(32)
 
 /**
  * Verify public key `pub` can be decoded.
  * @returns null if public key fails to decode, else return pointer to A
  */
-export function crypto_verify_decodepubkey (pub: StaticArray<u8>): StaticArray<ge_cached> | null {
+export function crypto_verify_decodepubkey (pub: StaticArray<u8>): StaticArray<p_cached> | null {
        const b = ge_frombytes_negate_vartime(A, pub, t_u8x32, t_fe_0, t_fe_1, t_fe_2)
        clear_t()
        if (b != 0) return null
-       ge_p3_cache_odd_multiples(Ai, A, t_fe_0)
+       ge_cache_odd_multiples(Ai, A, t_p3, t_fe_0)
        return Ai
 }
 
@@ -60,7 +59,7 @@ export function crypto_verify_decodepubkey (pub: StaticArray<u8>): StaticArray<g
  * to `A` for the scalar multiplication step before checking `sB = R + hA`.
  * @returns 0 if signature fails to verify, else return 1 if signature is good
  */
-export function crypto_verify_donna (sig: StaticArray<u8>, M: StaticArray<u8>, Ai: StaticArray<ge_cached>, pub: StaticArray<u8>): i32 {
+export function crypto_verify_donna (sig: StaticArray<u8>, M: StaticArray<u8>, Ai: StaticArray<p_cached>, pub: StaticArray<u8>): i32 {
 
        // fail if private scalar `S` is out of range (`2²⁵³ ≤ S`)
        if ((sig[63] & 224) != 0) return 0
@@ -75,7 +74,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)
-       ge_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, t_fe_6)
        clear_t()
 
        return equalbytes(sig, check_r, KEY_BYTELENGTH)
@@ -102,9 +101,9 @@ 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_p3_cache_odd_multiples(Ai, A, t_fe_0)
+       ge_cache_odd_multiples(Ai, A, t_p3, t_fe_0)
        ge_double_scalarmult_vartime_to_p3(sb_ah, h, Ai, S)
-       ge_p3_sub_p3(check, expected_r, sb_ah, t_fe_0)
+       p3_sub_p3(check, expected_r, sb_ah, t_fe_0)
 
        // after cofactoring, `check` should be small order and not malformed in order
        // to pass, unlike `verify_pubkey()` and `verify_signature()` below
@@ -137,9 +136,9 @@ 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_p3_cache_odd_multiples(Ai, A, t_fe_0)
+       ge_cache_odd_multiples(Ai, A, t_p3, t_fe_0)
        ge_double_scalarmult_vartime_to_p3(sb_ah, h, Ai, S)
-       ge_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, t_fe_6)
        clear_t()
        return equalbytes(sig, check_r, KEY_BYTELENGTH)
 }
index 5013de18227d3e52632102daca1cc52174b0a30e..1af361e40a772f0e30f0a201f1a5b3cda5ba9720 100644 (file)
@@ -2,9 +2,9 @@
 //! SPDX-FileCopyrightText: 2026 Chris Duncan <chris@codecow.com>
 //! SPDX-License-Identifier: ISC
 
-import { ge_precomp } from './p'
+import { p_precomp } from './p'
 
-export const base2 = StaticArray.fromArray<ge_precomp>([
+export const base2 = StaticArray.fromArray<p_precomp>([
        {
                yplusx: StaticArray.fromArray<i32>([25967493, -14356035, 29566456, 3660896, -12694345, 4014787, 27544626, -11754271, -6079156, 2047605, 0, 0]),
                yminusx: StaticArray.fromArray<i32>([-12545711, 934262, -2722910, 3049990, -727428, 9406986, 12720692, 5043384, 19500929, -15469378, 0, 0]),
index 453e9c7a5b3a67450309c75898e7f0fe56058c16..74bfb9730d64d746f5426fd5aab99c14e83f70ad 100644 (file)
  * where d = -121665/121666.
  *
  * Representations:
- * - ge_p2 (projective): (X:Y:Z) satisfying x=X/Z, y=Y/Z
- * - ge_p3 (extended): (X:Y:Z:T) satisfying x=X/Z, y=Y/Z, XY=ZT
- * - ge_p1p1 (completed): ((X:Z),(Y:T)) satisfying x=X/Z, y=Y/T
- * - ge_precomp (Duif): (y+x,y-x,2dxy)
+ * - p2 (projective): (X:Y:Z) satisfying x=X/Z, y=Y/Z
+ * - p3 (extended): (X:Y:Z:T) satisfying x=X/Z, y=Y/Z, XY=ZT
+ * - p1p1 (completed): ((X:Z),(Y:T)) satisfying x=X/Z, y=Y/T
+ * - precomp (Duif): (y+x,y-x,2dxy)
 */
 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_pair, fe_neg, fe_pow22523, fe_sq, fe_sub } from './fe'
-import { ge_cached, ge_p1p1, ge_p1p1_0, ge_p1p1_to_p2, ge_p1p1_to_p3, ge_p2, ge_p2_0, ge_p2_dbl, ge_p3, ge_p3_0, ge_p3_add_cached, ge_p3_add_cached_to_cached, ge_p3_add_precomp, ge_p3_dbl, ge_p3_dbl_to_p3, ge_p3_sub_cached, ge_p3_sub_precomp, ge_p3_to_cached, ge_p3_tobytes, ge_precomp, ge_precomp_0 } from './p'
+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'
 
 /**
  * √-1
@@ -37,7 +37,7 @@ const ed25519_d: FieldElement = StaticArray.fromArray<i32>([
        -10913610, 13857413, -15372611, 6949391, 114729, -8787816, -6275908, -3247719, -18696448, -12055116, 0, 0
 ])
 
-function ge_cmov8_base (t: ge_precomp, bp: usize, b: i8): void {
+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))
 
@@ -99,7 +99,7 @@ const ge_frombytes_negate_vartime_p_root_check: FieldElement = fe()
  *
  * @returns {i32} 0 if `s` decodes to a valid point, else -1
  */
-export function ge_frombytes_negate_vartime (h: ge_p3, s: StaticArray<u8>,
+export function ge_frombytes_negate_vartime (h: p3, s: StaticArray<u8>,
        t_u8x32: StaticArray<u8>, t_fe_0: FieldElement, t_fe_1: FieldElement, t_fe_2: FieldElement
 ): i32 {
        const u = ge_frombytes_negate_vartime_u
@@ -170,7 +170,7 @@ const ge_frombytes_x_sqrtm1: FieldElement = fe()
  *
  * @returns {i32} 0 if `s` decodes to a valid point, else -1
  */
-export function ge_frombytes (h: ge_p3, s: StaticArray<u8>,
+export function ge_frombytes (h: p3, s: StaticArray<u8>,
        t_fe_0: FieldElement, t_fe_1: FieldElement, t_fe_2: FieldElement, t_u8x32: StaticArray<u8>
 ): i32 {
        const u = ge_frombytes_u
@@ -221,10 +221,10 @@ export function ge_frombytes (h: ge_p3, s: StaticArray<u8>,
 }
 
 /**
- * @param {ge_p3} p
+ * @param {p3} p
  * @returns 1 if `p` is malformed (`Z = 0`, or `X = Y = 0`), else 0
  */
-function ge_is_malformed (p: ge_p3, t_fe: FieldElement, t_u8x32: StaticArray<u8>): i32 {
+function ge_is_malformed (p: p3, t_fe: FieldElement, t_u8x32: StaticArray<u8>): i32 {
        const x_iszero = fe_iszero(p.X, t_fe, t_u8x32)
        const y_iszero = fe_iszero(p.Y, t_fe, t_u8x32)
        const z_iszero = fe_iszero(p.Z, t_fe, t_u8x32)
@@ -234,10 +234,10 @@ function ge_is_malformed (p: ge_p3, t_fe: FieldElement, t_u8x32: StaticArray<u8>
 const ge_has_small_order_y_sqrtm1: FieldElement = fe()
 const ge_has_small_order_c: FieldElement = fe()
 /**
- * @param {ge_p3} p
+ * @param {p3} p
  * @returns 1 if `p` has small order, else 0
  */
-function ge_has_small_order (p: ge_p3, t_fe: FieldElement, t_u8x32: StaticArray<u8>): i32 {
+function ge_has_small_order (p: p3, t_fe: FieldElement, t_u8x32: StaticArray<u8>): i32 {
        const y_sqrtm1 = ge_has_small_order_y_sqrtm1
        const c = ge_has_small_order_c
 
@@ -256,10 +256,10 @@ function ge_has_small_order (p: ge_p3, t_fe: FieldElement, t_u8x32: StaticArray<
 /**
  * Used by the cofactored equation in `crypto_verify_sodium` where well-formed
  * small order means the signature is valid.
- * @param {ge_p3} p
+ * @param {p3} p
  * @returns 0 if `p` is not malformed and has small order, else -1
  */
-export function ge_accept_small_order (p: ge_p3, t_fe: FieldElement, t_u8x32: StaticArray<u8>): i32 {
+export function ge_accept_small_order (p: p3, t_fe: FieldElement, t_u8x32: StaticArray<u8>): i32 {
        const malformed = ge_is_malformed(p, t_fe, t_u8x32)
        const small_order = ge_has_small_order(p, t_fe, t_u8x32)
        return 0 - (malformed | (small_order ^ 1))
@@ -268,10 +268,10 @@ export function ge_accept_small_order (p: ge_p3, t_fe: FieldElement, t_u8x32: St
 /**
  * Used by verify checks on `A` and `R` where a malformed or small order point
  * means the signature is invalid.
- * @param {ge_p3} p
+ * @param {p3} p
  * @returns 0 if `p` is not malformed and not small order, else -1
  */
-export function ge_reject_small_order (p: ge_p3, t_fe: FieldElement, t_u8x32: StaticArray<u8>): i32 {
+export function ge_reject_small_order (p: p3, t_fe: FieldElement, t_u8x32: StaticArray<u8>): i32 {
        const malformed = ge_is_malformed(p, t_fe, t_u8x32)
        const small_order = ge_has_small_order(p, t_fe, t_u8x32)
        return 0 - (malformed | small_order)
@@ -295,11 +295,11 @@ export function ge_is_canonical (s: StaticArray<u8>): i32 {
        return 0 - (c & d & 1)
 }
 
-const ge_scalarmult_base_tobytes_h: ge_p3 = new ge_p3()
+const ge_scalarmult_base_tobytes_h: p3 = new p3()
 const ge_scalarmult_base_tobytes_e: StaticArray<i8> = new StaticArray<i8>(64)
-const ge_scalarmult_base_tobytes_r: ge_p1p1 = new ge_p1p1()
-const ge_scalarmult_base_tobytes_s: ge_p2 = new ge_p2()
-const ge_scalarmult_base_tobytes_t: ge_precomp = new ge_precomp()
+const ge_scalarmult_base_tobytes_r: p1p1 = new p1p1()
+const ge_scalarmult_base_tobytes_s: p2 = new p2()
+const ge_scalarmult_base_tobytes_t: p_precomp = new p_precomp()
 /**
  * `h = a * B` (with precomputation)
  *
@@ -343,62 +343,59 @@ export function ge_scalarmult_base_tobytes (S: StaticArray<u8>, a: StaticArray<u
        e[63] += carry
        /* each e[i] is between -8 and 8 */
 
-       ge_p3_0(h)
+       p3_0(h)
 
        // base pointer offset = 4 bytes * 12 values * 3 fe * 8 ge = 1152 bytes
        for (let i = 1, bp = 0; i < 64; i += 2, bp += 1152) {
                ge_cmov8_base(t, base + bp, load<i8>(changetype<usize>(e) + i))
-               ge_p3_add_precomp(r, h, t)
-               ge_p1p1_to_p3(h, r)
+               p3_add_precomp(r, h, t)
+               p1p1_to_p3(h, r)
        }
 
-       ge_p3_dbl(r, h)
-       ge_p1p1_to_p2(s, r)
-       ge_p2_dbl(r, s)
-       ge_p1p1_to_p2(s, r)
-       ge_p2_dbl(r, s)
-       ge_p1p1_to_p2(s, r)
-       ge_p2_dbl(r, s)
-       ge_p1p1_to_p3(h, r)
+       p3_dbl(r, h)
+       p1p1_to_p2(s, r)
+       p2_dbl(r, s)
+       p1p1_to_p2(s, r)
+       p2_dbl(r, s)
+       p1p1_to_p2(s, r)
+       p2_dbl(r, s)
+       p1p1_to_p3(h, r)
 
        // base pointer offset = 4 bytes * 12 values * 3 fe * 8 ge = 1152 bytes
        for (let i = 0, bp = 0; i < 64; i += 2, bp += 1152) {
                ge_cmov8_base(t, base + bp, load<i8>(changetype<usize>(e) + i))
-               ge_p3_add_precomp(r, h, t)
-               ge_p1p1_to_p3(h, r)
+               p3_add_precomp(r, h, t)
+               p1p1_to_p3(h, r)
        }
 
-       ge_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, t_fe_6)
 
        // clear sensitive data
-       ge_p1p1_0(r)
-       ge_p2_0(s)
-       ge_precomp_0(t)
-       ge_p3_0(h)
+       p1p1_0(r)
+       p2_0(s)
+       precomp_0(t)
+       p3_0(h)
        e.fill(0)
 }
 
-const ge_p3_cache_odd_multiples_A2: ge_p3 = new ge_p3()
 /**
  * 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_p3_cache_odd_multiples (Ai: StaticArray<ge_cached>, A: ge_p3, t_fe: FieldElement): void {
-       const A2 = ge_p3_cache_odd_multiples_A2
-
-       ge_p3_to_cached(Ai[0], A)
-       ge_p3_dbl_to_p3(A2, A, t_fe)
+export function ge_cache_odd_multiples (Ai: StaticArray<p_cached>, A: p3, t_p3: p3, t_fe: FieldElement): void {
+       p3_to_cached(Ai[0], A)
+       p3_dbl_to_p3(t_p3, A, t_fe)
 
        for (let i = 0; i < 7; i++) {
-               ge_p3_add_cached_to_cached(Ai[i + 1], A2, Ai[i], t_fe)
+               p3_add_cached_to_cached(Ai[i + 1], t_p3, Ai[i], t_fe)
        }
 }
 
 const ge_double_scalarmult_vartime_aslide: StaticArray<i8> = new StaticArray<i8>(256)
 const ge_double_scalarmult_vartime_bslide: StaticArray<i8> = new StaticArray<i8>(256)
-const ge_double_scalarmult_vartime_p: ge_p2 = new ge_p2()
-const ge_double_scalarmult_vartime_t: ge_p1p1 = new ge_p1p1()
-const ge_double_scalarmult_vartime_u: ge_p3 = new ge_p3()
+const ge_double_scalarmult_vartime_p: p2 = new p2()
+const ge_double_scalarmult_vartime_t: p1p1 = new p1p1()
+const ge_double_scalarmult_vartime_u: p3 = new p3()
 /**
  * `r = a[A] + b[B]`
  *
@@ -413,7 +410,7 @@ const ge_double_scalarmult_vartime_u: ge_p3 = new ge_p3()
  *
  * Variable-time; only used for signature verification.
  */
-export function ge_double_scalarmult_vartime_to_p3 (r: ge_p3, a: StaticArray<u8>, Ai: StaticArray<ge_cached>, b: StaticArray<u8>): void {
+export function ge_double_scalarmult_vartime_to_p3 (r: p3, a: StaticArray<u8>, Ai: StaticArray<p_cached>, b: StaticArray<u8>): void {
        const Bi = base2
        const aslide = ge_double_scalarmult_vartime_aslide
        const bslide = ge_double_scalarmult_vartime_bslide
@@ -421,12 +418,12 @@ export function ge_double_scalarmult_vartime_to_p3 (r: ge_p3, a: StaticArray<u8>
        const t = ge_double_scalarmult_vartime_t
        const u = ge_double_scalarmult_vartime_u
 
-       ge_p3_0(r)
+       p3_0(r)
 
        slide_vartime(aslide, a)
        slide_vartime(bslide, b)
 
-       ge_p2_0(p)
+       p2_0(p)
 
        let i: i32 = 255
        while (i >= 0 && !aslide[i] && !bslide[i]) {
@@ -434,30 +431,30 @@ export function ge_double_scalarmult_vartime_to_p3 (r: ge_p3, a: StaticArray<u8>
        }
 
        while (i >= 0) {
-               ge_p2_dbl(t, p)
+               p2_dbl(t, p)
 
                const aslidei = aslide[i]
                if (aslidei > 0) {
-                       ge_p1p1_to_p3(u, t)
-                       ge_p3_add_cached(t, u, Ai[aslidei >> 1])
+                       p1p1_to_p3(u, t)
+                       p3_add_cached(t, u, Ai[aslidei >> 1])
                } else if (aslidei < 0) {
-                       ge_p1p1_to_p3(u, t)
-                       ge_p3_sub_cached(t, u, Ai[(-aslidei) >> 1])
+                       p1p1_to_p3(u, t)
+                       p3_sub_cached(t, u, Ai[(-aslidei) >> 1])
                }
 
                const bslidei = bslide[i]
                if (bslidei > 0) {
-                       ge_p1p1_to_p3(u, t)
-                       ge_p3_add_precomp(t, u, Bi[bslidei >> 1])
+                       p1p1_to_p3(u, t)
+                       p3_add_precomp(t, u, Bi[bslidei >> 1])
                } else if (bslidei < 0) {
-                       ge_p1p1_to_p3(u, t)
-                       ge_p3_sub_precomp(t, u, Bi[(-bslidei) >> 1])
+                       p1p1_to_p3(u, t)
+                       p3_sub_precomp(t, u, Bi[(-bslidei) >> 1])
                }
 
                if (i > 0) {
-                       ge_p1p1_to_p2(p, t)
+                       p1p1_to_p2(p, t)
                } else {
-                       ge_p1p1_to_p3(r, t)
+                       p1p1_to_p3(r, t)
                }
                i--
        }
index 560ea560741cda1b2334504e52d908331df8e59c..429eeea1a7ead125a71e3d380ca408b2cfd7c484 100644 (file)
@@ -7,7 +7,7 @@ import { FieldElement, fe, fe_0, fe_1, fe_add, fe_addsub, fe_copy, fe_dbl, fe_in
 /**
  * Base class for building branded subclasses of coordinate systems.
  */
-class ge_coord {
+class Point {
        X: FieldElement = fe()
        Y: FieldElement = fe()
        Z: FieldElement = fe()
@@ -16,30 +16,30 @@ class ge_coord {
 /**
  * Projective coordinates.
  */
-export class ge_p2 extends ge_coord {
-       __brand: 'ge_p2' = 'ge_p2'
+export class p2 extends Point {
+       __brand: 'p2' = 'p2'
 }
 
 /**
  * Completed `(x, y)` where`x = X/Z`, `y = Y/T`
  */
-export class ge_p1p1 extends ge_coord {
+export class p1p1 extends Point {
        T: FieldElement = fe()
-       __brand: 'ge_p1p1' = 'ge_p1p1'
+       __brand: 'p1p1' = 'p1p1'
 }
 
 /**
  * Extended projective coordinates.
  */
-export class ge_p3 extends ge_coord {
+export class p3 extends Point {
        T: FieldElement = fe()
-       __brand: 'ge_p3' = 'ge_p3'
+       __brand: 'p3' = 'p3'
 }
 
 /**
  * Computed at runtime.
  */
-export class ge_cached {
+export class p_cached {
        YplusX: FieldElement = fe()
        YminusX: FieldElement = fe()
        Z: FieldElement = fe()
@@ -50,33 +50,33 @@ export class ge_cached {
  * Precomputed from base point and compiled into the module.
  * Requires an expensive `fe_invert` up front but saves one `fe_mul` at runtime.
  */
-export class ge_precomp {
+export class p_precomp {
        yplusx: FieldElement = fe()
        yminusx: FieldElement = fe()
        xy2d: FieldElement = fe()
 }
 
-export function ge_p2_0 (h: ge_p2): void {
+export function p2_0 (h: p2): void {
        fe_0(h.X)
        fe_1(h.Y)
        fe_1(h.Z)
 }
 
-export function ge_p1p1_0 (h: ge_p1p1): void {
+export function p1p1_0 (h: p1p1): void {
        fe_0(h.X)
        fe_1(h.Y)
        fe_1(h.Z)
        fe_0(h.T)
 }
 
-export function ge_p3_0 (h: ge_p3): void {
+export function p3_0 (h: p3): void {
        fe_0(h.X)
        fe_1(h.Y)
        fe_1(h.Z)
        fe_0(h.T)
 }
 
-export function ge_precomp_0 (h: ge_precomp): void {
+export function precomp_0 (h: p_precomp): void {
        fe_1(h.yplusx)
        fe_1(h.yminusx)
        fe_0(h.xy2d)
@@ -91,7 +91,7 @@ export function ge_precomp_0 (h: ge_precomp): void {
  * Z = Z₁T₁
  * ```
  */
-export function ge_p1p1_to_p2 (r: ge_p2, p: ge_p1p1): void {
+export function p1p1_to_p2 (r: p2, p: p1p1): void {
        fe_mul_pair(r.X, p.X, p.T, r.Y, p.Y, p.Z)
        fe_mul(r.Z, p.Z, p.T)
 }
@@ -106,7 +106,7 @@ export function ge_p1p1_to_p2 (r: ge_p2, p: ge_p1p1): void {
  * T = X₁Y₁
  * ```
  */
-export function ge_p1p1_to_p3 (r: ge_p3, p: ge_p1p1): void {
+export function p1p1_to_p3 (r: p3, p: p1p1): void {
        fe_mul_pair(r.Y, p.Y, p.Z, r.T, p.X, p.Y)
        fe_mul_pair(r.X, p.X, p.T, r.Z, p.Z, p.T)
 }
@@ -121,7 +121,7 @@ export function ge_p1p1_to_p3 (r: ge_p3, p: ge_p1p1): void {
  * T = 2T₁d
  * ```
  */
-export function ge_p3_to_cached (r: ge_cached, p: ge_p3): void {
+export function p3_to_cached (r: p_cached, p: p3): void {
        fe_addsub(r.YplusX, r.YminusX, p.Y, p.X)
        fe_copy(r.Z, p.Z)
        fe_mul_2d(r.T2d, p.T)
@@ -137,7 +137,7 @@ export function ge_p3_to_cached (r: ge_cached, p: ge_p3): void {
  * T2d = 2X₁Y₁d
  * ```
  */
-export function ge_p1p1_to_cached (r: ge_cached, p: ge_p1p1): void {
+export function p1p1_to_cached (r: p_cached, p: p1p1): void {
        fe_mul_pair(r.YminusX, p.X, p.T, r.YplusX, p.Y, p.Z)
        fe_mul_pair_2d(r.Z, p.Z, p.T, r.T2d, p.X, p.Y)
        fe_addsub(r.YplusX, r.YminusX, r.YplusX, r.YminusX)
@@ -153,7 +153,7 @@ export function ge_p1p1_to_cached (r: ge_cached, p: ge_p1p1): void {
  * T = 2Z₁² - (Y₁²-X₁²)
  * ```
  */
-export function ge_p2_dbl (r: ge_p1p1, p: ge_p2): void {
+export function p2_dbl (r: p1p1, p: p2): void {
        fe_add(r.T, p.X, p.Y)
        fe_sq_pair_dbl(r.X, r.T, r.T, p.Z)
        fe_sq_pair(r.Z, p.X, r.Y, p.Y)
@@ -172,7 +172,7 @@ export function ge_p2_dbl (r: ge_p1p1, p: ge_p2): void {
  * T = X₃Y₃ = ((Y₁+X₁)(Y₂+X₂) - (Y₁-X₁)(Y₂-X₂))((Y₁+X₁)(Y₂+X₂) + (Y₁-X₁)(Y₂-X₂))
  * ```
  */
-export function ge_p3_add_p3 (r: ge_p3, p: ge_p3, q: ge_p3, t_fe: FieldElement): void {
+export function p3_add_p3 (r: p3, p: p3, q: p3, t_fe: FieldElement): void {
        fe_addsub(r.X, r.Y, p.Y, p.X) // X = Y₁+X₁, Y = Y₁-X₁
        fe_addsub(r.Z, r.T, q.Y, q.X) // Z = Y₂+X₂, T = Y₂-X₂
        fe_mul_pair(r.X, r.X, r.Z, r.Y, r.Y, r.T) // X = (Y₁+X₁)(Y₂+X₂), Y = (Y₁-X₁)(Y₂-X₂)
@@ -194,7 +194,7 @@ export function ge_p3_add_p3 (r: ge_p3, p: ge_p3, q: ge_p3, t_fe: FieldElement):
  * T = 2Z₁² - (Y₁²-X₁²)
  * ```
  */
-export function ge_p3_dbl_to_p3 (r: ge_p3, p: ge_p3, t_fe: FieldElement): void {
+export function p3_dbl_to_p3 (r: p3, p: p3, t_fe: FieldElement): void {
        fe_add(r.T, p.X, p.Y)
        fe_sq_pair_dbl(r.X, r.T, r.T, p.Z)
        fe_sq_pair(r.Z, p.X, r.Y, p.Y)
@@ -216,7 +216,7 @@ export function ge_p3_dbl_to_p3 (r: ge_p3, p: ge_p3, t_fe: FieldElement): void {
  * T = 2Z₁² - (Y₁²-X₁²)
  * ```
  */
-export function ge_p3_dbl (r: ge_p1p1, p: ge_p3): void {
+export function p3_dbl (r: p1p1, p: p3): void {
        fe_add(r.T, p.X, p.Y)
        fe_sq_pair_dbl(r.X, r.T, r.T, p.Z)
        fe_sq_pair(r.Z, p.X, r.Y, p.Y)
@@ -235,7 +235,7 @@ export function ge_p3_dbl (r: ge_p1p1, p: ge_p3): void {
  * T = 2Z₁Z₂ - 2T₁T₂d
  * ```
  */
-export function ge_p3_add_cached (r: ge_p1p1, p: ge_p3, q: ge_cached): void {
+export function p3_add_cached (r: p1p1, p: p3, q: p_cached): void {
        fe_addsub(r.X, r.Y, p.Y, p.X)
        fe_mul_pair(r.X, r.X, q.YplusX, r.Y, r.Y, q.YminusX)
        fe_mul_pair_dbl(r.Z, p.Z, q.Z, r.T, q.T2d, p.T)
@@ -262,7 +262,7 @@ export function ge_p3_add_cached (r: ge_p1p1, p: ge_p3, q: ge_cached): void {
  * T2d = 2X₁Y₁d
  * ```
  */
-export function ge_p3_add_cached_to_cached (r: ge_cached, p: ge_p3, q: ge_cached, t_fe: FieldElement): void {
+export function p3_add_cached_to_cached (r: p_cached, p: p3, q: p_cached, t_fe: FieldElement): void {
        // p3 + cached
        fe_addsub(r.YplusX, r.YminusX, p.Y, p.X)
        fe_mul_pair(r.YplusX, r.YplusX, q.YplusX, r.YminusX, r.YminusX, q.YminusX)
@@ -286,7 +286,7 @@ export function ge_p3_add_cached_to_cached (r: ge_cached, p: ge_p3, q: ge_cached
  * T = 2Z₁ - 2T₁X₂Y₂d
  * ```
  */
-export function ge_p3_add_precomp (r: ge_p1p1, p: ge_p3, q: ge_precomp): void {
+export function p3_add_precomp (r: p1p1, p: p3, q: p_precomp): void {
        fe_addsub(r.X, r.Y, p.Y, p.X)
        fe_mul_pair(r.X, r.X, q.yplusx, r.Y, r.Y, q.yminusx)
        fe_dbl(r.Z, p.Z)
@@ -305,7 +305,7 @@ export function ge_p3_add_precomp (r: ge_p1p1, p: ge_p3, q: ge_precomp): void {
  * T = X₃Y₃ = ((Y₁+X₁)(Y₂-X₂) - (Y₁-X₁)(Y₂+X₂))((Y₁+X₁)(Y₂-X₂) + (Y₁-X₁)(Y₂+X₂))
  * ```
  */
-export function ge_p3_sub_p3 (r: ge_p3, p: ge_p3, q: ge_p3, t_fe: FieldElement): void {
+export function p3_sub_p3 (r: p3, p: p3, q: p3, t_fe: FieldElement): void {
        fe_addsub(r.X, r.Y, p.Y, p.X) // X = Y₁+X₁, Y = Y₁-X₁
        fe_addsub(r.Z, r.T, q.Y, q.X) // Z = Y₂+X₂, T = Y₂-X₂
        fe_mul_pair(r.X, r.X, r.T, r.Y, r.Y, r.Z) // X = (Y₁+X₁)(Y₂-X₂), Y = (Y₁-X₁)(Y₂+X₂)
@@ -327,7 +327,7 @@ export function ge_p3_sub_p3 (r: ge_p3, p: ge_p3, q: ge_p3, t_fe: FieldElement):
  * T = 2Z₁Z₂ + 2T₁T₂d
  * ```
  */
-export function ge_p3_sub_cached (r: ge_p1p1, p: ge_p3, q: ge_cached): void {
+export function p3_sub_cached (r: p1p1, p: p3, q: p_cached): void {
        fe_addsub(r.X, r.Y, p.Y, p.X)
        fe_mul_pair(r.X, r.X, q.YminusX, r.Y, r.Y, q.YplusX)
        fe_mul_pair_dbl(r.Z, p.Z, q.Z, r.T, q.T2d, p.T)
@@ -345,7 +345,7 @@ export function ge_p3_sub_cached (r: ge_p1p1, p: ge_p3, q: ge_cached): void {
  * T = 2Z₁ + 2T₁X₂Y₂d
  * ```
  */
-export function ge_p3_sub_precomp (r: ge_p1p1, p: ge_p3, q: ge_precomp): void {
+export function p3_sub_precomp (r: p1p1, p: p3, q: p_precomp): void {
        fe_addsub(r.X, r.Y, p.Y, p.X)
        fe_mul_pair(r.X, r.X, q.yminusx, r.Y, r.Y, q.yplusx)
        fe_dbl(r.Z, p.Z)
@@ -354,7 +354,7 @@ export function ge_p3_sub_precomp (r: ge_p1p1, p: ge_p3, q: ge_precomp): void {
        fe_addsub(r.T, r.Z, r.Z, r.T)
 }
 
-export function ge_p3_tobytes (s: StaticArray<u8>, h: ge_p3,
+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
 ): void {