kychacha_crypto-3.0.0 has been yanked.
Kychacha-crypto: Post-Quantum Secure Encryption Protocol
A post-quantum simple to use implementation for Kyber and ChaCha20
Hybrid cryptographic implementation using:
- Crystals-Kyber: Post-Quantum secure Key Encapsulation Mechanism (KEM) for key exchange.
- ChaCha20-Poly1305: Authenticated symmetric encryption.
Architecture
The following diagram describes the protocol flow between the "Sender" and the "Recipient":
sequenceDiagram
participant Sender
participant Recipient
Recipient-->>Sender: Recipient public key (Kyber pub key 1184 bytes)
Sender->>Sender: Encapsulate secret (Kyber)
Note right of Sender: Generates ephemeral keypair and derives shared secret
Sender->>Sender: Derive ChaCha key (HKDF-SHA256)
Note right of Sender: Uses shared secret to derive symmetric key
Sender->>Sender: Encrypt message (ChaCha20-Poly1305)
Sender->>Recipient: Send {ciphertext, nonce, encrypted message}
Recipient->>Recipient: Decapsulate secret (Kyber)
Note right of Recipient: Recovers shared secret
Recipient->>Recipient: Derive ChaCha key (HKDF-SHA256)
Note right of Recipient: Derives the same symmetric key
Recipient->>Recipient: Decrypt message
Note: During the encapsulation process on the sender's side, an ephemeral keypair is generated.
Technical Specifications
1. Key Exchange Protocol
- Algorithm: Kyber-1024 (NIST PQC Round 3)
- Key Parameters:
pub const KYBER_PUBLIC_KEY_BYTES: usize = 1184; pub const KYBER_SECRET_KEY_BYTES: usize = 2400; pub const KYBER_CIPHERTEXT_BYTES: usize = 1568; - Key Derivation: HKDF-SHA256 with specific context
2. Symetric Encryption
- Algorithm: ChaCha20-Poly1305 (IETF variant)
- Key Size: 256 bits
- Nonce: 96 bits (randomly generated per message)
3. Encrypted Data Format
The encrypted data is a serialized binary structure containing:
- Ciphertext: Kyber ciphertext (1568 bytes).
- Nonce: ChaCha20 nonce (12 bytes).
- Encrypted Message: Encrypted message with authentication tag.
Basic Usage
Key Generation and encryption
use ;
// Generate a Kyber-1024 keypair
let server_kp: Keypair = generate_keypair?;
let message = b"Secret message";
// Encrypt the message using the server's public key
let encrypted_data: = encrypt?;
// Receive encrypted_data as &[u8] from the client
let decrypted_message = decrypt?;
assert_eq!;
Note: The decrypt function assumes the original message is a valid UTF-8 string and returns a String. If the message contains non-UTF-8 binary data, decryption will fail.
Key Serialization (for storage/transmission)
use ;
// Convert keys to byte vectors
let pk_bytes: = public_key_to_bytes;
let sk_bytes: = secret_key_to_bytes;
// Reconstruct keys from bytes
let public_key = from;
let secret_key = from;
Safety Considerations
- Randomness: Depends on the secure generator of the system.
- HKDF context: Used for protocol binding.
- Nonces: Generated with CSPRNG for each message.