From: Chris Duncan Date: Sat, 15 Aug 2026 20:56:36 +0000 (-0700) Subject: Reduce form on division by shift. X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=0fd8b0f4a6f513bf70b75cccd99ea2c3f01adce1;p=nano25519.git Reduce form on division by shift. --- diff --git a/src/assembly/ge.ts b/src/assembly/ge.ts index 0e68650..c82639f 100644 --- a/src/assembly/ge.ts +++ b/src/assembly/ge.ts @@ -140,7 +140,7 @@ export function ge_frombytes (h: ge_p3, s: StaticArray): 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 diff --git a/src/assembly/utils.ts b/src/assembly/utils.ts index e794a08..dee20aa 100644 --- a/src/assembly/utils.ts +++ b/src/assembly/utils.ts @@ -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, 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