secp256k1

Pure Haskell Schnorr, ECDSA on the elliptic curve secp256k1 (docs.ppad.tech/secp256k1).
git clone git://git.ppad.tech/secp256k1.git
Log | Files | Refs | README | LICENSE

commit 0d6cdaf6d5ee7b836a0e1ff132ca76492fd2a0c2
parent 4a1df2ca61233e4d19777b64bf5ead0ab3f1192e
Author: Jared Tobin <jared@jtobin.io>
Date:   Tue, 17 Jun 2025 10:54:17 +0400

test: update to use total functions

Also updates the benchmark suites.

Diffstat:
Mbench/Main.hs | 4++--
Mbench/Weight.hs | 4++--
Mtest/BIP340.hs | 5+++--
Mtest/Noble.hs | 5+++--
Mtest/WycheproofEcdh.hs | 2+-
5 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/bench/Main.hs b/bench/Main.hs @@ -139,9 +139,9 @@ ecdsa = env setup $ \ ~(tex, big, pub, msg, sig) -> let !tex = S.precompute big = S.parse_int256 $ B16.decodeLenient "7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed" - pub = S.derive_pub big + Just pub = S.derive_pub big msg = "i approve of this message" - sig = S.sign_ecdsa big s_msg + Just sig = S.sign_ecdsa big s_msg pure (tex, big, pub, msg, sig) ecdh :: Benchmark diff --git a/bench/Weight.hs b/bench/Weight.hs @@ -94,9 +94,9 @@ ecdsa = W.wgroup "ecdsa" $ do W.func "verify_ecdsa" (S.verify_ecdsa msg pub) sig W.func "verify_ecdsa'" (S.verify_ecdsa' tex msg pub) sig where - pub = S.derive_pub big + Just pub = S.derive_pub big msg = "i approve of this message" - sig = S.sign_ecdsa big s_msg + Just sig = S.sign_ecdsa big s_msg ecdh :: W.Weigh () ecdh = W.wgroup "ecdh" $ do diff --git a/test/BIP340.hs b/test/BIP340.hs @@ -1,3 +1,4 @@ +{-# OPTIONS_GHC -fno-warn-incomplete-uni-patterns #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE ViewPatterns #-} @@ -56,8 +57,8 @@ execute tex Case {..} = testCase ("bip0340 " <> show c_index) $ -- XX test pubkey derivation from sk else do -- signature present; test sig too let sk = roll c_sk - sig = sign_schnorr sk c_msg c_aux - sig' = sign_schnorr' tex sk c_msg c_aux + Just sig = sign_schnorr sk c_msg c_aux + Just sig' = sign_schnorr' tex sk c_msg c_aux ver = verify_schnorr c_msg pk sig ver' = verify_schnorr' tex c_msg pk sig assertEqual mempty c_sig sig diff --git a/test/Noble.hs b/test/Noble.hs @@ -1,3 +1,4 @@ +{-# OPTIONS_GHC -fno-warn-incomplete-uni-patterns #-} {-# LANGUAGE BangPatterns #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RecordWildCards #-} @@ -40,8 +41,8 @@ execute_valid tex (label, ValidTest {..}) = let msg = vt_m x = vt_d pec = parse_compact vt_signature - sig = _sign_ecdsa_no_hash x msg - sig' = _sign_ecdsa_no_hash' tex x msg + Just sig = _sign_ecdsa_no_hash x msg + Just sig' = _sign_ecdsa_no_hash' tex x msg assertEqual mempty sig sig' assertEqual mempty pec sig diff --git a/test/WycheproofEcdh.hs b/test/WycheproofEcdh.hs @@ -44,7 +44,7 @@ execute EcdhTest {..} = H.testCase report $ do Right pub -> do let sec = parse_bigint t_private sar = parse_bigint t_shared - h_sar = SHA256.hash (unroll32 sar) + h_sar = Just (SHA256.hash (unroll32 sar)) out = ecdh pub sec H.assertEqual mempty h_sar out where