]> git.codecow.com Git - nano25519.git/commitdiff
Remove unused pair functions.
authorChris Duncan <chris@codecow.com>
Mon, 26 Oct 2026 13:41:18 +0000 (06:41 -0700)
committerChris Duncan <chris@codecow.com>
Mon, 26 Oct 2026 13:41:18 +0000 (06:41 -0700)
src/assembly/ed25519/fep.ts

index c035f04e918c375eadf2b3f83ec0d43d46b987f5..cfe8832f38eb693d3655bc30686331538ab9354b 100644 (file)
@@ -315,152 +315,6 @@ export function fep_dbl_lane (h: FieldElementPair, f: FieldElementPair): void {
        v128.store(changetype<usize>(h), h4, 4 << 4)
 }
 
-/**
- * Decompress bytes to a FieldElementPair. Ignores top bit of s.
- */
-// export function fep_frombytes (h: FieldElementPair, s: StaticArray<u8>): void {
-//     let h0: i64 = load_4(s, 0)
-//     let h1: i64 = load_3(s, 4) << 6
-//     let h2: i64 = load_3(s, 7) << 5
-//     let h3: i64 = load_3(s, 10) << 3
-//     let h4: i64 = load_3(s, 13) << 2
-//     let h5: i64 = load_4(s, 16)
-//     let h6: i64 = load_3(s, 20) << 7
-//     let h7: i64 = load_3(s, 23) << 5
-//     let h8: i64 = load_3(s, 26) << 4
-//     let h9: i64 = (load_3(s, 29) & 8388607) << 2
-
-//     const s25: i64 = <i64>1 << 25
-//     const s24: i64 = <i64>1 << 24
-//     const m26 = ~((<i64>1 << 26) - 1)
-//     const m25 = ~((<i64>1 << 25) - 1)
-
-//     let c: i64
-//     let carry0: i64
-//     let carry1: i64
-//     let carry2: i64
-//     let carry3: i64
-//     let carry4: i64
-//     let carry5: i64
-//     let carry6: i64
-//     let carry7: i64
-//     let carry8: i64
-//     let carry9: i64
-
-//     // odd limbs
-//     c = h9 + s24
-//     carry9 = c >> 25
-//     h9 -= c & m25
-//     h0 += carry9 * 19
-
-//     c = h1 + s24
-//     carry1 = c >> 25
-//     h1 -= c & m25
-//     h2 += carry1
-
-//     c = h3 + s24
-//     carry3 = c >> 25
-//     h3 -= c & m25
-//     h4 += carry3
-
-//     c = h5 + s24
-//     carry5 = c >> 25
-//     h5 -= c & m25
-//     h6 += carry5
-
-//     c = h7 + s24
-//     carry7 = c >> 25
-//     h7 -= c & m25
-//     h8 += carry7
-
-//     // even limbs
-//     c = h0 + s25
-//     carry0 = c >> 26
-//     h0 -= c & m26
-//     h1 += carry0
-
-//     c = h2 + s25
-//     carry2 = c >> 26
-//     h2 -= c & m26
-//     h3 += carry2
-
-//     c = h4 + s25
-//     carry4 = c >> 26
-//     h4 -= c & m26
-//     h5 += carry4
-
-//     c = h6 + s25
-//     carry6 = c >> 26
-//     h6 -= c & m26
-//     h7 += carry6
-
-//     c = h8 + s25
-//     carry8 = c >> 26
-//     h8 -= c & m26
-//     h9 += carry8
-
-//     store<i32>(changetype<usize>(h), h0, 0 << 2)
-//     store<i32>(changetype<usize>(h), h1, 1 << 2)
-//     store<i32>(changetype<usize>(h), h2, 2 << 2)
-//     store<i32>(changetype<usize>(h), h3, 3 << 2)
-//     store<i32>(changetype<usize>(h), h4, 4 << 2)
-//     store<i32>(changetype<usize>(h), h5, 5 << 2)
-//     store<i32>(changetype<usize>(h), h6, 6 << 2)
-//     store<i32>(changetype<usize>(h), h7, 7 << 2)
-//     store<i32>(changetype<usize>(h), h8, 8 << 2)
-//     store<i32>(changetype<usize>(h), h9, 9 << 2)
-// }
-
-/**
- * Inversion - sets `out` = 0 if `z` == 0
- */
-// export function fep_invert (out: FieldElementPair, z: FieldElementPair, t_fep_0: FieldElementPair, t_fep_1: FieldElementPair, t_fep_2: FieldElementPair, t_fep_3: FieldElementPair): void {
-//     fep_sq(t_fep_0, z)
-//     fep_sq(t_fep_1, t_fep_0)
-//     fep_sq(t_fep_1, t_fep_1)
-//     fep_mul(t_fep_1, z, t_fep_1)
-//     fep_mul(t_fep_0, t_fep_0, t_fep_1)
-//     fep_sq(t_fep_2, t_fep_0)
-//     fep_mul(t_fep_1, t_fep_1, t_fep_2)
-//     fep_sq(t_fep_2, t_fep_1)
-//     for (let i = 1; i < 5; ++i) {
-//             fep_sq(t_fep_2, t_fep_2)
-//     }
-//     fep_mul(t_fep_1, t_fep_2, t_fep_1)
-//     fep_sq(t_fep_2, t_fep_1)
-//     for (let i = 1; i < 10; ++i) {
-//             fep_sq(t_fep_2, t_fep_2)
-//     }
-//     fep_mul(t_fep_2, t_fep_2, t_fep_1)
-//     fep_sq(t_fep_3, t_fep_2)
-//     for (let i = 1; i < 20; ++i) {
-//             fep_sq(t_fep_3, t_fep_3)
-//     }
-//     fep_mul(t_fep_2, t_fep_3, t_fep_2)
-//     for (let i = 1; i < 11; ++i) {
-//             fep_sq(t_fep_2, t_fep_2)
-//     }
-//     fep_mul(t_fep_1, t_fep_2, t_fep_1)
-//     fep_sq(t_fep_2, t_fep_1)
-//     for (let i = 1; i < 50; ++i) {
-//             fep_sq(t_fep_2, t_fep_2)
-//     }
-//     fep_mul(t_fep_2, t_fep_2, t_fep_1)
-//     fep_sq(t_fep_3, t_fep_2)
-//     for (let i = 1; i < 100; ++i) {
-//             fep_sq(t_fep_3, t_fep_3)
-//     }
-//     fep_mul(t_fep_2, t_fep_3, t_fep_2)
-//     for (let i = 1; i < 51; ++i) {
-//             fep_sq(t_fep_2, t_fep_2)
-//     }
-//     fep_mul(t_fep_1, t_fep_2, t_fep_1)
-//     for (let i = 1; i < 6; ++i) {
-//             fep_sq(t_fep_1, t_fep_1)
-//     }
-//     fep_mul(out, t_fep_1, t_fep_0)
-// }
-
 /**
  * return 1 if f is in {1,3,5,...,q-2}
  * return 0 if f is in {0,2,4,...,q-1}
@@ -1019,154 +873,6 @@ export function fep_neg (h: FieldElementPair, f: FieldElementPair): void {
        v128.store(changetype<usize>(h), h4, 4 << 4)
 }
 
-/**
- * returns z^((p-5)/8) = z^(2²⁵²-3)
- * used to compute square roots since we have p=5 (mod 8); see Cohen and Frey.
- */
-// export function fep_pow22523 (out: FieldElementPair, z: FieldElementPair, t_fep_0: FieldElementPair, t_fep_1: FieldElementPair, t_fep_2: FieldElementPair): void {
-//     fep_sq(t_fep_0, z)
-//     fep_sq(t_fep_1, t_fep_0)
-//     fep_sq(t_fep_1, t_fep_1)
-//     fep_mul(t_fep_1, z, t_fep_1)
-//     fep_mul(t_fep_0, t_fep_0, t_fep_1)
-//     fep_sq(t_fep_0, t_fep_0)
-//     fep_mul(t_fep_0, t_fep_1, t_fep_0)
-//     fep_sq(t_fep_1, t_fep_0)
-//     for (let i = 1; i < 5; ++i) {
-//             fep_sq(t_fep_1, t_fep_1)
-//     }
-//     fep_mul(t_fep_0, t_fep_1, t_fep_0)
-//     fep_sq(t_fep_1, t_fep_0)
-//     for (let i = 1; i < 10; ++i) {
-//             fep_sq(t_fep_1, t_fep_1)
-//     }
-//     fep_mul(t_fep_1, t_fep_1, t_fep_0)
-//     fep_sq(t_fep_2, t_fep_1)
-//     for (let i = 1; i < 20; ++i) {
-//             fep_sq(t_fep_2, t_fep_2)
-//     }
-//     fep_mul(t_fep_1, t_fep_2, t_fep_1)
-//     for (let i = 1; i < 11; ++i) {
-//             fep_sq(t_fep_1, t_fep_1)
-//     }
-//     fep_mul(t_fep_0, t_fep_1, t_fep_0)
-//     fep_sq(t_fep_1, t_fep_0)
-//     for (let i = 1; i < 50; ++i) {
-//             fep_sq(t_fep_1, t_fep_1)
-//     }
-//     fep_mul(t_fep_1, t_fep_1, t_fep_0)
-//     fep_sq(t_fep_2, t_fep_1)
-//     for (let i = 1; i < 100; ++i) {
-//             fep_sq(t_fep_2, t_fep_2)
-//     }
-//     fep_mul(t_fep_1, t_fep_2, t_fep_1)
-//     for (let i = 1; i < 51; ++i) {
-//             fep_sq(t_fep_1, t_fep_1)
-//     }
-//     fep_mul(t_fep_0, t_fep_1, t_fep_0)
-//     fep_sq(t_fep_0, t_fep_0)
-//     fep_sq(t_fep_0, t_fep_0)
-//     fep_mul(out, t_fep_0, z)
-// }
-
-/**
- * Preconditions:
- * |h| bounded by 1.1x2²⁶,1.1x2²⁵,1.1x2²⁶,1.1x2²⁵,etc.
- *
- * Write p=2²⁵⁵-19; q=floor(h/p).
- * Basic claim: q = floor(2⁻²⁵⁵(h + 19 2⁻²⁵h9 + 2⁻¹)).
- *
- * Proof:
- * Have |h|≤p so |q|≤1 so |19² 2⁻²⁵⁵ q|<1/4.
- * Also have |h-2²³⁰ h9|<2²³¹ so |19 2⁻²⁵⁵(h-2²³⁰ h9)|<1/4.
- *
- * Write y=2⁻¹-19² 2⁻²⁵⁵q-19 2⁻²⁵⁵(h-2²³⁰ h9).
- * Then 0<y<1.
- *
- * Write r=h-pq.
- * Have 0 ≤ r ≤ p-1 = 2²⁵⁵-20.
- * Thus 0 ≤ r+19(2⁻²⁵⁵)r < r+19(2⁻²⁵⁵)2²⁵⁵ ≤ 2²⁵⁵-1.
- *
- * Write x=r+19(2⁻²⁵⁵)r+y.
- * Then 0 < x < 2²⁵⁵ so floor(2⁻²⁵⁵x) = 0 so floor(q+2⁻²⁵⁵x) = q.
- *
- * Have q+2⁻²⁵⁵x = 2⁻²⁵⁵(h + 19 2⁻²⁵ h9 + 2⁻¹)
- * so floor(2⁻²⁵⁵(h + 19 2⁻²⁵ h9 + 2⁻¹)) = q.
- */
-// export function fep_reduce (h: FieldElementPair, f: FieldElementPair): void {
-//     const f_ptr: usize = changetype<usize>(f)
-//     let f0: i32 = load<i32>(f_ptr, 0)
-//     let f1: i32 = load<i32>(f_ptr, 4)
-//     let f2: i32 = load<i32>(f_ptr, 8)
-//     let f3: i32 = load<i32>(f_ptr, 12)
-//     let f4: i32 = load<i32>(f_ptr, 16)
-//     let f5: i32 = load<i32>(f_ptr, 20)
-//     let f6: i32 = load<i32>(f_ptr, 24)
-//     let f7: i32 = load<i32>(f_ptr, 28)
-//     let f8: i32 = load<i32>(f_ptr, 32)
-//     let f9: i32 = load<i32>(f_ptr, 36)
-//     let q: i32
-//     let c0: i32, c1: i32, c2: i32, c3: i32, c4: i32, c5: i32, c6: i32, c7: i32, c8: i32, c9: i32
-
-//     q = (19 * f9 + (1 << 24)) >> 25
-//     q = (f0 + q) >> 26
-//     q = (f1 + q) >> 25
-//     q = (f2 + q) >> 26
-//     q = (f3 + q) >> 25
-//     q = (f4 + q) >> 26
-//     q = (f5 + q) >> 25
-//     q = (f6 + q) >> 26
-//     q = (f7 + q) >> 25
-//     q = (f8 + q) >> 26
-//     q = (f9 + q) >> 25
-
-//     /* Goal: Output h-(2²⁵⁵-19)q, which is between 0 and 2²⁵⁵-20. */
-//     f0 += 19 * q
-//     /* Goal: Output h-2²⁵⁵ q, which is between 0 and 2²⁵⁵-20. */
-
-//     c0 = f0 >> 26
-//     f1 += c0
-//     f0 -= c0 << 26
-//     c1 = f1 >> 25
-//     f2 += c1
-//     f1 -= c1 << 25
-//     c2 = f2 >> 26
-//     f3 += c2
-//     f2 -= c2 << 26
-//     c3 = f3 >> 25
-//     f4 += c3
-//     f3 -= c3 << 25
-//     c4 = f4 >> 26
-//     f5 += c4
-//     f4 -= c4 << 26
-//     c5 = f5 >> 25
-//     f6 += c5
-//     f5 -= c5 << 25
-//     c6 = f6 >> 26
-//     f7 += c6
-//     f6 -= c6 << 26
-//     c7 = f7 >> 25
-//     f8 += c7
-//     f7 -= c7 << 25
-//     c8 = f8 >> 26
-//     f9 += c8
-//     f8 -= c8 << 26
-//     c9 = f9 >> 25
-//     f9 -= c9 << 25
-
-//     const h_ptr: usize = changetype<usize>(h)
-//     store<i32>(h_ptr, f0, 0)
-//     store<i32>(h_ptr, f1, 4)
-//     store<i32>(h_ptr, f2, 8)
-//     store<i32>(h_ptr, f3, 12)
-//     store<i32>(h_ptr, f4, 16)
-//     store<i32>(h_ptr, f5, 20)
-//     store<i32>(h_ptr, f6, 24)
-//     store<i32>(h_ptr, f7, 28)
-//     store<i32>(h_ptr, f8, 32)
-//     store<i32>(h_ptr, f9, 36)
-// }
-
 /**
  * Square two pairs of FieldElement values in parallel and store the results.
  *
@@ -1670,57 +1376,3 @@ export function fep_swap (h: FieldElementPair, f: FieldElementPair): void {
        v128.store(changetype<usize>(h), h3, 3 << 4)
        v128.store(changetype<usize>(h), h4, 4 << 4)
 }
-
-/**
- * Goal: Output h0+...+2²⁵⁵ h10-2²⁵⁵ q, which is between 0 and 2²⁵⁵-20.
- * Have h0+...+2²³⁰ h9 between 0 and 2²⁵⁵-1;
- * evidently 2²⁵⁵ h10-2²⁵⁵ q = 0.
- *
- * Goal: Output h0+...+2²³⁰ h9.
- */
-// export function fep_tobytes (s: StaticArray<u8>, h: FieldElementPair, t_fe: FieldElementPair): void {
-//     fep_reduce(t_fe, h)
-//     const t0 = load<i32>(changetype<usize>(t_fe), 0 << 2)
-//     const t1 = load<i32>(changetype<usize>(t_fe), 1 << 2)
-//     const t2 = load<i32>(changetype<usize>(t_fe), 2 << 2)
-//     const t3 = load<i32>(changetype<usize>(t_fe), 3 << 2)
-//     const t4 = load<i32>(changetype<usize>(t_fe), 4 << 2)
-//     const t5 = load<i32>(changetype<usize>(t_fe), 5 << 2)
-//     const t6 = load<i32>(changetype<usize>(t_fe), 6 << 2)
-//     const t7 = load<i32>(changetype<usize>(t_fe), 7 << 2)
-//     const t8 = load<i32>(changetype<usize>(t_fe), 8 << 2)
-//     const t9 = load<i32>(changetype<usize>(t_fe), 9 << 2)
-
-//     store<u8>(changetype<usize>(s), t0 >> 0, 0)
-//     store<u8>(changetype<usize>(s), t0 >> 8, 1)
-//     store<u8>(changetype<usize>(s), t0 >> 16, 2)
-//     store<u8>(changetype<usize>(s), (t0 >> 24) | (t1 << 2), 3)
-//     store<u8>(changetype<usize>(s), t1 >> 6, 4)
-//     store<u8>(changetype<usize>(s), t1 >> 14, 5)
-//     store<u8>(changetype<usize>(s), (t1 >> 22) | (t2 << 3), 6)
-//     store<u8>(changetype<usize>(s), t2 >> 5, 7)
-//     store<u8>(changetype<usize>(s), t2 >> 13, 8)
-//     store<u8>(changetype<usize>(s), (t2 >> 21) | (t3 << 5), 9)
-//     store<u8>(changetype<usize>(s), t3 >> 3, 10)
-//     store<u8>(changetype<usize>(s), t3 >> 11, 11)
-//     store<u8>(changetype<usize>(s), (t3 >> 19) | (t4 << 6), 12)
-//     store<u8>(changetype<usize>(s), t4 >> 2, 13)
-//     store<u8>(changetype<usize>(s), t4 >> 10, 14)
-//     store<u8>(changetype<usize>(s), t4 >> 18, 15)
-//     store<u8>(changetype<usize>(s), t5 >> 0, 16)
-//     store<u8>(changetype<usize>(s), t5 >> 8, 17)
-//     store<u8>(changetype<usize>(s), t5 >> 16, 18)
-//     store<u8>(changetype<usize>(s), (t5 >> 24) | (t6 << 1), 19)
-//     store<u8>(changetype<usize>(s), t6 >> 7, 20)
-//     store<u8>(changetype<usize>(s), t6 >> 15, 21)
-//     store<u8>(changetype<usize>(s), (t6 >> 23) | (t7 << 3), 22)
-//     store<u8>(changetype<usize>(s), t7 >> 5, 23)
-//     store<u8>(changetype<usize>(s), t7 >> 13, 24)
-//     store<u8>(changetype<usize>(s), (t7 >> 21) | (t8 << 4), 25)
-//     store<u8>(changetype<usize>(s), t8 >> 4, 26)
-//     store<u8>(changetype<usize>(s), t8 >> 12, 27)
-//     store<u8>(changetype<usize>(s), (t8 >> 20) | (t9 << 6), 28)
-//     store<u8>(changetype<usize>(s), t9 >> 2, 29)
-//     store<u8>(changetype<usize>(s), t9 >> 10, 30)
-//     store<u8>(changetype<usize>(s), t9 >> 18, 31)
-// }