]> git.codecow.com Git - nano25519.git/commitdiff
Refactor to remove array index access and reduce load calls.
authorChris Duncan <chris@codecow.com>
Fri, 9 Oct 2026 16:15:44 +0000 (09:15 -0700)
committerChris Duncan <chris@codecow.com>
Fri, 9 Oct 2026 16:15:44 +0000 (09:15 -0700)
src/assembly/ed25519/fe.ts
src/assembly/ed25519/ge.ts

index b8913f37df39f0db3ddba640e282d92ae5dce80a..aff204a6117f4077d9fbb7370a2c1b4eea11b997 100644 (file)
@@ -48,7 +48,7 @@ export function fe_0 (h: FieldElement): void {
  */
 export function fe_1 (h: FieldElement): void {
        fe_0(h)
-       h[0] = 1
+       store<i32>(changetype<usize>(h), 1, 0)
 }
 
 /**
@@ -59,12 +59,12 @@ export function fe_1 (h: FieldElement): void {
  * @param g FieldElement summand source
  */
 export function fe_add (h: FieldElement, f: FieldElement, g: FieldElement): void {
-       const h_ptr = changetype<usize>(h)
-       const f_ptr = changetype<usize>(f)
-       const g_ptr = changetype<usize>(g)
-       v128.store(h_ptr, v128.add<i32>(v128.load(f_ptr, 0), v128.load(g_ptr, 0)), 0)
-       v128.store(h_ptr, v128.add<i32>(v128.load(f_ptr, 16), v128.load(g_ptr, 16)), 16)
-       v128.store_lane<i64>(h_ptr, v128.add<i32>(v128.load(f_ptr, 32), v128.load(g_ptr, 32)), 0, 32)
+       const f0 = v128.load(changetype<usize>(f), 0), f1 = v128.load(changetype<usize>(f), 16), f2 = v128.load(changetype<usize>(f), 32)
+       const g0 = v128.load(changetype<usize>(g), 0), g1 = v128.load(changetype<usize>(g), 16), g2 = v128.load(changetype<usize>(g), 32)
+       const h0 = v128.add<i32>(f0, g0), h1 = v128.add<i32>(f1, g1), h2 = v128.add<i32>(f2, g2)
+       v128.store(changetype<usize>(h), h0, 0)
+       v128.store(changetype<usize>(h), h1, 16)
+       v128.store_lane<i64>(changetype<usize>(h), h2, 0, 32)
 }
 
 /**
@@ -75,12 +75,13 @@ export function fe_add (h: FieldElement, f: FieldElement, g: FieldElement): void
  * @param {u64} b Copy `g` into `f` if 1, copy `f` into `f` if 0
  */
 export function fe_cmov (f: FieldElement, g: FieldElement, b: u64): void {
-       const f_ptr = changetype<usize>(f)
-       const g_ptr = changetype<usize>(g)
        const c = v128.splat<u64>(0 - b)
-       v128.store(f_ptr, v128.bitselect(v128.load(g_ptr), v128.load(f_ptr, 0), c))
-       v128.store(f_ptr, v128.bitselect(v128.load(g_ptr, 16), v128.load(f_ptr, 16), c), 16)
-       v128.store_lane<u64>(f_ptr, v128.bitselect(v128.load(g_ptr, 32), v128.load(f_ptr, 32), c), 0, 32)
+       const f0 = v128.load(changetype<usize>(f), 0), f1 = v128.load(changetype<usize>(f), 16), f2 = v128.load(changetype<usize>(f), 32)
+       const g0 = v128.load(changetype<usize>(g), 0), g1 = v128.load(changetype<usize>(g), 16), g2 = v128.load(changetype<usize>(g), 32)
+       const h0 = v128.bitselect(g0, f0, c), h1 = v128.bitselect(g1, f1, c), h2 = v128.bitselect(g2, f2, c)
+       v128.store(changetype<usize>(f), h0, 0)
+       v128.store(changetype<usize>(f), h1, 16)
+       v128.store_lane<u64>(changetype<usize>(f), h2, 0, 32)
 }
 
 /**
@@ -100,11 +101,11 @@ export function fe_copy (h: FieldElement, f: FieldElement): void {
  * @param f FieldElement summand source
  */
 export function fe_dbl (h: FieldElement, f: FieldElement): void {
-       const h_ptr = changetype<usize>(h)
-       const f_ptr = changetype<usize>(f)
-       v128.store(h_ptr, v128.shl<i32>(v128.load(f_ptr, 0), 1), 0)
-       v128.store(h_ptr, v128.shl<i32>(v128.load(f_ptr, 16), 1), 16)
-       v128.store_lane<i64>(h_ptr, v128.shl<i32>(v128.load(f_ptr, 32), 1), 0, 32)
+       const f0 = v128.load(changetype<usize>(f), 0), f1 = v128.load(changetype<usize>(f), 16), f2 = v128.load(changetype<usize>(f), 32)
+       const h0 = v128.shl<i32>(f0, 1), h1 = v128.shl<i32>(f1, 1), h2 = v128.shl<i32>(f2, 1)
+       v128.store(changetype<usize>(h), h0, 0)
+       v128.store(changetype<usize>(h), h1, 16)
+       v128.store_lane<i64>(changetype<usize>(h), h2, 0, 32)
 }
 
 /**
@@ -165,17 +166,16 @@ export function fe_frombytes (h: FieldElement, s: StaticArray<u8>): void {
        h9 += carry8
        h8 -= carry8 << 26
 
-       const h_ptr: usize = changetype<usize>(h)
-       store<i32>(h_ptr, h0, 0)
-       store<i32>(h_ptr, h1, 4)
-       store<i32>(h_ptr, h2, 8)
-       store<i32>(h_ptr, h3, 12)
-       store<i32>(h_ptr, h4, 16)
-       store<i32>(h_ptr, h5, 20)
-       store<i32>(h_ptr, h6, 24)
-       store<i32>(h_ptr, h7, 28)
-       store<i32>(h_ptr, h8, 32)
-       store<i32>(h_ptr, h9, 36)
+       store<i32>(changetype<usize>(h), h0, 0)
+       store<i32>(changetype<usize>(h), h1, 4)
+       store<i32>(changetype<usize>(h), h2, 8)
+       store<i32>(changetype<usize>(h), h3, 12)
+       store<i32>(changetype<usize>(h), h4, 16)
+       store<i32>(changetype<usize>(h), h5, 20)
+       store<i32>(changetype<usize>(h), h6, 24)
+       store<i32>(changetype<usize>(h), h7, 28)
+       store<i32>(changetype<usize>(h), h8, 32)
+       store<i32>(changetype<usize>(h), h9, 36)
 }
 
 /**
@@ -237,7 +237,7 @@ export function fe_invert (out: FieldElement, z: FieldElement, t_fe_0: FieldElem
  */
 export function fe_isnegative (f: FieldElement, t: FieldElement): u8 {
        fe_reduce(t, f)
-       return u8(t[0] & 1)
+       return u8(load<i32>(changetype<usize>(t), 0) & 1)
 }
 
 /**
@@ -247,14 +247,12 @@ export function fe_isnegative (f: FieldElement, t: FieldElement): u8 {
  * Preconditions:
  * |f| bounded by 1.1x2²⁶,1.1x2²⁵,1.1x2²⁶,1.1x2²⁵,etc.
  */
-export function fe_iszero (f: FieldElement, t_u8x32: StaticArray<u8>, t: FieldElement): u8 {
-       fe_tobytes(t_u8x32, f, t)
-       let d: i32 = 0
-       for (let i: i32 = 0; i < 32; i++) {
-               d |= t_u8x32[i]
-       }
-       d &= 255
-       return u8(((d - 1) >> 8) & 1)
+export function fe_iszero (f: FieldElement, t_fe: FieldElement, t_u8x32: StaticArray<u8>): u8 {
+       fe_tobytes(t_u8x32, f, t_fe)
+       const t0 = v128.load(changetype<usize>(t_u8x32), 0)
+       const t1 = v128.load(changetype<usize>(t_u8x32), 16)
+       const d = v128.or(t0, t1)
+       return u8(v128.any_true(d)) ^ 1
 }
 
 /**
@@ -265,26 +263,23 @@ export function fe_iszero (f: FieldElement, t_u8x32: StaticArray<u8>, t: FieldEl
  * @param g FieldElement multiplicand source
  */
 export function fe_mul (h: FieldElement, f: FieldElement, g: FieldElement): void {
-       const h_ptr: usize = changetype<usize>(h)
-       const f_ptr: usize = changetype<usize>(f)
-       const g_ptr: usize = changetype<usize>(g)
-       const g0123: v128 = v128.load(g_ptr, 0)
-       const g4567: v128 = v128.load(g_ptr, 16)
-       const g89xx: v128 = v128.load(g_ptr, 32)
-
        // mask to select even lane from first vector and odd lane from second
        const m: v128 = i32x4(-1, 0, -1, 0)
 
        // mask to double odd-on-odd indexes
        const odds: v128 = i32x4(0, -1, 0, -1)
 
+       const g0123: v128 = v128.load(changetype<usize>(g), 0)
+       const g4567: v128 = v128.load(changetype<usize>(g), 16)
+       const g89xx: v128 = v128.load(changetype<usize>(g), 32)
+
        // factor of 19 for wrap from h9 to h0
        const g0123_19: v128 = i32x4.mul(g0123, i32x4.splat(19))
        const g4567_19: v128 = i32x4.mul(g4567, i32x4.splat(19))
        const g89xx_19: v128 = i32x4.mul(g89xx, i32x4.splat(19))
 
        // f[0]
-       let f_i: v128 = v128.load_splat<i32>(f_ptr, 0 << 2)
+       let f_i: v128 = v128.load_splat<i32>(changetype<usize>(f), 0 << 2)
 
        let h01: v128 = i64x2.extmul_low_i32x4_s(f_i, g0123)
        let h23: v128 = i64x2.extmul_high_i32x4_s(f_i, g0123)
@@ -293,7 +288,7 @@ export function fe_mul (h: FieldElement, f: FieldElement, g: FieldElement): void
        let h89: v128 = i64x2.extmul_low_i32x4_s(f_i, g89xx)
 
        // f[1]
-       f_i = v128.load_splat<i32>(f_ptr, 1 << 2)
+       f_i = v128.load_splat<i32>(changetype<usize>(f), 1 << 2)
        f_i = v128.add<i32>(f_i, v128.and(f_i, odds))
 
        let h12: v128 = i64x2.extmul_low_i32x4_s(f_i, g0123)
@@ -303,7 +298,7 @@ export function fe_mul (h: FieldElement, f: FieldElement, g: FieldElement): void
        let h90: v128 = i64x2.extmul_low_i32x4_s(f_i, v128.bitselect(g89xx, g89xx_19, m))
 
        // f[2]
-       f_i = v128.load_splat<i32>(f_ptr, 2 << 2)
+       f_i = v128.load_splat<i32>(changetype<usize>(f), 2 << 2)
 
        let t0: v128 = i64x2.extmul_low_i32x4_s(f_i, g0123)
        let t1: v128 = i64x2.extmul_high_i32x4_s(f_i, g0123)
@@ -318,7 +313,7 @@ export function fe_mul (h: FieldElement, f: FieldElement, g: FieldElement): void
        h01 = i64x2.add(h01, t4)
 
        // f[3]
-       f_i = v128.load_splat<i32>(f_ptr, 3 << 2)
+       f_i = v128.load_splat<i32>(changetype<usize>(f), 3 << 2)
        f_i = v128.add<i32>(f_i, v128.and(f_i, odds))
 
        t0 = i64x2.extmul_low_i32x4_s(f_i, g0123)
@@ -334,7 +329,7 @@ export function fe_mul (h: FieldElement, f: FieldElement, g: FieldElement): void
        h12 = i64x2.add(h12, t4)
 
        // f[4]
-       f_i = v128.load_splat<i32>(f_ptr, 4 << 2)
+       f_i = v128.load_splat<i32>(changetype<usize>(f), 4 << 2)
 
        t0 = i64x2.extmul_low_i32x4_s(f_i, g0123)
        t1 = i64x2.extmul_high_i32x4_s(f_i, g0123)
@@ -349,7 +344,7 @@ export function fe_mul (h: FieldElement, f: FieldElement, g: FieldElement): void
        h23 = i64x2.add(h23, t4)
 
        // f[5]
-       f_i = v128.load_splat<i32>(f_ptr, 5 << 2)
+       f_i = v128.load_splat<i32>(changetype<usize>(f), 5 << 2)
        f_i = v128.add<i32>(f_i, v128.and(f_i, odds))
 
        t0 = i64x2.extmul_low_i32x4_s(f_i, g0123)
@@ -365,7 +360,7 @@ export function fe_mul (h: FieldElement, f: FieldElement, g: FieldElement): void
        h34 = i64x2.add(h34, t4)
 
        // f[6]
-       f_i = v128.load_splat<i32>(f_ptr, 6 << 2)
+       f_i = v128.load_splat<i32>(changetype<usize>(f), 6 << 2)
 
        t0 = i64x2.extmul_low_i32x4_s(f_i, g0123)
        t1 = i64x2.extmul_high_i32x4_s(f_i, g0123)
@@ -380,7 +375,7 @@ export function fe_mul (h: FieldElement, f: FieldElement, g: FieldElement): void
        h45 = i64x2.add(h45, t4)
 
        // f[7]
-       f_i = v128.load_splat<i32>(f_ptr, 7 << 2)
+       f_i = v128.load_splat<i32>(changetype<usize>(f), 7 << 2)
        f_i = v128.add<i32>(f_i, v128.and(f_i, odds))
 
        t0 = i64x2.extmul_low_i32x4_s(f_i, g0123)
@@ -396,7 +391,7 @@ export function fe_mul (h: FieldElement, f: FieldElement, g: FieldElement): void
        h56 = i64x2.add(h56, t4)
 
        // f[8]
-       f_i = v128.load_splat<i32>(f_ptr, 8 << 2)
+       f_i = v128.load_splat<i32>(changetype<usize>(f), 8 << 2)
 
        t0 = i64x2.extmul_low_i32x4_s(f_i, g0123)
        t1 = i64x2.extmul_high_i32x4_s(f_i, g0123_19)
@@ -411,7 +406,7 @@ export function fe_mul (h: FieldElement, f: FieldElement, g: FieldElement): void
        h67 = i64x2.add(h67, t4)
 
        // f[9]
-       f_i = v128.load_splat<i32>(f_ptr, 9 << 2)
+       f_i = v128.load_splat<i32>(changetype<usize>(f), 9 << 2)
        f_i = v128.add<i32>(f_i, v128.and(f_i, odds))
 
        t0 = i64x2.extmul_low_i32x4_s(f_i, v128.bitselect(g0123, g0123_19, m))
@@ -499,16 +494,16 @@ export function fe_mul (h: FieldElement, f: FieldElement, g: FieldElement): void
        h1 += carry0
 
        // assign results to output
-       store<i32>(h_ptr, h0, 0)
-       store<i32>(h_ptr, h1, 4)
-       store<i32>(h_ptr, h2, 8)
-       store<i32>(h_ptr, h3, 12)
-       store<i32>(h_ptr, h4, 16)
-       store<i32>(h_ptr, h5, 20)
-       store<i32>(h_ptr, h6, 24)
-       store<i32>(h_ptr, h7, 28)
-       store<i32>(h_ptr, h8, 32)
-       store<i32>(h_ptr, h9, 36)
+       store<i32>(changetype<usize>(h), h0, 0)
+       store<i32>(changetype<usize>(h), h1, 4)
+       store<i32>(changetype<usize>(h), h2, 8)
+       store<i32>(changetype<usize>(h), h3, 12)
+       store<i32>(changetype<usize>(h), h4, 16)
+       store<i32>(changetype<usize>(h), h5, 20)
+       store<i32>(changetype<usize>(h), h6, 24)
+       store<i32>(changetype<usize>(h), h7, 28)
+       store<i32>(changetype<usize>(h), h8, 32)
+       store<i32>(changetype<usize>(h), h9, 36)
 }
 
 /**
@@ -518,11 +513,11 @@ export function fe_mul (h: FieldElement, f: FieldElement, g: FieldElement): void
  * @param {FieldElement} f operand source
  */
 export function fe_neg (h: FieldElement, f: FieldElement): void {
-       const h_ptr = changetype<usize>(h)
-       const f_ptr = changetype<usize>(f)
-       v128.store(h_ptr, v128.neg<i32>(v128.load(f_ptr)))
-       v128.store(h_ptr, v128.neg<i32>(v128.load(f_ptr, 16)), 16)
-       v128.store_lane<i64>(h_ptr, v128.neg<i32>(v128.load(f_ptr, 32)), 0, 32)
+       const f0 = v128.load(changetype<usize>(f), 0), f1 = v128.load(changetype<usize>(f), 16), f2 = v128.load(changetype<usize>(f), 32)
+       const h0 = v128.neg<i32>(f0), h1 = v128.neg<i32>(f1), h2 = v128.neg<i32>(f2)
+       v128.store(changetype<usize>(h), h0, 0)
+       v128.store(changetype<usize>(h), h1, 16)
+       v128.store_lane<i64>(changetype<usize>(h), h2, 0, 32)
 }
 
 /**
@@ -704,17 +699,16 @@ export function fe_reduce (h: FieldElement, f: FieldElement): void {
  * @param f FieldElement base source
  */
 export function fe_sq (h: FieldElement, f: FieldElement): void {
-       const f_ptr: usize = changetype<usize>(f)
-       const f0: i64 = i64(load<i32>(f_ptr, 0))
-       const f1: i64 = i64(load<i32>(f_ptr, 4))
-       const f2: i64 = i64(load<i32>(f_ptr, 8))
-       const f3: i64 = i64(load<i32>(f_ptr, 12))
-       const f4: i64 = i64(load<i32>(f_ptr, 16))
-       const f5: i64 = i64(load<i32>(f_ptr, 20))
-       const f6: i64 = i64(load<i32>(f_ptr, 24))
-       const f7: i64 = i64(load<i32>(f_ptr, 28))
-       const f8: i64 = i64(load<i32>(f_ptr, 32))
-       const f9: i64 = i64(load<i32>(f_ptr, 36))
+       const f0: i64 = i64(load<i32>(changetype<usize>(f), 0))
+       const f1: i64 = i64(load<i32>(changetype<usize>(f), 4))
+       const f2: i64 = i64(load<i32>(changetype<usize>(f), 8))
+       const f3: i64 = i64(load<i32>(changetype<usize>(f), 12))
+       const f4: i64 = i64(load<i32>(changetype<usize>(f), 16))
+       const f5: i64 = i64(load<i32>(changetype<usize>(f), 20))
+       const f6: i64 = i64(load<i32>(changetype<usize>(f), 24))
+       const f7: i64 = i64(load<i32>(changetype<usize>(f), 28))
+       const f8: i64 = i64(load<i32>(changetype<usize>(f), 32))
+       const f9: i64 = i64(load<i32>(changetype<usize>(f), 36))
 
        const f0_2: i64 = f0 * 2
        const f1_2: i64 = f1 * 2
@@ -1071,12 +1065,12 @@ export function fe_sq2 (h: FieldElement, f: FieldElement): void {
  * @param g FieldElement subtrahend source
  */
 export function fe_sub (h: FieldElement, f: FieldElement, g: FieldElement): void {
-       const f_ptr = changetype<usize>(f)
-       const g_ptr = changetype<usize>(g)
-       const h_ptr = changetype<usize>(h)
-       v128.store(h_ptr, v128.sub<i32>(v128.load(f_ptr, 0), v128.load(g_ptr, 0)), 0)
-       v128.store(h_ptr, v128.sub<i32>(v128.load(f_ptr, 16), v128.load(g_ptr, 16)), 16)
-       v128.store_lane<i64>(h_ptr, v128.sub<i32>(v128.load(f_ptr, 32), v128.load(g_ptr, 32)), 0, 32)
+       const f0 = v128.load(changetype<usize>(f), 0), f1 = v128.load(changetype<usize>(f), 16), f2 = v128.load(changetype<usize>(f), 32)
+       const g0 = v128.load(changetype<usize>(g), 0), g1 = v128.load(changetype<usize>(g), 16), g2 = v128.load(changetype<usize>(g), 32)
+       const h0 = v128.sub<i32>(f0, g0), h1 = v128.sub<i32>(f1, g1), h2 = v128.sub<i32>(f2, g2)
+       v128.store(changetype<usize>(h), h0, 0)
+       v128.store(changetype<usize>(h), h1, 16)
+       v128.store_lane<i64>(changetype<usize>(h), h2, 0, 32)
 }
 
 /**
@@ -1088,49 +1082,47 @@ export function fe_sub (h: FieldElement, f: FieldElement, g: FieldElement): void
  */
 export function fe_tobytes (s: StaticArray<u8>, h: FieldElement, t_fe: FieldElement): void {
        fe_reduce(t_fe, h)
-       const t_ptr: usize = changetype<usize>(t_fe)
-       const t0 = load<i32>(t_ptr, 0)
-       const t1 = load<i32>(t_ptr, 4)
-       const t2 = load<i32>(t_ptr, 8)
-       const t3 = load<i32>(t_ptr, 12)
-       const t4 = load<i32>(t_ptr, 16)
-       const t5 = load<i32>(t_ptr, 20)
-       const t6 = load<i32>(t_ptr, 24)
-       const t7 = load<i32>(t_ptr, 28)
-       const t8 = load<i32>(t_ptr, 32)
-       const t9 = load<i32>(t_ptr, 36)
-
-       const s_ptr: usize = changetype<usize>(s)
-       store<u8>(s_ptr, t0 >> 0, 0)
-       store<u8>(s_ptr, t0 >> 8, 1)
-       store<u8>(s_ptr, t0 >> 16, 2)
-       store<u8>(s_ptr, (t0 >> 24) | (t1 << 2), 3)
-       store<u8>(s_ptr, t1 >> 6, 4)
-       store<u8>(s_ptr, t1 >> 14, 5)
-       store<u8>(s_ptr, (t1 >> 22) | (t2 << 3), 6)
-       store<u8>(s_ptr, t2 >> 5, 7)
-       store<u8>(s_ptr, t2 >> 13, 8)
-       store<u8>(s_ptr, (t2 >> 21) | (t3 << 5), 9)
-       store<u8>(s_ptr, t3 >> 3, 10)
-       store<u8>(s_ptr, t3 >> 11, 11)
-       store<u8>(s_ptr, (t3 >> 19) | (t4 << 6), 12)
-       store<u8>(s_ptr, t4 >> 2, 13)
-       store<u8>(s_ptr, t4 >> 10, 14)
-       store<u8>(s_ptr, t4 >> 18, 15)
-       store<u8>(s_ptr, t5 >> 0, 16)
-       store<u8>(s_ptr, t5 >> 8, 17)
-       store<u8>(s_ptr, t5 >> 16, 18)
-       store<u8>(s_ptr, (t5 >> 24) | (t6 << 1), 19)
-       store<u8>(s_ptr, t6 >> 7, 20)
-       store<u8>(s_ptr, t6 >> 15, 21)
-       store<u8>(s_ptr, (t6 >> 23) | (t7 << 3), 22)
-       store<u8>(s_ptr, t7 >> 5, 23)
-       store<u8>(s_ptr, t7 >> 13, 24)
-       store<u8>(s_ptr, (t7 >> 21) | (t8 << 4), 25)
-       store<u8>(s_ptr, t8 >> 4, 26)
-       store<u8>(s_ptr, t8 >> 12, 27)
-       store<u8>(s_ptr, (t8 >> 20) | (t9 << 6), 28)
-       store<u8>(s_ptr, t9 >> 2, 29)
-       store<u8>(s_ptr, t9 >> 10, 30)
-       store<u8>(s_ptr, t9 >> 18, 31)
+       const t0 = load<i32>(changetype<usize>(t_fe), 0)
+       const t1 = load<i32>(changetype<usize>(t_fe), 4)
+       const t2 = load<i32>(changetype<usize>(t_fe), 8)
+       const t3 = load<i32>(changetype<usize>(t_fe), 12)
+       const t4 = load<i32>(changetype<usize>(t_fe), 16)
+       const t5 = load<i32>(changetype<usize>(t_fe), 20)
+       const t6 = load<i32>(changetype<usize>(t_fe), 24)
+       const t7 = load<i32>(changetype<usize>(t_fe), 28)
+       const t8 = load<i32>(changetype<usize>(t_fe), 32)
+       const t9 = load<i32>(changetype<usize>(t_fe), 36)
+
+       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)
 }
index 5cda5ae3935bd2591eb4160055fcc7a394f1b204..0d43594582f7dabb903af128c5f5a8ba33a74973 100644 (file)
@@ -140,10 +140,10 @@ export function ge_frombytes_negate_vartime (h: ge_p3, s: StaticArray<u8>,
 
        // m = vx²-u
        fe_sub(m_root_check, vxx, u)
-       if (fe_iszero(m_root_check, t_u8x32, t_fe_0) == 0) {
+       if (fe_iszero(m_root_check, t_fe_0, t_u8x32) == 0) {
                // p = vx²+u
                fe_add(p_root_check, vxx, u)
-               if (fe_iszero(p_root_check, t_u8x32, t_fe_0) == 0) {
+               if (fe_iszero(p_root_check, t_fe_0, t_u8x32) == 0) {
                        return -1
                }
                fe_mul(h.X, h.X, fe_sqrtm1)
@@ -204,11 +204,11 @@ export function ge_frombytes (h: ge_p3, s: StaticArray<u8>,
 
        // m = vx²-u
        fe_sub(m_root_check, vxx, u)
-       has_m_root = fe_iszero(m_root_check, t_u8x32, t_fe_0)
+       has_m_root = fe_iszero(m_root_check, t_fe_0, t_u8x32)
 
        // p = vx²+u
        fe_add(p_root_check, vxx, u)
-       has_p_root = fe_iszero(p_root_check, t_u8x32, t_fe_0)
+       has_p_root = fe_iszero(p_root_check, t_fe_0, t_u8x32)
 
        // x√-1
        fe_mul(x_sqrtm1, h.X, fe_sqrtm1)
@@ -233,14 +233,14 @@ export function ge_has_small_order (p: ge_p3, t_fe: FieldElement, t_u8x32: Stati
 
        let ret: i32 = 0
 
-       ret |= fe_iszero(p.X, t_u8x32, t_fe)
-       ret |= fe_iszero(p.Y, t_u8x32, t_fe)
-       ret |= fe_iszero(p.Z, t_u8x32, t_fe)
+       ret |= fe_iszero(p.X, t_fe, t_u8x32)
+       ret |= fe_iszero(p.Y, t_fe, t_u8x32)
+       ret |= fe_iszero(p.Z, t_fe, t_u8x32)
        fe_mul(y_sqrtm1, p.Y, fe_sqrtm1)
        fe_sub(c, y_sqrtm1, p.X)
-       ret |= fe_iszero(c, t_u8x32, t_fe)
+       ret |= fe_iszero(c, t_fe, t_u8x32)
        fe_add(c, y_sqrtm1, p.X)
-       ret |= fe_iszero(c, t_u8x32, t_fe)
+       ret |= fe_iszero(c, t_fe, t_u8x32)
 
        return ret
 }