A double-ratchet implementation following Signal.
Compared to others
My code is much more object-oriented.
- There's no global party state, instead, it is each ratchet having its own state.
- It's really double-ratchet (2 kinds of ratchets), DhRootRatchet and MessageRatchet.
- HeaderKey support.
- Do nothing about message/header encryption/decryption, instead, provide correct message/header keys only.
Example
use SharedKeys;
let shared_keys = SharedKeys ;
let mut alice = shared_keys.alice;
let mut bob = shared_keys.bob;
// Alice sends first
alice.step_dh_root;
bob.step_dh_root;
assert_eq!; // debug_assertions only, Alice and Bob have the "same" state
assert_eq!; // returning the same message key
assert_eq!;
// Bob sends
bob.step_dh_root;
alice.step_dh_root;
assert_eq!;
assert_eq!;
assert_eq!;
// Alice sends
alice.step_dh_root;
bob.step_dh_root;
assert_eq!;
assert_eq!;
assert_eq!;