hkdf

Pure Haskell HMAC-based KDF (docs.ppad.tech/hkdf).
git clone git://git.ppad.tech/hkdf.git
Log | Files | Refs | README | LICENSE

README.md (2832B)


      1 # hkdf
      2 
      3 [![](https://img.shields.io/hackage/v/ppad-hkdf?color=blue)](https://hackage.haskell.org/package/ppad-hkdf)
      4 ![](https://img.shields.io/badge/license-MIT-brightgreen)
      5 [![](https://img.shields.io/badge/haddock-hkdf-lightblue)](https://docs.ppad.tech/hkdf)
      6 
      7 A HMAC-based key derivation function (HKDF) per
      8 [RFC5869](https://datatracker.ietf.org/doc/html/rfc5869).
      9 
     10 ## Usage
     11 
     12 A sample GHCi session:
     13 
     14 ```
     15   > :set -XOverloadedStrings
     16   > -- import qualified
     17   > import qualified Crypto.KDF.HMAC as KDF
     18   >
     19   > -- supply your own HMAC function
     20   > import qualified Crypto.Hash.SHA256 as SHA256
     21   >
     22   > -- derive a 32-byte key from a secret
     23   > Just (KDF.derive SHA256.hmac "my salt" "my optional info" 32 "my secret input")
     24   "\EM\232\v\140\202\230\f2:\221n\221\209\233\US\209>\174_!\138\255\\C\150\237^X\226\tt\252"
     25 ```
     26 
     27 ## Documentation
     28 
     29 Haddocks (API documentation, etc.) are hosted at
     30 [docs.ppad.tech/hkdf][hadoc].
     31 
     32 ## Performance
     33 
     34 The aim is best-in-class performance for pure, highly-auditable Haskell
     35 code.
     36 
     37 Current benchmark figures on an M4 Silicon MacBook Air look like (use
     38 `cabal bench` to run the benchmark suite):
     39 
     40 ```
     41   benchmarking ppad-hkdf/HKDF-SHA256/derive (outlen 32)
     42   time                 6.787 μs   (6.780 μs .. 6.792 μs)
     43                        1.000 R²   (1.000 R² .. 1.000 R²)
     44   mean                 6.774 μs   (6.769 μs .. 6.778 μs)
     45   std dev              16.89 ns   (14.95 ns .. 19.57 ns)
     46 
     47   benchmarking ppad-hkdf/HKDF-SHA512/derive (outlen 32)
     48   time                 7.014 μs   (7.007 μs .. 7.019 μs)
     49                        1.000 R²   (1.000 R² .. 1.000 R²)
     50   mean                 7.003 μs   (6.999 μs .. 7.008 μs)
     51   std dev              16.60 ns   (13.60 ns .. 20.14 ns)
     52 ```
     53 
     54 ## Security
     55 
     56 This library aims at the maximum security achievable in a
     57 garbage-collected language under an optimizing compiler such as GHC, in
     58 which strict constant-timeness can be [challenging to achieve][const].
     59 
     60 The HKDF implementation within has been tested against the [Project
     61 Wycheproof vectors][wyche] available for SHA-256 and SHA-512, using
     62 the HMAC functions from [ppad-sha256][sh256] and [ppad-sha512][sh512]
     63 respectively.
     64 
     65 If you discover any vulnerabilities, please disclose them via
     66 security@ppad.tech.
     67 
     68 ## Development
     69 
     70 You'll require [Nix][nixos] with [flake][flake] support enabled. Enter a
     71 development shell with:
     72 
     73 ```
     74 $ nix develop
     75 ```
     76 
     77 Then do e.g.:
     78 
     79 ```
     80 $ cabal repl ppad-hkdf
     81 ```
     82 
     83 to get a REPL for the main library.
     84 
     85 [nixos]: https://nixos.org/
     86 [flake]: https://nixos.org/manual/nix/unstable/command-ref/new-cli/nix3-flake.html
     87 [hadoc]: https://docs.ppad.tech/hkdf
     88 [sh256]: https://git.ppad.tech/sha256
     89 [sh512]: https://git.ppad.tech/sha512
     90 [const]: https://www.chosenplaintext.ca/articles/beginners-guide-constant-time-cryptography.html
     91 [wyche]: https://github.com/C2SP/wycheproof