hkdf

Pure Haskell HKDF (docs.ppad.tech/hkdf).
git clone git://git.ppad.tech/hkdf.git
Log | Files | Refs | README | LICENSE

commit 5c310fb56f6a605581274343714bb3fd9bf00cee
parent caeb2c6cf101ee2dac766f849f3ea12a5e3f1c4a
Author: Jared Tobin <jared@jtobin.io>
Date:   Fri, 10 Jan 2025 14:54:50 +0400

lib: hkdf indexing/overflow fixes

Diffstat:
Mlib/Crypto/KDF/HMAC.hs | 6+++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/Crypto/KDF/HMAC.hs b/lib/Crypto/KDF/HMAC.hs @@ -65,13 +65,13 @@ expand -> BS.ByteString -- ^ output keying material expand (HMACEnv hmac hashlen) info (fi -> len) prk | len > 255 * hashlen = error "ppad-hkdf (expand): invalid outlength" - | otherwise = BS.take len (go 0 mempty mempty) + | otherwise = BS.take len (go (1 :: Int) mempty mempty) where n = ceiling ((fi len :: Double) / (fi hashlen :: Double)) :: Int go !j t !tl - | j == fi n = BS.toStrict (BSB.toLazyByteString t) + | j > fi n = BS.toStrict (BSB.toLazyByteString t) | otherwise = - let nt = hmac prk (tl <> info <> BS.singleton j) + let nt = hmac prk (tl <> info <> BS.singleton (fi j)) in go (succ j) (t <> BSB.byteString nt) nt -- | HMAC-based key derivation function.