#crypto #double-ratchet

no-std ratchet-x2

Pure Rust Double Ratchet protocol implementation

2 unstable releases

0.3.0 May 17, 2023
0.2.7 Mar 2, 2023
0.2.4 Feb 28, 2023
0.2.2 Apr 21, 2022
0.1.0 Jan 25, 2022

#1856 in Cryptography

Download history 19/week @ 2023-10-31 18/week @ 2023-11-14 15/week @ 2023-11-21 58/week @ 2023-11-28 14/week @ 2023-12-05 14/week @ 2023-12-12 30/week @ 2023-12-26 16/week @ 2024-01-16 28/week @ 2024-01-30 1/week @ 2024-02-06 74/week @ 2024-02-13

107 downloads per month

MIT license

25KB
589 lines

TestStatus Crate API

RATCHET-X2

Pure Rust Double Ratchet protocol implementation

Example

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());
}

Dependencies

~6.5MB
~143K SLoC