hkdf

Pure Rust, no-std implementation of the HMAC-based Extract-and-Expand Key Derivation Function

Library
Cargo
v0.13.0
104stars
MIT OR Apache-2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
54/100Fair
Development Activity56
Maintenance12
Community76
Maturity60
Momentum12

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
73/100Good
Architecture75
Code Quality78
Innovation68
Learning Curve70

hkdf is the RustCrypto project’s pure-Rust implementation of HKDF (RFC 5869), the HMAC-based Extract-and-Expand Key Derivation Function used to turn non-uniform input key material — such as a Diffie-Hellman shared secret — into one or more cryptographically strong keys. It is generic over any hash function implementing the digest crate traits, works in no_std environments, and exposes both a combined Hkdf::new API and separate extract/expand steps for callers that need access to the intermediate pseudorandom key.

As part of the broader RustCrypto/KDFs workspace, the crate is maintained alongside sibling key-derivation-function crates (ANSI-X9.63-KDF, bake-kdf, Concat-KDF, KBKDF) and shares their testing infrastructure, MSRV policy, and dual Apache-2.0/MIT licensing. It is one of the most widely depended-upon low-level cryptographic crates in the Rust ecosystem, used by TLS, cryptocurrency, and secure-messaging libraries wherever key material needs to be derived deterministically from a shared secret.

What You Get

  • A Hkdf<H> type generic over any hash function implementing the digest/hmac traits (SHA-1, SHA-2, SHA-3, BLAKE2, etc.)
  • Combined new/expand API for the common case, plus separate extract/from_prk calls for advanced use cases that need the intermediate pseudorandom key
  • no_std support with zero required allocation, suitable for embedded and constrained environments
  • An optional SimpleHmac-backed variant (SimpleHkdf) for hash functions without a dedicated HMAC optimization
  • Test vectors from RFC 5869 and Project Wycheproof exercised in the crate’s own test suite

Common Use Cases

  • Deriving symmetric encryption/authentication keys from a Diffie-Hellman shared secret in a handshake protocol
  • Expanding a single high-entropy master key into multiple purpose-specific subkeys
  • Key derivation steps inside higher-level protocol implementations (TLS 1.3, Noise Protocol, Signal-style ratchets)
  • Deterministically generating keys for envelope encryption or key-wrapping schemes

Under The Hood

Architecture hkdf.rs exposes GenericHkdf<H>/GenericHkdfExtract<H> structs generic over an HmacImpl trait (src/hmac_impl.rs), with Hkdf<H>/HkdfExtract<H> as Hmac-backed type aliases and SimpleHkdf<H>/SimpleHkdfExtract<H> as SimpleHmac-backed alternatives for hashes lacking a dedicated HMAC fast path. The public surface in src/lib.rs (177 lines) is intentionally small: new, extract, from_prk, and expand/expand_multi_info, mirroring RFC 5869’s Extract-then-Expand two-step construction while allowing callers to skip the extract step if they already hold a strong PRK. An optional kdf feature implements the generic Kdf trait from the sibling kdf crate so HKDF can be used interchangeably with other KDFs in the workspace. Tech Stack Pure Rust, no_std by default (src/lib.rs #![no_std]), depending only on the hmac crate (itself generic over digest); dev-dependencies pull in sha1/sha2 and the blobby test-vector-parsing crate for RFC 5869/Wycheproof conformance tests. Edition 2024, MSRV 1.85, part of a Cargo workspace shared with four sibling KDF crates (ansi-x963-kdf, bake-kdf, kbkdf, one-step-kdf) under a single top-level Cargo.toml. Code Quality The crate carries an extensive workspace-wide Clippy lint configuration (unsafe_code = "forbid", unwrap_used, missing_docs, cast_* lints all set to warn/forbid), and its tests/ directory runs both the official RFC 5869 test vectors (tests/rfc5869.rs) and Google’s Project Wycheproof vectors (tests/wycheproof.rs) against tests/data, giving strong confidence in cryptographic correctness beyond unit tests alone. Error handling uses explicit typed errors (InvalidLength, InvalidPrkLength in src/errors.rs) rather than panics for user-facing failure modes. API Design The API mirrors RFC 5869’s own extract/expand vocabulary closely, keeping the mental model thin for anyone who has read the spec; Hkdf::new covers the 90% case in one call, while extract/from_prk are opt-in for advanced composition. Minimal external dependencies and no_std support make it a low-friction building block inside other protocol crates rather than a standalone tool.

Used by 8 apps in this directory

TypeScript
51%
MIT

Anarlog

Note Taking · AI Assistants · Productivity

9,087

Anarlog is an open-source, local-first AI meeting notetaker that records, transcribes, and summarizes meetings entirely on your device — no cloud lock-in, no mandatory account, and every note saved as a plain markdown file you own forever.

View details
86
Repo Health
77
Technical
69
Dependency
Built with
TypeScript51%
Rust38%
Updated today
TypeScript
75%
GPL 3.0

Bramble

Password Manager · Security · Authentication

315

Local-first, end-to-end encrypted password manager that syncs your vault directly between your own devices over a private peer-to-peer mesh — no server, no account, no cloud in the middle.

View details
73
Repo Health
84
Technical
72
Dependency
Built with
TypeScript75%
Updated today
Rust
50%
Other

hoodik

File Storage · Security

1,446

Self-hosted, end-to-end encrypted cloud storage with browser-based encryption and S3-compatible storage support

View details
74
Repo Health
71
Technical
65
Dependency
Built with
Rust50%
TypeScript33%
Vue15%
Updated 4 days ago
Rust
95%
Apache 2.0

obscura

AI Agents · Developer Tools

21,654

A lightweight, stealthy headless browser written in Rust — drop-in compatible with Puppeteer and Playwright, built for AI agents and web scraping at scale.

View details
80
Repo Health
79
Technical
75
Dependency
Built with
Rust95%
Updated 4 days ago
Python
74%
AGPL 3.0

OpenViking

Databases · AI Development

29,711

An open-source context database that gives AI agents a unified filesystem for memory, resources, and skills with hierarchical tiered retrieval.

View details
84
Repo Health
75
Technical
65
Dependency
Built with
Python74%
Rust14%
Updated today
Rust
77%
AGPL 3.0

Spacedrive

File Storage · Collaboration

38,790

One file manager for all your devices and clouds — powered by a Virtual Distributed File System built in Rust.

View details
60
Repo Health
84
Technical
65
Dependency
Built with
Rust77%
TypeScript20%
Updated 3 weeks ago
Rust
98%

Stalwart

Collaboration

14,255

All-in-one secure mail and collaboration server covering IMAP, JMAP, SMTP, CalDAV, CardDAV, and WebDAV in a single memory-safe Rust binary.

View details
89
Repo Health
81
Technical
68
Dependency
Built with
Rust98%
Updated yesterday
Rust
50%
Apache 2.0

Vibe Kanban

AI Agents · AI Code Assistants · Project Management

27,849

A kanban board for planning work and dispatching Claude Code, Codex, Gemini CLI, and eight other coding agents into isolated git worktrees, then reviewing and merging their diffs from one UI.

View details
53
Repo Health
75
Technical
65
Dependency
Built with
Rust50%
TypeScript46%
Updated 3 months ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search