2 个版本
0.1.1 | 2024 年 4 月 13 日 |
---|---|
0.1.0 | 2024 年 4 月 13 日 |
#954 在 加密
9KB
115 行
lazyxchacha-rs
基于 RustCrypto: ChaCha20Poly1305 的 Rust 实现 Lazy XChaCha20-Poly1305。
算法细节
- 密钥交换:X25519
- 加密:XChaCha20
- 认证:Poly1305
基准测试
Gnuplot not found, using plotters backend
encrypt time: [1.4821 µs 1.4897 µs 1.5010 µs]
change: [-33.403% -32.895% -32.441%] (p = 0.00 < 0.05)
Performance has improved.
Found 4 outliers among 100 measurements (4.00%)
1 (1.00%) high mild
3 (3.00%) high severe
Benchmarking decrypt: Warming up for 3.0000 s
decrypt time: [1.3529 µs 1.3560 µs 1.3594 µs]
change: [-27.218% -27.057% -26.897%] (p = 0.00 < 0.05)
Performance has improved.
Found 8 outliers among 100 measurements (8.00%)
8 (8.00%) high mild
如何使用
- 生成密钥对
let keypair = KeyPair::new();
- 密钥交换 & 共享密钥
let client_kp = KeyPair::new();
let server_kp = KeyPair::new();
let server_pk = server_kp.pk_string();
let shared_key = SharedKey::new(server_pk, client_kp.sk);
- 加密
let lazyxchacha = LazyXChaCha::new();
let shared_key = SharedKey::new(server_pk, client_kp.sk);
let plaintext = r#"{"message": "hi"}"#;
let ciphertext = lazyxchacha.encrypt(plaintext, shared_key);
- 解密
let lazyxchacha = LazyXChaCha::new();
let shared_key = SharedKey::new(server_pk, client_kp.sk);
let ciphertext = "58b99ca4a7";
let plaintext = lazyxchacha.decrypt(ciphertext, shared_key);
依赖项
~2.5–4MB
~80K SLoC