]> git.codecow.com Git - nano25519.git/commitdiff
Invert check results.
authorChris Duncan <chris@codecow.com>
Sat, 17 Oct 2026 05:52:58 +0000 (22:52 -0700)
committerChris Duncan <chris@codecow.com>
Sat, 17 Oct 2026 05:52:58 +0000 (22:52 -0700)
src/assembly/crypto_verify.ts
src/assembly/ed25519/ge.ts

index 02c2057d71bde06a92977cf80e95db6faf4e5f3d..58264bc8d14ec572c9acc2ac430fd846fcf78cfe 100644 (file)
@@ -96,7 +96,9 @@ export function crypto_verify_sodium (sig: StaticArray<u8>, M: StaticArray<u8>,
        // to pass, unlike `verify_pubkey()` and `verify_signature()` below
        const b = ge_accept_small_order(check, t_fe_0, t_u8x32)
        clear_t()
-       return b
+       if (b != 0) return 0
+
+       return 1
 }
 
 /**
index ed30d385eaf14a5d722d04cc8e79d5af5c532707..26f3006cd3a66a1b34e79fb88043b7189afae913 100644 (file)
@@ -256,29 +256,27 @@ function ge_has_small_order (p: ge_p3, t_fe: FieldElement, t_u8x32: StaticArray<
 }
 
 /**
- * For the cofactored equation in `crypto_verify_sodium`, where small order means
- * the signature is valid: a malformed point must not pass.
+ * Used by the cofactored equation in `crypto_verify_sodium` where well-formed
+ * small order means the signature is valid.
  * @param {ge_p3} p
- * @returns 1 if `p` is small order and not malformed, else 0
+ * @returns 0 if `p` is not malformed and has small order, else -1
  */
 export function ge_accept_small_order (p: ge_p3, t_fe: FieldElement, t_u8x32: StaticArray<u8>): i32 {
-       const small_order = ge_has_small_order(p, t_fe, t_u8x32)
        const malformed = ge_is_malformed(p, t_fe, t_u8x32)
-
-       return small_order & (malformed ^ 1)
+       const small_order = ge_has_small_order(p, t_fe, t_u8x32)
+       return 0 - (malformed | (small_order ^ 1))
 }
 
 /**
- * For the checks on the key and `R`, where small order means reject: a
- * malformed point must not pass either.
+ * Used by verify checks on `A` and `R` where a malformed or small order point
+ * means the signature is invalid.
  * @param {ge_p3} p
- * @returns 0 if `p` is not small order and not malformed, else -1
+ * @returns 0 if `p` is not malformed and not small order, else -1
  */
 export function ge_reject_small_order (p: ge_p3, t_fe: FieldElement, t_u8x32: StaticArray<u8>): i32 {
-       const small_order = ge_has_small_order(p, t_fe, t_u8x32)
        const malformed = ge_is_malformed(p, t_fe, t_u8x32)
-
-       return 0 - (small_order | malformed)
+       const small_order = ge_has_small_order(p, t_fe, t_u8x32)
+       return 0 - (malformed | small_order)
 }
 
 /**