double-ratchet-2

Implementation of the double ratchet system/encryption as specified by Signal.

The implementation follows the cryptographic recommendations provided by Signal. The AEAD Algorithm uses a constant Nonce. This might be changed in the future.

Example Usage:

Standard:

```rust use doubleratchet2::ratchet::Ratchet;

let sk = [1; 32]; // Initial Key created by a symmetric key agreement protocol let (mut bobratchet, publickey) = Ratchet::initbob(sk); // Creating Bobs Ratchet (returns Bobs PublicKey) let mut aliceratchet = Ratchet::initalice(sk, publickey); // Creating Alice Ratchet with Bobs PublicKey let data = b"Hello World".to_vec(); // Data to be encrypted

let (header, encrypted) = aliceratchet.ratchetencrypt(&data); // Encrypting message with Alice Ratchet (Alice always needs to send the first message) let decrypted = bobratchet.ratchetdecrypt(&header, &encrypted); // Decrypt message with Bobs Ratchet assert_eq!(data, decrypted) ```

With lost message:

```rust

let sk = [1; 32]; // Initial Key created by a symmetric key agreement protocol let (mut bobratchet, publickey) = Ratchet::initbob(sk); // Creating Bobs Ratchet (returns Bobs PublicKey) let mut aliceratchet = Ratchet::initalice(sk, publickey); // Creating Alice Ratchet with Bobs PublicKey let data = b"Hello World".to_vec(); // Data to be encrypted

let (header1, encrypted1) = aliceratchet.ratchetencrypt(&data); // Lost message let (header2, encrypted2) = aliceratchet.ratchetencrypt(&data); // Successful message

let decrypted2 = bobratchet.ratchetdecrypt(&header2, &encrypted2); // Decrypting second message first let decrypted1 = bobratchet.ratchetdecrypt(&header1, &encrypted1); // Decrypting latter message

let comp = decrypted1 == data && decrypted2 == data; assert!(comp); ```

Encryption before recieving inital message

```rust use doubleratchet2::ratchet::Ratchet; let sk = [1; 32];

let (mut bobratchet, _) = Ratchet::initbob(sk); let data = b"Hello World".to_vec();

let (, _) = bobratchet.ratchet_encrypt(&data); ```

Encryption after recieving initial message

However bob can (of course) also encrypt messages. This is possible, after decrypting the first message from alice.

```rust use doubleratchet2::ratchet::Ratchet; let sk = [1; 32];

let (mut bobratchet, publickey) = Ratchet::initbob(sk); let mut aliceratchet = Ratchet::initalice(sk, publickey);

let data = b"Hello World".to_vec();

let (header1, encrypted1) = aliceratchet.ratchetencrypt(&data); let decrypted1 = bobratchet.ratchet_decrypt(&header1, &encrypted1);

let (header2, encrypted2) = bobratchet.ratchetencrypt(&data); let decrypted2 = aliceratchet.ratchetdecrypt(&header2, &encrypted2);

assert_eq!(data, decrypted2); ```

Constructing and Deconstructing Headers

rust let header_bytes: Vec<u8> = header.clone().into(); let header_const = Header::from(header_bytes); assert_eq!(header, header_const);

Features

Currently the crate only supports one feature: ring. If feature is enabled the crate switches to ring-compat and uses ring as backend for Sha512 Hashing. May result in slightly better performance.

TODO: - [x] Standard Double Ratchet - [ ] [Double Ratchet with encrypted headers][3]