Expand description
Cryptographic primitives: keys, AEAD, KDF. Low-level cryptographic primitives.
Everything in this module is building-block level: authenticated
encryption with associated data (AES-256-GCM), password key derivation
(Argon2id), per-file subkey derivation (HKDF-SHA256) and constant-time
comparison. The higher-level single-file and vault APIs compose these
primitives; most applications should use crate::encrypt_file,
crate::decrypt_file or crate::Vault instead.
§Design notes
- All keys live in
zeroize::Zeroizingmemory and are overwritten when dropped. Keys are passed by reference; no public API hands out raw key bytes by value. - Every AEAD operation takes associated data (AAD). Callers bind all unauthenticated header fields through AAD — this is what makes truncation, reordering and format-confusion attacks detectable.
Debugfor keys is manually implemented and never prints key bytes.
Structs§
- Key
- A 32-byte symmetric key stored in zeroizing memory.
Constants§
- KEY_LEN
- Symmetric key length in bytes (AES-256).
- NONCE_
LEN - GCM nonce length in bytes.
- SALT_
LEN - Raw salt length used by new (v3+) containers.
- TAG_LEN
- GCM authentication tag length in bytes.
Functions§
- derive_
key - Derives a 256-bit key from
passwordandsaltusing Argon2id. - fill_
random - Fills
bufwith random bytes from the operating system CSPRNG. - open
- Decrypts
ciphertext_with_tagunderkeyafter verifyingaad. - random_
nonce - Generates a fresh random nonce.
- seal
- Encrypts
plaintextunderkey, bindingaad. - secure_
compare - Constant-time equality comparison.
Type Aliases§
- Nonce12
- A 96-bit GCM nonce.