secp256k1

Pure Haskell cryptographic primitives on the secp256k1 elliptic curve.
git clone git://git.ppad.tech/secp256k1.git
Log | Files | Refs | LICENSE

commit 411122f32984e59a08dcfa74c6522a4f4d896cd3
parent 9bfc6b6037ac9e4446a271cd350f8dc56dd94752
Author: Jared Tobin <jared@jtobin.io>
Date:   Fri,  5 Apr 2024 18:15:48 +0400

lib: change affine type

Diffstat:
Mlib/Crypto/Secp256k1.hs | 17+++++++----------
1 file changed, 7 insertions(+), 10 deletions(-)

diff --git a/lib/Crypto/Secp256k1.hs b/lib/Crypto/Secp256k1.hs @@ -343,15 +343,13 @@ mul_safe p n else loop r (add f d) nd nm -- | Convert to affine coordinates. -affine :: Projective -> Maybe Affine +affine :: Projective -> Affine affine p@(Projective x y z) - | p == _ZERO = pure (Affine 0 0) - | z == 1 = pure (Affine x y) - | otherwise = do - iz <- modinv z (fromIntegral _CURVE_P) - if modP (z * iz) /= 1 - then Nothing - else pure (Affine (modP (x * iz)) (modP (y * iz))) + | p == _ZERO = Affine 0 0 + | z == 1 = Affine x y + | otherwise = case modinv z (fromIntegral _CURVE_P) of + Nothing -> error "ppad-secp256k1 (affine): impossible point" + Just iz -> Affine (modP (x * iz)) (modP (y * iz)) -- | Convert to projective coordinates. projective :: Affine -> Projective @@ -362,8 +360,7 @@ projective (Affine x y) -- | Point is valid valid :: Projective -> Bool valid p = case affine p of - Nothing -> False - Just (Affine x y) + Affine x y | not (fe x) || not (fe y) -> False | modP (y * y) /= weierstrass x -> False | otherwise -> True