Ever Crypto
A simple Rust library providing easy-to-use APIs for modern cryptographic operations, specifically:
- XChaCha20Poly1305: Authenticated encryption with extended nonce support
- Kyber1024: Post-quantum key encapsulation mechanism
Features
- 🔒 XChaCha20Poly1305 - Fast, secure authenticated encryption
- 🛡️ Kyber1024 - Post-quantum cryptography ready
- 🚀 Simple API - Easy to use, hard to misuse
- 🔐 Memory Safety - Automatic secure memory cleanup with zeroization
- ✅ Well Tested - Comprehensive test suite
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
Usage Examples
XChaCha20Poly1305 Encryption
use ;
// Generate a key and nonce
let key = generate;
let nonce = generate;
// Encrypt a message
let plaintext = b"Hello, World!";
let ciphertext = encrypt.unwrap;
// Decrypt the message
let decrypted = decrypt.unwrap;
assert_eq!;
XChaCha20Poly1305 with Additional Authenticated Data (AAD)
use ;
let key = generate;
let plaintext = b"Secret message";
let aad = b"Additional authenticated data";
// Encrypt with random nonce
let = encrypt_with_random_nonce.unwrap;
// Decrypt
let decrypted = decrypt.unwrap;
assert_eq!;
Kyber1024 Key Encapsulation
use ;
// Alice generates a key pair
let alice_keypair = generate_keypair;
// Bob encapsulates a shared secret for Alice
let = encapsulate;
// Alice decapsulates the shared secret
let alice_shared_secret = decapsulate;
// Both parties now have the same shared secret
assert_eq!;
Hybrid Encryption (Kyber1024 + XChaCha20Poly1305)
use ;
// Step 1: Key establishment with Kyber1024
let alice_keypair = generate_keypair;
let = encapsulate;
// Step 2: Use shared secret as XChaCha20Poly1305 key
let xchacha_key = from_bytes.unwrap;
// Step 3: Encrypt data with XChaCha20Poly1305
let plaintext = b"This is a secret message using hybrid encryption!";
let = encrypt_with_random_nonce.unwrap;
// Decryption process:
// Step 1: Alice decapsulates the shared secret
let alice_shared_secret = decapsulate;
let alice_xchacha_key = from_bytes.unwrap;
// Step 2: Decrypt the message
let decrypted = decrypt.unwrap;
assert_eq!;
API Reference
XChaCha20Poly1305
Types
XChaChaKey: 256-bit encryption keyXChaChaNonce: 192-bit nonce (24 bytes)XChaChaCrypto: Main encryption/decryption operations
Methods
XChaChaKey::generate(): Generate a random keyXChaChaKey::from_bytes(bytes): Create key from bytesXChaChaNonce::generate(): Generate a random nonceXChaChaCrypto::encrypt(key, nonce, plaintext, aad): Encrypt dataXChaChaCrypto::decrypt(key, nonce, ciphertext, aad): Decrypt dataXChaChaCrypto::encrypt_with_random_nonce(key, plaintext, aad): Encrypt with auto-generated nonce
Kyber1024
Types
KyberKeyPair: Public and secret key pairKyberPublicKey: Public key for encapsulationKyberSecretKey: Secret key for decapsulationKyberSharedSecret: 32-byte shared secretKyberCiphertext: Encapsulated ciphertext
Methods
KyberCrypto::generate_keypair(): Generate a new key pairKyberCrypto::encapsulate(public_key): Encapsulate a shared secretKyberCrypto::decapsulate(ciphertext, secret_key): Decapsulate shared secretKyberCrypto::sizes(): Get component sizes
Key Sizes
| Component | Size (bytes) |
|---|---|
| XChaCha20Poly1305 Key | 32 |
| XChaCha20Poly1305 Nonce | 24 |
| Kyber1024 Public Key | 1,568 |
| Kyber1024 Secret Key | 3,168 |
| Kyber1024 Ciphertext | 1,568 |
| Kyber1024 Shared Secret | 32 |
Security Notes
- XChaCha20Poly1305 provides authenticated encryption with 256-bit security
- Kyber1024 is designed to be secure against both classical and quantum attacks
- All secret keys are automatically zeroized when dropped
- Never reuse nonces with the same key in XChaCha20Poly1305
- The library uses cryptographically secure random number generation
Testing
Run the test suite:
For verbose output:
Dependencies
chacha20poly1305: Pure Rust implementation of XChaCha20Poly1305pqcrypto-kyber: Post-quantum cryptography (Kyber1024)aead: Authenticated encryption trait definitionsrand_core: Random number generationthiserror: Error handlingzeroize: Secure memory cleanup
License
This project is licensed under the MIT License.