commit 87fb7fe848f01d90e98508aed1fcec27fc29cb94 parent 07e360a0da43053bff65c81f5e992fb37fa4e996 Author: Jared Tobin <jared@jtobin.io> Date: Tue, 23 Dec 2025 07:30:45 -0330 lib: dumber/faster modQ Diffstat:
| M | lib/Crypto/Curve/Secp256k1.hs | | | 7 | +++++-- |
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/lib/Crypto/Curve/Secp256k1.hs b/lib/Crypto/Curve/Secp256k1.hs @@ -283,9 +283,12 @@ unroll32 (Wider (# w0, w1, w2, w3 #)) = Storable.pokeByteOff ptr 31 (word8 w0) {-# INLINABLE unroll32 #-} --- cheeky montgomery-assisted modQ +-- modQ via conditional subtraction modQ :: Wider -> Wider -modQ = S.from . S.to +modQ x = + let !(Wider xw) = x + !(Wider qw) = _CURVE_Q + in W.select x (x - _CURVE_Q) (CT.not# (W.lt# xw qw)) {-# INLINABLE modQ #-} -- bytewise xor