rs-crypto-hkdf 0.1.0
HKDF key derivation (RFC 5869) over HMAC-SHA256 and HMAC-SHA512, with its own SHA-2 and HMAC inside, std only
Install
cargo add rs-crypto-hkdf --registry rupm
In Ruststudio: Packages, search for rs-crypto-hkdf, Install.
Owner: Rust Studio. Licence: MIT OR Apache-2.0. Total downloads: 0. Published 2026-11-23.
Versions
- 0.1.0 2026-11-23
README
# rs-crypto-hkdf
HKDF key derivation (RFC 5869) over HMAC-SHA256 and HMAC-SHA512, with its own SHA-2 and HMAC inside, std only
Add it with `rupm add rs-crypto-hkdf` (or `cargo add rs-crypto-hkdf --registry rupm`).
The extract and expand steps are checked against the RFC 5869 test vectors (SHA-256) and the SHA-2 and HMAC parts against NIST and RFC 4231 vectors. This is a plain, unaudited implementation that is not constant-time: do not use it for security-critical work, use an audited crate there.
## Install
```
rupm add rs-crypto-hkdf
```
## Usage
```rust
use rs_crypto_hkdf::{hkdf, Hash};
// Derive 32 bytes of key material from a shared secret.
let okm = hkdf(Hash::Sha256, b"salt", b"input key material", b"app v1 encryption key", 32).unwrap();
assert_eq!(okm.len(), 32);
// Or run the two steps yourself.
let prk = rs_crypto_hkdf::extract(Hash::Sha512, b"salt", b"input key material");
let key = rs_crypto_hkdf::expand(Hash::Sha512, &prk, b"context", 16).unwrap();
assert_eq!(key.len(), 16);
```
## API overview
- `Hash`: `Sha256` or `Sha512`, with `output_len`.
- `extract(hash, salt, ikm)`: HKDF-Extract, returns the pseudorandom key.
- `expand(hash, prk, info, len)`: HKDF-Expand, up to 255 times the hash length bytes; returns `Result`.
- `hkdf(hash, salt, ikm, info, len)`: both steps in one call.
- `hmac(hash, key, data)`: the HMAC used underneath.
- `Error`: `PrkTooShort` or `OutputTooLong`.