10个版本
0.3.3 | 2021年10月24日 |
---|---|
0.3.1 | 2021年5月12日 |
0.3.0 | 2020年11月2日 |
0.2.4 | 2020年5月16日 |
0.1.0 | 2019年2月3日 |
#211 in 密码学
124,956 每月下载量
用于 156 个crate (6 直接)
145KB
4K SLoC
ChaCha系列流密码
特性
- 纯Rust实现
- 支持RustCrypto API
- 基于稳定版Rust构建
- 可移植
- 速度快:在我的机器上(Xeon X5650,使用ppv-lite86),性能比手动优化的ASM SIMD实现(floodberry/chacha-opt)快15%以内
- 兼容no-std(仅运行时算法选择需要std)
支持的变体
ChaCha20:用于TLS中的chacha20-poly1305,OpenSSH中的arc4random,BSDs中的arc4random,Linux /dev/urandom自4.8以来。
Ietf:IETF RFC 7539。更长的nonce,较短的块计数器。
XChaCha20:类似于XSalsa20构建;初始化过程中的混合步骤允许使用长nonce和完整的块计数器。
ChaCha12,ChaCha8:更快;安全性更低的保险系数。
lib.rs
:
具有SIMD优化的纯Rust ChaCha
流密码使用
#[cfg(features = "std")]
fn demo() {
extern crate c2_chacha;
use c2_chacha::stream_cipher::{NewStreamCipher, SyncStreamCipher, SyncStreamCipherSeek};
use c2_chacha::{ChaCha20, ChaCha12};
let key = b"very secret key-the most secret.";
let iv = b"my nonce";
let plaintext = b"The quick brown fox jumps over the lazy dog.";
let mut buffer = plaintext.to_vec();
// create cipher instance
let mut cipher = ChaCha20::new_var(key, iv).unwrap();
// apply keystream (encrypt)
cipher.apply_keystream(&mut buffer);
// and decrypt it back
cipher.seek(0);
cipher.apply_keystream(&mut buffer);
// stream ciphers can be used with streaming messages
let mut cipher = ChaCha12::new_var(key, iv).unwrap();
for chunk in buffer.chunks_mut(3) {
cipher.apply_keystream(chunk);
}
}