]> git.codecow.com Git - nano25519.git/commitdiff
Document canonical group element encoding check.
authorChris Duncan <chris@codecow.com>
Tue, 6 Oct 2026 04:58:02 +0000 (21:58 -0700)
committerChris Duncan <chris@codecow.com>
Tue, 6 Oct 2026 04:58:02 +0000 (21:58 -0700)
src/assembly/ed25519/ge.ts

index 0e47f27172698cb91e2a33142f27cc4c64bbfc6d..d8337df25e84b38e0c70cc0fb0d79746641116ba 100644 (file)
@@ -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<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)
 }