Amarula.Protocol.AppState.LTHash (amarula v0.1.0)
View SourceLT Hash — the summation hash that keeps app-state integrity across mutations.
Ported from Baileys' pre-WASM pure-JS impl (src/Utils/lt-hash.ts before the
rust bridge). Adding/removing a mutation gives the same hash as if the whole
sequence had been applied in order, so patches can be verified incrementally.
The hash is 128 bytes = 64 little-endian unsigned 16-bit words. Each mutation
mac is expanded with HKDF(mac, 128, salt="", info="WhatsApp Patch Integrity")
into the same 64-word space and added/subtracted pointwise mod 2^16 (wraparound).
subtract_then_add/3 is the operation app-state uses: drop the macs of removed
records, add the macs of new ones.
Summary
Functions
Add each mac in macs to hash (pointwise, with wraparound).
Subtract each mac in macs from hash.
Subtract the subtract macs, then add the add macs.
A fresh, all-zero 128-byte hash.
Functions
Add each mac in macs to hash (pointwise, with wraparound).
Subtract each mac in macs from hash.
Subtract the subtract macs, then add the add macs.
@spec zero() :: binary()
A fresh, all-zero 128-byte hash.