| Crates.io | fast_chacha |
| lib.rs | fast_chacha |
| version | 0.3.0 |
| created_at | 2025-05-28 02:34:13.193974+00 |
| updated_at | 2025-06-04 13:59:09.76541+00 |
| description | CPU-optimized ChaCha20 implementation with rust fallbacks |
| homepage | https://github.com/sh0rch/fast_chacha |
| repository | https://github.com/sh0rch/fast_chacha |
| max_upload_size | |
| id | 1692251 |
| size | 622,970 |
High-performance ChaCha20 stream cipher implementation with optional assembly acceleration (leveraging OpenSSL's assembler modules) and pure Rust fallback.
no_std Support: Works in embedded and bare-metal environments (disable default std).Add fast_chacha to your Cargo.toml:
[dependencies]
fast_chacha = "0.1.0"
By default, the std feature is enabled. To use in no_std environments:
[dependencies]
fast_chacha = { version = "0.1.0", default-features = false }
Basic example:
use fast_chacha::FastChaCha20;
let key = [0u8; 32];
let nonce = [0u8; 12];
let mut data = b"Secret message!".to_vec();
// Encrypt or decrypt in-place
let mut cipher = FastChaCha20::new(&key, &nonce);
cipher.apply_keystream(&mut data);
If you need to force the pure Rust fallback implementation:
let mut data = b"Secret message!".to_vec();
let mut cipher = FastChaCha20::new(&key, &nonce);
cipher.apply_keystream_pure(&mut data);
Full documentation is available on docs.rs:
The build script (build.rs) will compile and link optimized assembly implementations when available. This crate integrates assembly modules directly from OpenSSL, ensuring battle-tested, platform-specific routines. If no assembly is detected for your architecture, the crate falls back to the pure Rust version and emits a warning:
cargo:warning=fast_chacha: no ASM for <target>
Conditional compilation flag fast_chacha_asm is enabled when assembly (from OpenSSL) is used.
Here is a sample result of the comparison test for encrypting a 1 MiB block:
chacha20 (RustCrypto) : 111.8584ms
fast_chacha ("ASM") : 547.7µs
fast_chacha (Fallback) : 14.6214ms
chacha6 (Fallback) : 9.4224ms
Actual results of tests you can see on Github Actions page.
Note: Actual performance may vary depending on your CPU and platform.
Licensed under the Apache License, Version 2.0 © 2025 sh0rch sh0rch@iwl.dev
Contributions, issues, and feature requests are welcome! Please open an issue or pull request on GitHub:
https://github.com/sh0rch/fast_chacha
Based on the original ChaCha20 specification (RFC 8439) and assembly modules from OpenSSL.