Overview
Rustic uses:- AES-256-CTR for encryption
- Poly1305-AES for authentication (MAC)
- SHA-256 for hashing
- scrypt for key derivation from passwords
- Confidentiality (encryption)
- Integrity (MAC)
- Content-addressed storage (hashing)
Key Structure
The master key is 64 bytes, split into three parts:Creating Keys
Encryption
Encryption adds a random nonce and authentication tag:Decryption
Decryption verifies the MAC before returning plaintext:Hashing
SHA-256 hashing for content-addressed storage:Streaming Hash
For large data:Key Derivation
Password-based key derivation using scrypt:Deriving Key from Password
- N = 2^15 = 32768 (log_n = 15)
- r = 8
- p = 1
- 64-byte output
Generating Key Files
MasterKey Structure
The master key is encrypted and stored:CryptoKey Trait
Generic interface for encryption/decryption:Key for AES-256-CTR + Poly1305-AES.
Security Properties
Authenticated Encryption (AEAD)
- Confidentiality: AES-256 in CTR mode
- Authenticity: Poly1305-AES MAC
- Random IVs: Each encryption uses fresh nonce
Content Addressing
- SHA-256 hashing: 256-bit security
- Collision resistance: Deduplication is safe
- Tamper detection: Changed data = different ID
Key Derivation
- scrypt: Memory-hard, GPU-resistant
- Random salt: 64 bytes per key file
- Tunable cost: Increase N for more security
Common Patterns
Encrypting Repository Data
Decrypting Repository Data
Content-Addressed Blobs
Error Handling
Crypto errors indicate serious problems:Performance
Encryption overhead:- 32 bytes per blob (nonce + tag)
- ~10-50 MB/s on modern CPUs
- scrypt: ~100ms per password check
- Intentionally slow (prevents brute force)
- SHA-256: ~500 MB/s per core
- Streaming for large files
See Also
- Repository Files - KeyFile format
- Blob Types - Encrypted blob storage
- Repository - Using crypto in operations