PBKDF2 key derivation function for OCaml (RFC 2898)
OCaml 71.8%
Python 9.9%
Dune 5.6%
Other 12.7%
14 1 0

Clone this repository

https://tangled.org/gazagnaire.org/ocaml-pbkdf2 https://tangled.org/did:plc:jhift2vwcxhou52p3sewcrpx/ocaml-pbkdf2
git@git.recoil.org:gazagnaire.org/ocaml-pbkdf2 git@git.recoil.org:did:plc:jhift2vwcxhou52p3sewcrpx/ocaml-pbkdf2

For self-hosted knots, clone URLs may differ based on your setup.

Download tar.gz
README.md

pbkdf2#

Password-Based Key Derivation Function 2 (RFC 8018) for OCaml.

Overview#

pbkdf2 provides a pure OCaml implementation of PBKDF2-HMAC-SHA256 as specified in RFC 8018. PBKDF2 derives cryptographic keys from passwords using a pseudorandom function (HMAC-SHA256), applying it iteratively to resist brute-force attacks.

Features#

  • RFC 8018 compliant: Implements PBKDF2-HMAC-SHA256
  • Configurable iterations: Control computational cost for security
  • Pure OCaml: No C dependencies, works everywhere OCaml runs
  • Fuzz tested: Includes Crowbar-based property tests

Installation#

opam install pbkdf2

Usage#

(* Derive a 32-byte key from a password *)
let key = Pbkdf2.derive
  ~password:"user_password"
  ~salt:random_salt
  ~iterations:100000
  ~length:32

API#

  • Pbkdf2.derive ~password ~salt ~iterations ~length - Derive a key using PBKDF2-HMAC-SHA256
  • Pbkdf2.hash_length - Output length of the underlying hash (32 bytes for SHA-256)

Security Recommendations#

  • Use at least 100,000 iterations for password hashing (OWASP recommendation)
  • Generate random salts of at least 16 bytes
  • Use unique salts per password
  • kdf - Key derivation functions including HKDF, PBKDF, and SCRYPT. Uses mirage-crypto for PBKDF2-SHA256.
  • pbkdf - PBKDF1/PBKDF2 implementation using nocrypto (archived, now part of kdf).

This library provides a minimal, standalone PBKDF2-HMAC-SHA256 implementation using digestif.

Licence#

MIT License. See LICENSE.md for details.