Supported Algorithms
QIMEM provides authenticated encryption with associated data (AEAD) through two algorithms:AES-256-GCM (Always Available)
Source: src/crypto.rs:18-19- Cipher: AES with 256-bit keys
- Mode: Galois/Counter Mode (GCM)
- Tag Size: 128 bits (16 bytes)
- Nonce: 96 bits (12 bytes), randomly generated per encryption
- Use Case: Industry-standard AEAD cipher with hardware acceleration on modern CPUs (AES-NI)
AES-256-GCM is enabled by default and requires no feature flags.
ChaCha20-Poly1305 (Optional)
Source: src/crypto.rs:20-22- Cipher: ChaCha20 stream cipher
- MAC: Poly1305 authenticator
- Tag Size: 128 bits (16 bytes)
- Nonce: 96 bits (12 bytes)
- Use Case: Software-optimized AEAD for environments without AES hardware support
CryptoEngine
Source: src/crypto.rs:44-123 TheCryptoEngine struct provides a unified interface for encryption and decryption operations:
Creating an Engine
The algorithm choice is made at engine creation time and enforced during decryption to prevent algorithm confusion attacks.
Encryption Process
Source: src/crypto.rs:56-92Step-by-Step Flow
-
Active Key Check (src/crypto.rs:58-60)
Only active keys can encrypt new data.
-
Nonce Generation (src/crypto.rs:61-62)
Uses OS-provided cryptographically secure random number generator.
-
AEAD Encryption (src/crypto.rs:64-80)
-
Tag Separation (src/crypto.rs:82)
The 16-byte authentication tag is extracted from the ciphertext.
-
Envelope Construction (src/crypto.rs:84-91)
Example
Decryption Process
Source: src/crypto.rs:94-123Step-by-Step Flow
-
Algorithm Validation (src/crypto.rs:96-98)
Ensures the engine is configured for the envelope’s algorithm.
-
Tag Recombination (src/crypto.rs:99-100)
-
AEAD Decryption (src/crypto.rs:102-121)
If the tag verification fails,
QimemError::Decryptionis returned.
Example
Key Material Wrapping
Source: src/keystore/mod.rs:31-40 All key material is wrapped withzeroize::Zeroizing to prevent sensitive data from lingering in memory:
Benefits
- Automatic Zeroing: Memory is overwritten when the
KeyMaterialis dropped - Defense Against Cold Boot Attacks: Reduces exposure window for key material in RAM
- Compiler Guarantees: Cannot be optimized away by compiler
Key Generation
Source: src/keystore/mod.rs:52-56- Length: 256 bits (32 bytes) for AES-256 and ChaCha20
- Source: OS-provided CSPRNG via
rand_core::OsRng - Entropy: Full 256 bits of cryptographic entropy
Algorithm Identifiers
Source: src/crypto.rs:25-42 Each algorithm is assigned a numeric ID for binary serialization:Unknown algorithm IDs return
QimemError::UnsupportedAlgorithm to prevent processing of future or unsupported formats.Security Considerations
No Key Reuse
Each encryption generates a fresh random nonce, ensuring nonce uniqueness even for the same plaintext and key.Constant-Time Operations
The underlyingaes-gcm and chacha20poly1305 crates implement constant-time cryptography to prevent timing side-channels.
No Unsafe Code
Next Steps
Envelope Format
Learn how encrypted data is serialized
Key Rotation
Understand key lifecycle management