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:
use Ratchet;
let sk = ; // Initial Key created by a symmetric key agreement protocol
let = init_bob; // Creating Bobs Ratchet (returns Bobs PublicKey)
let mut alice_ratchet = init_alice; // Creating Alice Ratchet with Bobs PublicKey
let data = b"Hello World".to_vec; // Data to be encrypted
let = alice_ratchet.ratchet_encrypt; // Encrypting message with Alice Ratchet (Alice always needs to send the first message)
let decrypted = bob_ratchet.ratchet_decrypt; // Decrypt message with Bobs Ratchet
assert_eq!
With lost message:
let sk = ; // Initial Key created by a symmetric key agreement protocol
let = init_bob; // Creating Bobs Ratchet (returns Bobs PublicKey)
let mut alice_ratchet = init_alice; // Creating Alice Ratchet with Bobs PublicKey
let data = b"Hello World".to_vec; // Data to be encrypted
let = alice_ratchet.ratchet_encrypt; // Lost message
let = alice_ratchet.ratchet_encrypt; // Successful message
let decrypted2 = bob_ratchet.ratchet_decrypt; // Decrypting second message first
let decrypted1 = bob_ratchet.ratchet_decrypt; // Decrypting latter message
let comp = decrypted1 == data && decrypted2 == data;
assert!;
Encryption before recieving inital message
use Ratchet;
let sk = ;
let = init_bob;
let data = b"Hello World".to_vec;
let = bob_ratchet.ratchet_encrypt;
Encryption after recieving initial message
However bob can (of course) also encrypt messages. This is possible, after decrypting the first message from alice.
use Ratchet;
let sk = ;
let = init_bob;
let mut alice_ratchet = init_alice;
let data = b"Hello World".to_vec;
let = alice_ratchet.ratchet_encrypt;
let _decrypted1 = bob_ratchet.ratchet_decrypt;
let = bob_ratchet.ratchet_encrypt;
let decrypted2 = alice_ratchet.ratchet_decrypt;
assert_eq!;
Constructing and Deconstructing Headers
let header_bytes: = header.clone.into;
let header_const = from;
assert_eq!;
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:
- Standard Double Ratchet
- Double Ratchet with encrypted headers