๐ฏ Discohash
Discohash (also known as BEBB4185) is a super simple and super fast hash that passes all of SMHasher, and runs at 2-5GB/s (depending on hardware) in this naive, portable, serial implementation.
Link to the SUPERCOP ECRYPT benchmark for bebb4185
CLI app included
- A super-fast 64-bit hash.
- one of the fastest hashes ever benchmarked at ecrypt
- ECRYPT benchmark is 4x faster than BLAKE3
- Mix is super simple.
- Tested at ~ 5GB/s @ 3Gz, (Google Cloud Platform, N1 CPU)
- Passes all SMHasher tests.
- Also known as: BEBB4185
- Implemented in C++, and also a port to JS
- This repo includes a simple CLI app for hashing files or stdin from the command line.
The main 128-bit-to-128-bit mixing function is just this:
mix(const int A)
{
const int B = A+1;
ds[A] *= P;
ds[A] = rot(ds[A], 23);
ds[A] *= Q;
ds[B] ^= ds[A];
ds[B] *= P;
ds[B] = rot(ds[B], 23);
ds[B] *= Q;
}
which is just multiplications by two 64-bit primes, P and Q, bit rotation, and xor.
P, and Q are:
- P = 0xFFFFFFFFFFFFFFFF - 58
- Q = 13166748625691186689
The standard internal state is 256-bits and the mixing function windows across that.
The standard digest is 64-bits, but you can modify it to yield 128-bits or more if you want a cryptographically secure hash.
Use the C code from this repository, either in your project or as a CL-app (included):
cd src
./build.sh
./bin/bebbsum < 0xa2a647993898a3df.txt
> 0xa2a647993898a3df
./bin/bebbsum 0xa2a647993898a3df.txt
> 0xa2a647993898a3df
or, for a JS implementation:
npm i --save bebb4185
Use in Node.JS:
import {discohash} from 'bebb4185'
Or using Snowpack as a webmodule:
import {discohash} from './web_modules/bebb4185.js';
Then call it:
const hash = discohash(string_or_typed_array_key, optional_seed);
- The JS Implementation produces the same value hashes as the C++ implementation.
- The JS implementation is ~ 500x slower than the C++ implementation.
- This is probably because of the use of BigInts to stand in for
uint64_t
- It's possible to implement a 64-bit mult using 32-bit view which would remove the need for BigInt. I have no plan to do this.
The value is: BEBB4185
Make a parallel version using Merkle tree