commit 9bbd83c5cb7e70d86876bc5e00fd5bf0e8b5ab6f
parent 1ee2b4f9c8f96b29071d29ed19e34c786c3c7481
Author: Jared Tobin <jared@jtobin.io>
Date: Sat, 29 Nov 2025 07:48:44 +0400
lib: fix montgomery signums
Diffstat:
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/lib/Numeric/Montgomery/Secp256k1/Curve.hs b/lib/Numeric/Montgomery/Secp256k1/Curve.hs
@@ -39,7 +39,9 @@ instance Num Montgomery where
a * b = mul a b
negate a = neg a
abs = id
- signum = id -- XX
+ signum a = case a of
+ Montgomery (# 0##, 0##, 0##, 0## #) -> 0
+ _ -> 1
fromInteger = to . WW.to
-- XX define constants here, current approach is fragile
diff --git a/lib/Numeric/Montgomery/Secp256k1/Scalar.hs b/lib/Numeric/Montgomery/Secp256k1/Scalar.hs
@@ -39,7 +39,9 @@ instance Num Montgomery where
a * b = mul a b
negate a = neg a
abs = id
- signum = id
+ signum a = case a of
+ Montgomery (# 0##, 0##, 0##, 0## #) -> 0
+ _ -> 1
fromInteger = to . WW.to
-- XX define constants here, current approach is fragile