]> git.codecow.com Git - nano25519.git/commitdiff
Reduce form on division by shift.
authorChris Duncan <chris@zoso.dev>
Sat, 15 Aug 2026 20:56:36 +0000 (13:56 -0700)
committerChris Duncan <chris@zoso.dev>
Sat, 15 Aug 2026 20:56:36 +0000 (13:56 -0700)
src/assembly/ge.ts
src/assembly/utils.ts

index 0e6865053df71020ed8fd9384b4f11f742529094..c82639f28782a32901cafc1c51b08fcde9a33239 100644 (file)
@@ -140,7 +140,7 @@ export function ge_frombytes (h: ge_p3, s: StaticArray<u8>): i32 {
        fe_cmov(h.X, x_sqrtm1, 1 - has_m_root)
 
        fe_neg(negx, h.X)
-       fe_cmov(h.X, negx, fe_isnegative(h.X) ^ ((s[31] >> 5) >> 2))
+       fe_cmov(h.X, negx, fe_isnegative(h.X) ^ (s[31] >> 7))
        fe_mul(h.T, h.X, h.Y)
 
        return (has_m_root | has_p_root) - 1
index e794a084154b09ae7a0f01e9715a4060efdef3f0..dee20aa97c45f98957252abd63539e2fc2607c63 100644 (file)
@@ -7,7 +7,7 @@ export function equal (b: i8, c: i8): u8 {
        const x: u8 = u8(b) ^ u8(c) /* 0: yes; 1..255: no */
        let y: u32 = u32(x) /* 0: yes; 1..255: no */
        y--
-       return u8((y >> 29) >> 2) /* 1: yes; 0: no */
+       return u8(y >> 31) /* 1: yes; 0: no */
 }
 
 //@ts-expect-error
@@ -31,7 +31,7 @@ export function load_4 (input: StaticArray<u8>, i: u8): u64 {
 @inline
 export function negative (b: i8): u8 {
        const x: u8 = u8(b) /* 0..127: no 128..255: yes */
-       return (x >> 5) >> 2 /* 1: yes; 0: no */
+       return x >> 7 /* 1: yes; 0: no */
 }
 
 //@ts-expect-error