libchat/double-ratchets
kaichao 10940321ff
Encode ratchet sate for serialization (#20)
* feat: costom encode for double ratchet

* chore: correct capacity

* chore: refactor reference

* chore: reader for parse bytes

* chore: extract reader

* chore: example with persist state.

* chore: update example

* chore: implement serde compatibility.

* chore: as_bytes

* chore: zerorize the secrec material

* chore: use as_types to return reference for static key.

* chore: extract example from basic demo
2026-01-29 09:19:52 +08:00
..

Double Ratchet

This library provides an implementation of the Double Ratchet algorithm.

Usage

let shared_secret = [42u8; 32];
let bob_dh = DhKeyPair::generate();

let mut alice = RatchetState::init_sender(shared_secret, bob_dh.public);
let mut bob = RatchetState::init_receiver(shared_secret, bob_dh);

let (ciphertext, header) = alice.encrypt_message(b"Hello Bob!");
let plaintext = bob.decrypt_message(&ciphertext, header);

Run examples,

cargo run --example double_ratchet_basic

cargo run --example storage_demo --features storage
cargo run --example storage_demo --features sqlcipher

Run Nim FFI example,

# In the root folder (libchat)
cargo build --release
# In ffi-nim-example folder
nimble run