commit 81897d9b54b49e9dc0f042420f8aa4971376281f
parent ee40b39f69f79e77ce50ca9be31e0e4679839b8a
Author: Jared Tobin <jared@jtobin.io>
Date: Wed, 4 Feb 2026 17:42:17 +0400
lib: update to newer ppad-hmac-drbg dependency
Diffstat:
2 files changed, 22 insertions(+), 22 deletions(-)
diff --git a/flake.lock b/flake.lock
@@ -122,11 +122,11 @@
]
},
"locked": {
- "lastModified": 1768057958,
- "narHash": "sha256-Csrv+J0WnGankFhvEMQsHnLd3h8zVpmTKV5WaHD5LoM=",
+ "lastModified": 1770211545,
+ "narHash": "sha256-D19hrPxPc81A/7MvOiYeWXItlgDwAdEw5wgqOgOMoDo=",
"owner": "ppad-tech",
"repo": "hmac-drbg",
- "rev": "c6487458ef620c4f83bdbc7494f5f48c989133b6",
+ "rev": "0ab3f384fa77f18b515d140cf35dcc082cd38957",
"type": "github"
},
"original": {
@@ -175,11 +175,11 @@
]
},
"locked": {
- "lastModified": 1768045644,
- "narHash": "sha256-8+jLaYRN8iX6NmyotE7DvjfjUIT8I0KOchgcP7uq7Vo=",
+ "lastModified": 1769942235,
+ "narHash": "sha256-6NlOumhA4BD9Eihfb58mjfueHLM6t3wxpcHAYsntbMg=",
"ref": "master",
- "rev": "4716cd5b4e673e9cb66e4e5e427e5464a7c10977",
- "revCount": 116,
+ "rev": "40792bf33df4582897000fc331a75cc458db9463",
+ "revCount": 127,
"type": "git",
"url": "git://git.ppad.tech/sha256.git"
},
@@ -209,11 +209,11 @@
]
},
"locked": {
- "lastModified": 1768045869,
- "narHash": "sha256-ySqv5fQRz+/9X54yXCuck2QnGyuIqRLpRzanh+Ehl88=",
+ "lastModified": 1769944296,
+ "narHash": "sha256-uw4EgnM5yQF6LmkkxHY0PJLNko8Wad9aq7GEtacEM3g=",
"ref": "master",
- "rev": "0fbaba3c091692622744d30016e36ca6b726a819",
- "revCount": 42,
+ "rev": "8fa68ca2fcfc589e7716be9162e2fef52293516a",
+ "revCount": 48,
"type": "git",
"url": "git://git.ppad.tech/sha512.git"
},
diff --git a/lib/Crypto/Curve/Secp256k1.hs b/lib/Crypto/Curve/Secp256k1.hs
@@ -105,7 +105,7 @@ module Crypto.Curve.Secp256k1 (
import Control.Monad (guard)
import Control.Monad.ST
-import qualified Crypto.DRBG.HMAC as DRBG
+import qualified Crypto.DRBG.HMAC.SHA256 as DRBG
import qualified Crypto.Hash.SHA256 as SHA256
import qualified Data.Bits as B
import qualified Data.ByteString as BS
@@ -1261,13 +1261,10 @@ _sign_ecdsa _mul ty hf _SECRET m = runST $ do
-- RFC6979 sec 3.3a
let entropy = int2octets _SECRET
nonce = bits2octets h
- drbg <- DRBG.new hmac entropy nonce mempty
+ drbg <- DRBG.new entropy nonce mempty
-- RFC6979 sec 2.4
sign_loop drbg
where
- hmac k b = case SHA256.hmac k b of
- SHA256.MAC mac -> mac
-
d = S.to _SECRET
hm = S.to (bits2int h)
h = case hf of
@@ -1283,21 +1280,24 @@ _sign_ecdsa _mul ty hf _SECRET m = runST $ do
s = (hm + d * r) * ki
pure $! (S.retr r, S.retr s)
case mpair of
- Nothing -> pure Nothing
+ Nothing -> do
+ DRBG.wipe g
+ pure Nothing
Just (r, s)
| W.eq_vartime r 0 -> sign_loop g -- negligible probability
- | otherwise ->
+ | otherwise -> do
+ DRBG.wipe g
let !sig = Just $! ECDSA r s
- in case ty of
- Unrestricted -> pure sig
- LowS -> pure (fmap low sig)
+ pure $ case ty of
+ Unrestricted -> sig
+ LowS -> fmap low sig
{-# INLINE _sign_ecdsa #-}
-- RFC6979 sec 3.3b
gen_k :: DRBG.DRBG s -> ST s Wider
gen_k g = loop g where
loop drbg = do
- bytes <- DRBG.gen mempty (fi _CURVE_Q_BYTES) drbg
+ bytes <- DRBG.gen drbg mempty (fi _CURVE_Q_BYTES)
case bytes of
Left {} -> error "ppad-secp256k1: internal error (please report a bug!)"
Right bs -> do