2个不稳定版本
0.3.0 | 2023年5月17日 |
---|---|
0.2.7 | 2023年3月2日 |
0.2.4 |
|
0.2.2 |
|
0.1.0 |
|
1959 在 密码学 中
51 每月下载次数
25KB
589 代码行
RATCHET-X2
纯Rust双摇杆协议实现
示例
use cryptimitives::{aead, hmac, kdf, key::x25519_ristretto};
use cryptraits::{key::KeyPair, key_exchange::DiffieHellman};
use rand_core::OsRng;
use ratchet_x2::DoubleRatchet;
type DR = DoubleRatchet<
x25519_ristretto::KeyPair,
kdf::sha256::Kdf,
aead::aes_gcm::Aes256Gcm,
hmac::sha256::Hmac,
>;
fn main() {
let alice_pair = x25519_ristretto::KeyPair::default();
let bob_pair = x25519_ristretto::KeyPair::default();
let ssk = alice_pair.diffie_hellman(bob_pair.public());
let mut alice = DR::init_alice(&ssk, bob_pair.to_public(), None, &mut OsRng);
let mut bob = DR::init_bob(&ssk, bob_pair, None);
let (pt_a, ad_a) = (b"Hey, Bob", b"A2B");
let (header_a, ciphertext_a) = alice.encrypt(pt_a, ad_a, &mut OsRng);
let decrypted_msg = bob.decrypt(&header_a, &ciphertext_a, ad_a, &mut OsRng);
println!("{}", String::from_utf8(decrypted_msg).unwrap());
}
依赖项
~7MB
~159K SLoC