}
/**
- * Checks input `s` is less than the field prime `p = 2²⁵⁵ - 19`
+ * Checks input `s` is less than the field prime `p = 2²⁵⁵ - 19`. Note that the
+ * highest bit position is excluded since it encodes the sign of `x`.
* @param {StaticArray<u8>} s 32-byte encoded group element
* @returns 0 if `s < p`, else -1
*/
export function ge_is_canonical (s: StaticArray<u8>): i32 {
+ // setup failure if any bits of `y` are set to 0
let c: i32 = (s[31] & 0x7f) ^ 0x7f
for (let i = 30; i > 0; i--) {
c |= s[i] ^ 0xff
}
c = (c - 1) >> 8
+ // setup failure if low bits of `y` are greater than or equal to -19
const d: i32 = (0xec - s[0]) >> 8
return 0 - (c & d & 1)
}