cryptkit
Cryptographic primitives for Rust — HMAC-SHA256, AES-GCM, constant-time comparison, and secure random with zeroize.
Purpose
cryptkit provides a curated set of cryptographic building blocks designed for application-level use:
- HMAC-SHA256 — keyed hashing for message authentication
- AES-256-GCM — authenticated encryption with associated data
- Constant-time comparison — prevents timing side-channel attacks
- SHA-256 — fast cryptographic hashing
- Secure random — OS-backed random byte generation with
zeroizesupport
All secret material is zeroized on drop via the zeroize crate.
Quick Start
HMAC-SHA256
use ;
let key = b"my-secret-key";
let message = b"important data";
let tag = hmac_sign;
assert!;
AES-256-GCM Encryption
use AesGcmEncryptor;
let enc = generate.unwrap;
let ciphertext = enc.encrypt.unwrap;
let plaintext = enc.decrypt.unwrap;
assert_eq!;
SHA-256 Hashing
use sha256;
let hash = sha256;
assert_eq!;
Constant-Time Comparison
use constant_time_eq;
assert!;
assert!;
Security Properties
#![forbid(unsafe_code)]— no unsafe in the entire crate- Zeroize on drop — all secret keys are cleared from memory when dropped
- Constant-time operations — HMAC verification and equality checks use
subtlecrate - OS entropy — random generation uses the platform CSPRNG
- No hard-coded keys or IVs — all nonces are randomly generated per encryption
Features
| Feature | Default | Description |
|---|---|---|
hmac_sha256 |
yes | HMAC-SHA256 signing and verification |
aes-gcm |
yes | AES-256-GCM authenticated encryption |
ed25519 |
no | Ed25519 signatures via ed25519-dalek |
fips |
no | FIPS-approved primitives via ring |
Comparison with other crates
vs hmac + sha2 directly
cryptkit wraps hmac and sha2 with a simpler API and adds constant-time verification. If you need fine-grained HMAC control, use the underlying crates directly.
vs ring
ring provides FIPS-grade primitives but has a complex build process and unsafe internals. cryptkit uses pure-Rust crates with #![forbid(unsafe_code)] for simplicity. Enable the fips feature to pull in ring when you need it.
vs aes-gcm directly
cryptkit wraps aes-gcm with automatic nonce generation and key management. The AesGcmEncryptor struct handles nonce storage in the ciphertext, so you don't need to manage nonces yourself.
vs rust-crypto
rust-crypto is unmaintained. cryptkit uses actively maintained, audited crates from the RustCrypto project.
MSRV
Rust 1.85 (edition 2024).
License
Licensed under either of Apache License, Version 2.0 or MIT License at your option.