ppad-pbkdf-0.2.0: A password-based key derivation function
Copyright(c) 2025 Jared Tobin
LicenseMIT
MaintainerJared Tobin <jared@ppad.tech>
Safe HaskellSafe-Inferred
LanguageHaskell2010

Crypto.KDF.PBKDF

Description

A pure PBKDF2 (password-based key derivation function) implementation, as specified by RFC2898.

Synopsis

HMAC synonym

type HMAC = ByteString -> ByteString -> ByteString Source #

A HMAC function, taking a key as the first argument and the input value as the second, producing a MAC digest.

(RFC2898 specifically requires a "pseudorandom function" of two arguments, but in practice this will usually be a HMAC function.)

>>> import qualified Crypto.Hash.SHA256 as SHA256
>>> :t SHA256.hmac
SHA256.hmac :: BS.ByteString -> BS.ByteString -> BS.ByteString
>>> SHA256.hmac "my HMAC key" "my HMAC input"
<256-bit MAC>

PBKDF2

derive Source #

Arguments

:: HMAC

pseudo-random function (HMAC)

-> ByteString

password

-> ByteString

salt

-> Word64

iteration count

-> Word32

bytelength of derived key (max 0xffff_ffff * hlen)

-> Maybe ByteString

derived key

Derive a key from a secret via the PBKDF2 key derivation function.

>>> :set -XOverloadedStrings
>>> import qualified Crypto.Hash.SHA256 as SHA256
>>> import qualified Data.ByteString as BS
>>> import qualified Data.ByteString.Base16 as B16
>>> let Just key = derive SHA256.hmac "passwd" "salt" 1 64
>>> BS.take 16 (B16.encode key)
"55ac046e56e3089f"