Skip to main content

Module crypto

Module crypto 

Source
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::Zeroizing memory 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.
  • Debug for 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 password and salt using Argon2id.
fill_random
Fills buf with random bytes from the operating system CSPRNG.
open
Decrypts ciphertext_with_tag under key after verifying aad.
random_nonce
Generates a fresh random nonce.
seal
Encrypts plaintext under key, binding aad.
secure_compare
Constant-time equality comparison.

Type Aliases§

Nonce12
A 96-bit GCM nonce.