A lightweight homomorphic, commutative hash implementation
Project description
Homomorphic Commutative Hash (LtHash)
A lightweight homomorphic, commutative hash implementation in Python. Designed for set reconciliation and difference detection in distributed systems.
Background
In a distributed system, database replication involves copying information to keep it synchronized across multiple locations to improve availability and read latency. This problem of securing update broadcasts in such systems was formally analyzed by Maitin-Shepard et al. in "Securing Update Propagation with Homomorphic Hashing" [ePrint 2019/227], which proposed the use of homomorphic hash functions for efficient verification. Database modifications must be propagated to each location to maintain the consistency of the replicated objects with the master database. For a model in which database writes are published by a central distributor that manages the master database, the distributor is responsible for propagating updates to a set of subscribers in a reliable and efficient manner. The simplest way to achieve this is for the distributor to be in charge of directly sending the updates to each subscribed client. In this repo I have attempted to implement the LtHash as specified by researchers at Facebook.
Features
- Homomorphic: hash(a) + hash(b) = hash(a + b)
- Commutative: hash(a + b) = hash(b + a)
- Invertible: Elements can be added and removed
- Fixed size state (2048 bytes)
- Based on BLAKE2b and 16-bit arithmetic
Usage
from lthash import new16
# Basic usage
h = new16()
h.add(b"Hello")
h.add(b"World")
state = h.get_sum(b"")
# Remove elements
h.remove(b"World")
# Save/restore state
saved_state = h.get_sum(b"")
h2 = new16()
h2.set_state(saved_state)
Use Cases
- Set reconciliation
- Difference detection
- Content-based deduplication
- Distributed caching
Testing
python -m unittest tests/lthash_test.py
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lthash-0.1.0.tar.gz.
File metadata
- Download URL: lthash-0.1.0.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
db898842510717addbc933e884205083f62fe07ec2438d43ac1ab52ad96673c5
|
|
| MD5 |
d281f5e18059f60b637f58290af828be
|
|
| BLAKE2b-256 |
bc77f98738f4907883516cbc839d40785f93ce4488d8fc159ba98c5c608e85f2
|
File details
Details for the file lthash-0.1.0-py3-none-any.whl.
File metadata
- Download URL: lthash-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6ac8c393e220f746078f93f133b5459f09918549af235f47c5fa54535a4a0923
|
|
| MD5 |
b8e5a448aa1e5f3a78f03c4f8a6f36e5
|
|
| BLAKE2b-256 |
04637eb6c8a9ebaac53d39fffda58570a4d66594211d07636dccd03e7baf79f8
|