Fast non-cryptographic 64-bit hash function for checksums, file dedup, hash tables.
uint64_t bitHash_oneshot(const void *data, size_t len, uint64_t seed);
void bitHash_init(BitHashState *state, uint64_t seed);
void bitHash_update(BitHashState *state, const void *data, size_t len);
uint64_t bitHash_finish(BitHashState *state);
int bitHash_file(const char *path, void *io_buf, size_t io_buf_len,
uint64_t seed, uint64_t *out_hash);
int bitHash_file_fp(void *fp, void *io_buf, size_t io_buf_len,
uint64_t seed, uint64_t *out_hash);
int bitHash_files_equal(const char *path_a, const char *path_b,
void *io_buf, size_t io_buf_len);Streaming (init / update / finish) and one-shot variants produce identical
digests for identical input. Seed defaults to BITHASH_SEED_DEFAULT (0).
gcc -O2 -c bithash.c
No dependencies. c99, header is c++-safe (extern "C").
hashtest.c generates test files in memory-free chunks, then times bithash
against openssl's md5 / sha1 / sha256 / sha512 / blake2b (EVP api) reading the
same files.
gcc -O2 -o hashtest hashtest.c bithash.c -lcrypto
./hashtest
- CPU: AMD Ryzen 7 7445HS (12 threads, up to 4.75 GHz)
- OS: CachyOS x86_64, kernel 7.1.6-1-cachyos
- compiler: gcc,
-O2
| size | md5 | sha1 | sha256 | sha512 | blake2b | bithash |
|---|---|---|---|---|---|---|
| 1MB | 394 MB/s | 1489 MB/s | 1996 MB/s | 1018 MB/s | 1154 MB/s | 7289 MB/s |
| 16MB | 863 MB/s | 1761 MB/s | 1798 MB/s | 954 MB/s | 947 MB/s | 3931 MB/s |
| 64MB | 869 MB/s | 1869 MB/s | 1768 MB/s | 935 MB/s | 1080 MB/s | 4247 MB/s |
| 256MB | 891 MB/s | 1897 MB/s | 1806 MB/s | 948 MB/s | 1077 MB/s | 4913 MB/s |
| 1GB | 907 MB/s | 1966 MB/s | 1862 MB/s | 973 MB/s | 1087 MB/s | 5595 MB/s |
BitHash is roughly 2.5-3x faster than sha256 on this x86_64 machine.
These numbers are throughput only, not a security comparison. bithash is not cryptographic: No collision resistance guarantees, not suitable for signatures, passwords, or anything adversarial. use it for checksums, dedup, hash table keys, cache keys.
Apache License 2.0. See LICENSE for more.