Linked Truncated Hash for app state integrity verification.
LTHash is a summation-based hash that maintains data integrity across a series of mutations. Values can be added or removed and the resulting hash equals what you'd get from applying the same mutations sequentially.
The 128-byte hash state is treated as 64 unsigned 16-bit little-endian integers. Each value MAC is expanded to 128 bytes via SHA-256 with 4 counter prefixes, then added to or subtracted from the state with wrapping arithmetic.
Ports LTHashAntiTampering from Baileys' whatsapp-rust-bridge (lt-hash.ts).
Summary
Functions
Create a fresh 128-byte zero hash state.
Apply subtract-then-add operations to the hash state.
Functions
@spec new() :: <<_::1024>>
Create a fresh 128-byte zero hash state.
Ports newLTHashState().hash — the initial hash is all zeros.
Apply subtract-then-add operations to the hash state.
First subtracts all sub_buffs from the hash, then adds all add_buffs.
Each buffer is a 32-byte value MAC that gets expanded to 128 bytes before
the arithmetic operation.
Ports LT_HASH_ANTI_TAMPERING.subtractThenAdd(hash, subBuffs, addBuffs).
Parameters
hash— 128-byte current hash statesub_buffs— list of 32-byte value MACs to subtractadd_buffs— list of 32-byte value MACs to add
Returns
Updated 128-byte hash state.