From c0835f4aba1644974805d36cc5d1a3e7b9614c76 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Fri, 16 Oct 2026 22:52:58 -0700 Subject: [PATCH] Invert check results. --- src/assembly/crypto_verify.ts | 4 +++- src/assembly/ed25519/ge.ts | 22 ++++++++++------------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/assembly/crypto_verify.ts b/src/assembly/crypto_verify.ts index 02c2057..58264bc 100644 --- a/src/assembly/crypto_verify.ts +++ b/src/assembly/crypto_verify.ts @@ -96,7 +96,9 @@ export function crypto_verify_sodium (sig: StaticArray, M: StaticArray, // 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 } /** diff --git a/src/assembly/ed25519/ge.ts b/src/assembly/ed25519/ge.ts index ed30d38..26f3006 100644 --- a/src/assembly/ed25519/ge.ts +++ b/src/assembly/ed25519/ge.ts @@ -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): 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): 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) } /** -- 2.52.0