anubis_rage/
lib.rs

1//! # Anubis Rage - Post-Quantum Secure File Encryption
2//!
3//! <div style="background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); padding: 20px; border-radius: 10px; margin: 20px 0;">
4//! <h2 style="color: white; margin: 0;">🔐 Quantum-Resistant File Encryption</h2>
5//! <p style="color: white; margin: 10px 0 0 0;">Powered by ML-KEM-1024 (NIST FIPS 203) and ML-DSA-87 (NIST FIPS 204)</p>
6//! </div>
7//!
8//! **Anubis Rage** is a modern, secure file encryption tool and library implementing **NIST-standardized
9//! post-quantum cryptography** to protect your data against both current and future threats, including
10//! attacks from quantum computers.
11//!
12//! ## 🎯 Key Features
13//!
14//! - **🔒 Post-Quantum Security**: ML-KEM-1024 encryption resistant to quantum attacks
15//! - **✍️ Digital Signatures**: Mandatory ML-DSA-87 signatures for authenticated encryption (v1.1.0+)
16//! - **🏆 NIST Level-5 Security**: Highest standardized post-quantum security level (256-bit equivalent)
17//! - **⚡ High Performance**: Efficient implementation via liboqs
18//! - **🚀 Simple API**: Clean, ergonomic interface for both CLI and library usage
19//! - **🔐 Secure by Default**: No passphrases, no config files, explicit keys only
20//!
21//! ## 📦 Installation
22//!
23//! ### As a Library
24//!
25//! Add to your `Cargo.toml`:
26//! ```toml
27//! [dependencies]
28//! anubis-rage = "1.1"
29//! ```
30//!
31//! ### As CLI Tools
32//!
33//! ```bash
34//! cargo install anubis-rage
35//! ```
36//!
37//! This installs three command-line tools:
38//! - **`anubis-rage`** - Encrypt/decrypt files with quantum-resistant encryption
39//! - **`anubis-rage-keygen`** - Generate ML-KEM-1024 encryption keys
40//! - **`anubis-rage-sign`** - Generate ML-DSA-87 signing keys
41//!
42//! ## 🚀 Quick Start (Library)
43//!
44//! ### Basic Encryption/Decryption
45//!
46//! ```rust
47//! use anubis_rage::pqc::mlkem;
48//! use std::io::{Read, Write};
49//!
50//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
51//! // Generate ML-KEM-1024 keypair
52//! let identity = mlkem::Identity::generate();
53//! let recipient = identity.to_public();
54//!
55//! // Encrypt data
56//! let plaintext = b"Secret quantum-resistant message!";
57//! let encryptor = anubis_rage::Encryptor::with_recipients(vec![&recipient as _])?;
58//! let mut ciphertext = vec![];
59//! let mut writer = encryptor.wrap_output(&mut ciphertext)?;
60//! writer.write_all(plaintext)?;
61//! writer.finish()?;
62//!
63//! // Decrypt data
64//! let decryptor = anubis_rage::Decryptor::new(&ciphertext[..])?;
65//! let mut decrypted = vec![];
66//! decryptor.decrypt(vec![&identity as _])?.read_to_end(&mut decrypted)?;
67//!
68//! assert_eq!(decrypted, plaintext);
69//! println!("✓ Encryption and decryption successful!");
70//! # Ok(())
71//! # }
72//! ```
73//!
74//! ### Multiple Recipients
75//!
76//! ```rust
77//! use anubis_rage::pqc::mlkem;
78//! use std::io::Write;
79//!
80//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
81//! // Generate keys for multiple recipients
82//! let alice_identity = mlkem::Identity::generate();
83//! let bob_identity = mlkem::Identity::generate();
84//!
85//! let alice_recipient = alice_identity.to_public();
86//! let bob_recipient = bob_identity.to_public();
87//!
88//! // Encrypt to multiple recipients (any one can decrypt)
89//! let encryptor = anubis_rage::Encryptor::with_recipients(vec![
90//!     &alice_recipient as _,
91//!     &bob_recipient as _,
92//! ])?;
93//!
94//! let mut ciphertext = vec![];
95//! let mut writer = encryptor.wrap_output(&mut ciphertext)?;
96//! writer.write_all(b"Team secret")?;
97//! writer.finish()?;
98//!
99//! // Both Alice and Bob can decrypt
100//! let decryptor = anubis_rage::Decryptor::new(&ciphertext[..])?;
101//! let mut decrypted = vec![];
102//! decryptor.decrypt(vec![&alice_identity as _])?.read_to_end(&mut decrypted)?;
103//! assert_eq!(decrypted, b"Team secret");
104//! # Ok(())
105//! # }
106//! ```
107//!
108//! ## 💻 Quick Start (CLI)
109//!
110//! ### Generate Keys
111//!
112//! ```bash
113//! # Generate encryption keys
114//! anubis-rage-keygen -o my-key.txt
115//! # Public key: anubis1mlkem11ptpjg078r7rjw3x86e0mj346h8223derqruv8qx...
116//!
117//! # Generate signing keys (required for v1.1.0+)
118//! anubis-rage-sign keygen --output signing-key.txt
119//! # verification key: anubis1mldsa871tu22gw7ysld7gsw3c8dn7aydpagllmunu...
120//! ```
121//!
122//! ### Encrypt with Mandatory Signature (v1.1.0+)
123//!
124//! ```bash
125//! anubis-rage -r anubis1mlkem1... \
126//!     --signing-key signing-key.txt \
127//!     -o secrets.txt.age secrets.txt
128//! # File encrypted and signed with ML-DSA-87
129//! ```
130//!
131//! ### Decrypt with Mandatory Verification (v1.1.0+)
132//!
133//! ```bash
134//! anubis-rage -d \
135//!     --verify-key anubis1mldsa87... \
136//!     -i my-key.txt \
137//!     -o secrets.txt secrets.txt.age
138//! # Signature verified successfully
139//! ```
140//!
141//! ## 🔐 Security Guarantees
142//!
143//! ### Encryption (ML-KEM-1024)
144//!
145//! - **Algorithm**: Module-Lattice-Based Key-Encapsulation Mechanism
146//! - **Standard**: NIST FIPS 203 (approved August 2024)
147//! - **Security Level**: NIST Category 5 (≥256-bit equivalent)
148//! - **Security Property**: IND-CCA2 (Indistinguishability under Adaptive Chosen-Ciphertext Attack)
149//! - **Quantum Resistance**: Secure against Shor's and Grover's algorithms
150//! - **Key Sizes**:
151//!   - Public Key: 1,568 bytes
152//!   - Secret Key: 3,168 bytes
153//!   - Ciphertext: 1,568 bytes
154//!
155//! ### Digital Signatures (ML-DSA-87, Mandatory in v1.1.0+)
156//!
157//! - **Algorithm**: Module-Lattice-Based Digital Signature Algorithm
158//! - **Standard**: NIST FIPS 204 (approved August 2024)
159//! - **Security Level**: NIST Category 5 (≥256-bit equivalent)
160//! - **Security Property**: SUF-CMA (Strong Unforgeability under Chosen-Message Attack)
161//! - **Quantum Resistance**: Secure against quantum forgery attacks
162//! - **Key/Signature Sizes**:
163//!   - Public Key: 2,592 bytes
164//!   - Secret Key: 4,896 bytes
165//!   - Signature: 4,595 bytes
166//!
167//! ### Additional Security Features
168//!
169//! - **AEAD Encryption**: AES-256-GCM-SIV (RFC 8452, nonce-misuse resistant)
170//! - **Key Derivation**: HKDF-SHA512 (NIST SP 800-56C)
171//! - **Header Authentication**: HMAC-SHA512 (64-byte MAC)
172//! - **Forward Secrecy**: Ephemeral key wrapping
173//! - **No Metadata Leakage**: Recipient public keys not stored in ciphertext
174//!
175//! ## 🔄 Version Compatibility
176//!
177//! ### v1.1.0+ (Current) - Mandatory Signatures
178//!
179//! All files are automatically signed with ML-DSA-87:
180//! - Encryption requires `--signing-key`
181//! - Decryption requires `--verify-key`
182//! - Provides authenticated encryption
183//! - Detects tampering automatically
184//!
185//! ### v1.0.0 - Encryption Only
186//!
187//! - No signature support
188//! - Files lack authentication
189//! - **⚠️ Not compatible with v1.1.0+**
190//!
191//! **Migration**: Re-encrypt files with v1.1.0+ to add mandatory signatures.
192//!
193//! ## ⚡ Performance
194//!
195//! Benchmarks on 2023 MacBook Pro M2:
196//!
197//! | Operation | File Size | Time | Throughput |
198//! |-----------|-----------|------|------------|
199//! | Key Generation | - | ~2ms | - |
200//! | Encryption | 1 MB | ~8ms | 125 MB/s |
201//! | Encryption | 1 GB | ~7.5s | 133 MB/s |
202//! | Decryption | 1 MB | ~8ms | 125 MB/s |
203//! | Decryption | 1 GB | ~7.3s | 137 MB/s |
204//!
205//! ML-DSA-87 signature overhead (v1.1.0+):
206//! - Signing: +3-5ms
207//! - Verification: +3-5ms
208//! - File size: +4.6KB
209//!
210//! ## 📚 Advanced Usage
211//!
212//! ### Streaming Large Files
213//!
214//! ```rust
215//! use anubis_rage::pqc::mlkem;
216//! use std::fs::File;
217//! use std::io::{BufReader, BufWriter, copy};
218//!
219//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
220//! let identity = mlkem::Identity::generate();
221//! let recipient = identity.to_public();
222//!
223//! // Encrypt large file with streaming
224//! let input = BufReader::new(File::open("large-file.bin")?);
225//! let output = BufWriter::new(File::create("large-file.bin.age")?);
226//!
227//! let encryptor = anubis_rage::Encryptor::with_recipients(vec![&recipient as _])?;
228//! let mut writer = encryptor.wrap_output(output)?;
229//!
230//! // Stream data efficiently
231//! let mut reader = input;
232//! copy(&mut reader, &mut writer)?;
233//! writer.finish()?;
234//! # Ok(())
235//! # }
236//! ```
237//!
238//! ### ASCII Armor Format
239//!
240//! ```rust
241//! use anubis_rage::pqc::mlkem;
242//! use anubis_rage::armor::{ArmoredWriter, Format};
243//! use std::io::Write;
244//!
245//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
246//! let identity = mlkem::Identity::generate();
247//! let recipient = identity.to_public();
248//!
249//! let encryptor = anubis_rage::Encryptor::with_recipients(vec![&recipient as _])?;
250//!
251//! let mut output = vec![];
252//! let armored = ArmoredWriter::wrap_output(&mut output, Format::AsciiArmor)?;
253//! let mut writer = encryptor.wrap_output(armored)?;
254//!
255//! writer.write_all(b"Text-safe encrypted data")?;
256//! writer.finish()?.finish()?;
257//!
258//! // Output is ASCII-armored
259//! let armored_text = String::from_utf8(output)?;
260//! assert!(armored_text.starts_with("-----BEGIN AGE ENCRYPTED FILE-----"));
261//! # Ok(())
262//! # }
263//! ```
264//!
265//! ## 🆚 Comparison with Other Tools
266//!
267//! | Feature | Anubis Rage | age/rage | GPG | NaCl |
268//! |---------|-------------|----------|-----|------|
269//! | Post-Quantum | ✅ ML-KEM-1024 | ❌ X25519 | ❌ RSA/ECC | ❌ X25519 |
270//! | PQ Signatures | ✅ ML-DSA-87 | ❌ | ❌ | ❌ |
271//! | NIST Standardized | ✅ FIPS 203/204 | ❌ | ✅ (legacy) | ❌ |
272//! | Quantum Resistant | ✅ | ❌ | ❌ | ❌ |
273//! | Simple API | ✅ | ✅ | ❌ | ✅ |
274//! | No Config Files | ✅ | ✅ | ❌ | ✅ |
275//!
276//! ## 📖 Technical Documentation
277//!
278//! ### File Format
279//!
280//! Anubis Rage encrypted files use the following structure:
281//!
282//! ```text
283//! anubis-encryption.org/v1
284//! -> MLKEM-1024
285//! [base64-encoded-encapsulated-key]
286//! [base64-encoded-wrapped-file-key]
287//! -> [grease-stanza]
288//! [grease-body]
289//! --- [86-character-SHA512-MAC]
290//! [encrypted-payload]
291//! ```
292//!
293//! With ML-DSA-87 signatures (v1.1.0+), the entire encrypted file is signed.
294//!
295//! ### Cryptographic Primitives
296//!
297//! All primitives achieve strong security guarantees:
298//!
299//! | Component | Algorithm | Security |
300//! |-----------|-----------|----------|
301//! | KEM | ML-KEM-1024 | NIST L5 (≥256-bit) |
302//! | Signature | ML-DSA-87 | NIST L5 (≥256-bit) |
303//! | KDF | HKDF-SHA512 | 256-bit |
304//! | MAC | HMAC-SHA512 | 256-bit |
305//! | AEAD | AES-256-GCM-SIV | 256-bit + nonce-misuse resistant |
306//!
307//! ## 🔗 Resources
308//!
309//! - **GitHub**: [AnubisQuantumCipher/anubis-rage](https://github.com/AnubisQuantumCipher/anubis-rage)
310//! - **Crates.io**: [anubis-rage](https://crates.io/crates/anubis-rage)
311//! - **NIST PQC**: [Post-Quantum Cryptography Project](https://csrc.nist.gov/projects/post-quantum-cryptography)
312//! - **FIPS 203**: [ML-KEM Standard](https://csrc.nist.gov/pubs/fips/203/final)
313//! - **FIPS 204**: [ML-DSA Standard](https://csrc.nist.gov/pubs/fips/204/final)
314//!
315//! ## 🛡️ Security Disclosure
316//!
317//! If you discover a security vulnerability, please report it via:
318//! - **GitHub Security Advisories**: [Report a vulnerability](https://github.com/AnubisQuantumCipher/anubis-rage/security/advisories/new)
319//! - **GitHub Issues**: [Create an issue](https://github.com/AnubisQuantumCipher/anubis-rage/issues)
320//!
321//! ## 📄 License
322//!
323//! Licensed under either of:
324//! - Apache License, Version 2.0 ([LICENSE-APACHE](https://github.com/AnubisQuantumCipher/anubis-rage/blob/main/LICENSE-APACHE))
325//! - MIT license ([LICENSE-MIT](https://github.com/AnubisQuantumCipher/anubis-rage/blob/main/LICENSE-MIT))
326//!
327//! at your option.
328
329#![cfg_attr(docsrs, feature(doc_cfg))]
330#![forbid(unsafe_code)]
331#![deny(rustdoc::broken_intra_doc_links)]
332#![deny(missing_docs)]
333
334// Re-export the entire anubis-age library
335// Note: cargo will auto-download anubis-age and its dependencies
336pub use anubis_age::*;