From: Chris Duncan Date: Tue, 6 Oct 2026 04:58:02 +0000 (-0700) Subject: Document canonical group element encoding check. X-Git-Tag: v2.0.0~2^2~19 X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=311628efc54fc3cc8bbde2497e8acf7b516693cf;p=nano25519.git Document canonical group element encoding check. --- diff --git a/src/assembly/ed25519/ge.ts b/src/assembly/ed25519/ge.ts index 0e47f27..d8337df 100644 --- a/src/assembly/ed25519/ge.ts +++ b/src/assembly/ed25519/ge.ts @@ -265,16 +265,19 @@ export function ge_has_small_order (p: ge_p3): i32 { } /** - * 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} s 32-byte encoded group element * @returns 0 if `s < p`, else -1 */ export function ge_is_canonical (s: StaticArray): 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) }