All Projects → lemire → Clhash

lemire / Clhash

Licence: apache-2.0
C library implementing the ridiculously fast CLHash hashing function

Programming Languages

c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to Clhash

komihash
Very fast, high-quality hash function (non-cryptographic, C) + PRNG
Stars: ✭ 68 (-69.09%)
Mutual labels:  hashing, hash
Util
A collection of useful utility functions
Stars: ✭ 201 (-8.64%)
Mutual labels:  hash, hashing
agent-python
Official python agent for using the distributed hashcracker Hashtopolis
Stars: ✭ 39 (-82.27%)
Mutual labels:  hashing, hash
bromberg sl2
Cayley hashing as in "Navigating in the Cayley Graph of SL₂(𝔽ₚ)"
Stars: ✭ 32 (-85.45%)
Mutual labels:  hashing, hash
Minperf
A Minimal Perfect Hash Function Library
Stars: ✭ 107 (-51.36%)
Mutual labels:  hash, hashing
laravel-hashid
HashId Implementation on Laravel Eloquent ORM
Stars: ✭ 23 (-89.55%)
Mutual labels:  hashing, hash
Name That Hash
🔗 Don't know what type of hash it is? Name That Hash will name that hash type! 🤖 Identify MD5, SHA256 and 3000+ other hashes ☄ Comes with a neat web app 🔥
Stars: ✭ 540 (+145.45%)
Mutual labels:  hash, hashing
hash-checker
Fast and simple application that allows you to generate and compare hashes from files and text
Stars: ✭ 72 (-67.27%)
Mutual labels:  hashing, hash
Xxhash cpp
Port of the xxhash library to C++17.
Stars: ✭ 106 (-51.82%)
Mutual labels:  hash, hashing
Eternal
A C++14 compile-time/constexpr map and hash map with minimal binary footprint
Stars: ✭ 93 (-57.73%)
Mutual labels:  hash, hashing
agent
hashtopolis.org
Stars: ✭ 19 (-91.36%)
Mutual labels:  hashing, hash
Password4j
Password4j is a user-friendly cryptographic library that supports Argon2, Bcrypt, Scrypt, PBKDF2 and various cryptographic hash functions.
Stars: ✭ 124 (-43.64%)
Mutual labels:  hash, hashing
metrohash-rs
Rust MetroHash
Stars: ✭ 45 (-79.55%)
Mutual labels:  hashing, hash
pthash
Fast and compact minimal perfect hash functions in C++.
Stars: ✭ 62 (-71.82%)
Mutual labels:  hashing, hash
haiti
🔑 Hash type identifier (CLI & lib)
Stars: ✭ 287 (+30.45%)
Mutual labels:  hashing, hash
Ahash
aHash is a non-cryptographic hashing algorithm that uses the AES hardware instruction
Stars: ✭ 251 (+14.09%)
Mutual labels:  hash, hashing
prvhash
PRVHASH - Pseudo-Random-Value Hash. Hash functions, PRNG with unlimited period, randomness extractor. (Codename Gradilac/Градилак)
Stars: ✭ 194 (-11.82%)
Mutual labels:  hashing, hash
noble-hashes
Audited & minimal JS implementation of SHA2, SHA3, RIPEMD, BLAKE2/3, HMAC, HKDF, PBKDF2 & Scrypt
Stars: ✭ 213 (-3.18%)
Mutual labels:  hashing, hash
Wyhash Rs
wyhash fast portable non-cryptographic hashing algorithm and random number generator in Rust
Stars: ✭ 44 (-80%)
Mutual labels:  hash, hashing
Data Structures
Data-Structures using C++.
Stars: ✭ 121 (-45%)
Mutual labels:  hash, hashing

clhash

Build Status Code Quality: Cpp

C library implementing the ridiculously fast CLHash hashing function (with C++ wrappers)

CLHash is a very fast hashing function that uses the carry-less multiplication and SSE instructions. Best used on recent x64 processors (Haswell or better).

CLHash has the following characteristics :

  • On a recent Intel processor (e.g., Skylake), it can hash input strings at a speed of 0.1 cycles per byte for sufficiently long strings. You read this right: it is simply ridiculously fast.
  • It has strong theoretical guarantees: XOR universality of short strings and excellent almost universality for longer strings.

For details, please see the research article:

Daniel Lemire, Owen Kaser, Faster 64-bit universal hashing using carry-less multiplications, Journal of Cryptographic Engineering 6 (3), 2016. http://arxiv.org/abs/1503.03465

Requirements

Please do not try to compile and run this software on legacy hardware (x64 processors before Haswell), it will either fail to work or be slow. It should be able to port the code to other architectures such as ARM or POWER processors but performance is unknown at this point. And, yes, this means that CLHash is not portable hardware-wise.

If your compiler is not C99 compliant... please get better one.

If your applications requires hashing tiny strings, then you will not get a speed close to 0.1 cycles per byte. The string should be significantly several times larger than a vector register (128 bits). So clhash is not meant to be a general-purpose hash function.

Usage

make
./unit

Compile option: if you define BITMIX during compilation, extra work is done to pass smhasher's avalanche test succesfully. Disabled by default.

Code sample

#include <assert.h>

#include "clhash.h"

int main() {
    void * random =  get_random_key_for_clhash(UINT64_C(0x23a23cf5033c3c81),UINT64_C(0xb3816f6a2c68e530));
    uint64_t hashvalue1 = clhash(random,"my dog",6);
    uint64_t hashvalue2 = clhash(random,"my cat",6);
    uint64_t hashvalue3 = clhash(random,"my dog",6);
    assert(hashvalue1 == hashvalue3);
    assert(hashvalue1 != hashvalue2);// very likely to be true
    free(random);
    return 0;
}

Simple benchmark

make
./benchmark

C++

If you prefer the convenience of a C++ interface with support for stl::vector and std::string, you can create a clhasher object instead.

#include <assert.h>
#include <cstdio>
#include <vector>

#include "clhash.h"


int main(void) {
    clhasher h(UINT64_C(0x23a23cf5033c3c81),UINT64_C(0xb3816f6a2c68e530));
    std::vector<int> vec{1,3,4,5,2,24343};
    uint64_t vechash = h(vec);

    uint64_t arrayhash = h(vec.data(), vec.size());

    assert(vechash == arrayhash);

    uint64_t cstringhash = h("o hai wurld");
    uint64_t stringhash = h(std::string("o hai wurld"));
    assert(cstringhash == stringhash);
}
make
./cppunit

Credit for C++ wrapper: Daniel Baker

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].