ppad-hkdf 0.1.0 → 0.2.0
raw patch · 5 files changed
+19/−12 lines, 5 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
- Crypto.KDF.HMAC: hkdf :: HMAC -> ByteString -> ByteString -> Word64 -> ByteString -> ByteString
+ Crypto.KDF.HMAC: derive :: HMAC -> ByteString -> ByteString -> Word64 -> ByteString -> ByteString
Files
- CHANGELOG +4/−0
- bench/Main.hs +5/−3
- lib/Crypto/KDF/HMAC.hs +6/−5
- ppad-hkdf.cabal +1/−1
- test/Main.hs +3/−3
CHANGELOG view
@@ -1,5 +1,9 @@ # Changelog +- 0.2.0 (2025-01-10)+ * API change, opting for "derive" in place of "hkdf" to work more+ smoothly with a import qualifier like "KDF".+ - 0.1.0 (2025-01-10) * Initial release, supporting a generic RFC5869 HKDF function.
bench/Main.hs view
@@ -3,7 +3,7 @@ module Main where import Criterion.Main-import qualified Crypto.KDF.HMAC as K+import qualified Crypto.KDF.HMAC as KDF import qualified Crypto.Hash.SHA256 as SHA256 import qualified Crypto.Hash.SHA512 as SHA512 @@ -16,10 +16,12 @@ suite = bgroup "ppad-hkdf" [ bgroup "HKDF-SHA256" [- bench "32" $ nf (K.hkdf SHA256.hmac "muh salt" "muh info" 32) "muh secret"+ bench "derive (outlen 32)" $+ nf (KDF.derive SHA256.hmac "muh salt" "muh info" 32) "muh secret" ] , bgroup "HKDF-SHA512" [- bench "32" $ nf (K.hkdf SHA512.hmac "muh salt" "muh info" 32) "muh secret"+ bench "derive (outlen 32)" $+ nf (KDF.derive SHA512.hmac "muh salt" "muh info" 32) "muh secret" ] ]
lib/Crypto/KDF/HMAC.hs view
@@ -13,7 +13,7 @@ module Crypto.KDF.HMAC ( -- * HMAC-based KDF- hkdf+ derive , HMAC -- internals@@ -75,22 +75,23 @@ in go (succ j) (t <> BSB.byteString nt) nt {-# INLINE expand #-} --- | HMAC-based key derivation function.+-- | Derive a key from a secret, via a HMAC-based key derivation+-- function. -- -- The /salt/ and /info/ arguments are optional to the KDF, and may -- be simply passed as 'mempty'. An empty salt will be replaced by -- /hashlen/ zero bytes. -- -- >>> import qualified Crypto.Hash.SHA256 as SHA256--- >>> hkdf SHA256.hmac "my public salt" mempty 64 "my secret input"+-- >>> derive SHA256.hmac "my public salt" mempty 64 "my secret input" -- <64-byte output keying material>-hkdf+derive :: HMAC -- ^ HMAC function -> BS.ByteString -- ^ salt -> BS.ByteString -- ^ optional context and application-specific info -> Word64 -- ^ bytelength of output keying material (<= 255 * hashlen) -> BS.ByteString -- ^ input keying material -> BS.ByteString -- ^ output keying material-hkdf hmac salt info len = expand env info len . extract env salt where+derive hmac salt info len = expand env info len . extract env salt where env = HMACEnv hmac (fi (BS.length (hmac mempty mempty)))
ppad-hkdf.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.0 name: ppad-hkdf-version: 0.1.0+version: 0.2.0 synopsis: A HMAC-based key derivation function license: MIT license-file: LICENSE
test/Main.hs view
@@ -6,7 +6,7 @@ import Control.Exception import qualified Crypto.Hash.SHA256 as SHA256 import qualified Crypto.Hash.SHA512 as SHA512-import qualified Crypto.KDF.HMAC as H+import qualified Crypto.KDF.HMAC as KDF import qualified Data.ByteString as BS import qualified Data.Aeson as A import qualified Data.Text.IO as TIO@@ -52,13 +52,13 @@ pec = ht_okm if ht_result == "invalid" then do- out <- try (pure $! H.hkdf hmac sal inf siz ikm)+ out <- try (pure $! KDF.derive hmac sal inf siz ikm) :: IO (Either ErrorCall BS.ByteString) case out of Left _ -> assertBool "invalid" True Right o -> assertBool "invalid" (pec /= o) else do- let out = H.hkdf hmac sal inf siz ikm+ let out = KDF.derive hmac sal inf siz ikm assertEqual mempty pec out where hmac = case h of