TCrypt
tcrypt is a secure cryptographic library for Rust that provides tools for encryption, key exchange, and secure channel communication. It implements modern cryptographic primitives using the X25519 key exchange protocol and AES-GCM for symmetric encryption, with optional support for post-quantum cryptography.
Features
-
Classical Cryptography
- Diffie-Hellman key exchange using X25519
- AES-256-GCM symmetric encryption with authenticated encryption
- Secure channel implementation for encrypted communications
- Client/Server key exchange protocols with simple APIs
-
Password-Based Encryption
- Secure password-based encryption using Argon2id for key derivation
- Salt management and secure format handling
- Simple API with convenient macros
-
Quantum-Resistant Cryptography (optional)
- CRYSTALS-Kyber key encapsulation mechanism (KEM)
- Hybrid classical/quantum key exchange
- Quantum-resistant secure channels
Usage Examples
Basic Key Exchange and Encryption
use ;
use SecureChannel;
// Initialize client and server
let mut client = new;
let mut server = new;
// Perform key exchange
let client_public = client.initiate_exchange;
let = server.respond_to_exchange.unwrap;
let client_secret = client.complete_exchange.unwrap;
// Create secure channels
let client_channel = new.unwrap;
let server_channel = new.unwrap;
// Use channels for secure communication
let message = b"Secret message";
let encrypted = client_channel.encrypt.unwrap;
let decrypted = server_channel.decrypt.unwrap;
assert_eq!;
Password-Based Encryption
use ;
// Encrypt data with password
let password = "my-secure-password";
let data = "sensitive information";
let encrypted = pcrypt!.unwrap;
// Decrypt data using the same password
let decrypted = pdecrypt!.unwrap;
assert_eq!;
Quantum-Resistant Key Exchange
// This requires the "quantum" feature to be enabled
use ;
// Initialize quantum-resistant key exchange
let mut client = new;
let mut server = new;
// Exchange keys using CRYSTALS-Kyber
let server_public = server.public_key;
let = client.complete_exchange.unwrap;
let server_secret = server.respond_to_exchange.unwrap;
assert_eq!;
Feature Flags
quantum: Enables quantum-resistant cryptography features using CRYSTALS-Kyber- By default, only classical cryptography features are enabled
Security Considerations
- All cryptographic operations use constant-time implementations where possible
- Proper entropy is ensured for key generation using OS-provided RNG
- Side-channel protections are in place for sensitive operations
- Memory containing sensitive data is securely zeroed when dropped
Installation
Add this to your Cargo.toml:
[]
= "0.1.2"
# Or, to enable quantum-resistant features:
= { = "0.1.2", = ["quantum"] }
License
This project is licensed under the MIT License.