Simple, Secure and Fast encryption for any CPU.
ChaCha20-BLAKE3 is a secure Authenticated Encryption with Associated Data (AEAD) algorithm that is:
- more secure than classic AEADs by providing full context commitment
- uses long nonces that can be safely generated randomly
- doesn't require any specific harware instruction but instead scales with the width of the SIMD instructions of your CPU (AVX2 / AVX-512 on amd64 and NEON / SVE on arm)
Which make it a great fit for everything from microcontrollers to huge servers.
It has been designed to be the only encryption algorithm you will ever need.
https://kerkour.com/chacha20-blake3
Indicative single-core performance of pure-Rust, non-optimized implementations from the official implementation and the Rust Crypto project.
| Message Size | ChaCha20-BLAKE3 | XChaCha20-Poly1305 | AES-256-GCM |
|---|---|---|---|
| 64 B | 103 MB/s | 116 MB/s | 540 MB/s |
| 1 KB | 523 MB/s | 767 MB/s | 1,287 MB/s |
| 64 KB | 2,153 MB/s | 1,636 MB/s | 1,475 MB/s |
| 1 MB | 3,297 MB/s | 1,654 MB/s | 1,476 MB/s |
| 10 MB | 3,353 MB/s | 1,664 MB/s | 1,477 MB/s |
Machine: AMD EPYC 9R45 (virtualized, AWS ma8.xlarge)
Warning
Cargo.toml
[dependencies]
chacha20-blake3 = { git = "https://github.com/skerkour/chacha20-blake3", branch = "main" }use chacha20_blake3::ChaCha20Blake3;
fn main() {
// DO NOT USE A ALL-ZERO KEY / NONCE, THIS CODE IS FOR DEMONSTRATION ONLY
let key = [0u8; 32];
let nonce = [0u8; 24];
// or with an u64 counter to encrypt up to 2^64 messages with a single key:
// let mut nonce = [0u8; 24];
// nonce[..8].copy_from_slice(&counter.to_le_bytes());
let message = b"Hello World!";
let cipher = ChaCha20Blake3::new(key);
let ciphertext: Vec<u8> = cipher.encrypt(&nonce, message, &[]);
let plaintext: Vec<u8> = cipher.decrypt(&nonce, &ciphertext, &[]).unwrap();
assert_eq!(plaintext, message);
}| Feature | Default? | Description |
|---|---|---|
std |
✓ | Enables use of the standard library such as runtime SIMD detection. Enabling std automatically enables alloc. |
alloc |
✓ | Enables the encrypt / decrypt APIs that allocate memory. |
zeroize |
✓ | Enables zeroize to erase sensitive secrets from memory. |
The old version, ChaCha12-BLAKE3 is available on the chacha12-blake3 branch but won't receive any further update.
MIT. See LICENSE.txt