All Projects → whitfin → siphash-java

whitfin / siphash-java

Licence: MIT license
SipHash in Java; zero-allocation and streaming implementations

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to siphash-java

HashDepot
.NET library for xxHash, FNV, MurmurHash3 and SipHash algorithms
Stars: ✭ 107 (+328%)
Mutual labels:  hashing, siphash
hash-checker
Fast and simple application that allows you to generate and compare hashes from files and text
Stars: ✭ 72 (+188%)
Mutual labels:  hashing
CryptoKnight
CryptoKnight is a general purpose cryptography desktop app
Stars: ✭ 18 (-28%)
Mutual labels:  hashing
prvhash
PRVHASH - Pseudo-Random-Value Hash. Hash functions, PRNG with unlimited period, randomness extractor. (Codename Gradilac/Градилак)
Stars: ✭ 194 (+676%)
Mutual labels:  hashing
blockchain
No description or website provided.
Stars: ✭ 28 (+12%)
Mutual labels:  hashing
IJCAI2018 SSDH
Semantic Structure-based Unsupervised Deep Hashing IJCAI2018
Stars: ✭ 38 (+52%)
Mutual labels:  hashing
crc32c
Fast CRC-32-Castagnoli implementation in Rust
Stars: ✭ 26 (+4%)
Mutual labels:  hashing
djb2a
DJB2a non-cryptographic hash function
Stars: ✭ 31 (+24%)
Mutual labels:  hashing
password-hasher
The PasswordHasher component provides password hashing utilities.
Stars: ✭ 425 (+1600%)
Mutual labels:  hashing
node-blake2
All four BLAKE2 variants (blake2b, blake2bp, blake2s, blake2sp) with stream support for Node.js
Stars: ✭ 52 (+108%)
Mutual labels:  hashing
binance-signature-examples
Examples of generating HMAC and RSA signature for Binance API
Stars: ✭ 170 (+580%)
Mutual labels:  hashing
HashGAN
HashGAN: Deep Learning to Hash with Pair Conditional Wasserstein GAN
Stars: ✭ 63 (+152%)
Mutual labels:  hashing
noble-hashes
Audited & minimal JS implementation of SHA2, SHA3, RIPEMD, BLAKE2/3, HMAC, HKDF, PBKDF2 & Scrypt
Stars: ✭ 213 (+752%)
Mutual labels:  hashing
cisip-FIRe
Fast Image Retrieval (FIRe) is an open source project to promote image retrieval research. It implements most of the major binary hashing methods to date, together with different popular backbone networks and public datasets.
Stars: ✭ 40 (+60%)
Mutual labels:  hashing
BitFact
🛡️ Robust data integrity tool. Prove data, text, & files using the Ethereum blockchain.
Stars: ✭ 42 (+68%)
Mutual labels:  hashing
hashvis
Rust Program for Deterministic Generation of Random Art.
Stars: ✭ 43 (+72%)
Mutual labels:  hashing
zig-okredis
Zero-allocation Client for Redis 6+
Stars: ✭ 137 (+448%)
Mutual labels:  zero-allocation
sshash
A compressed, associative, exact, and weighted dictionary for k-mers.
Stars: ✭ 62 (+148%)
Mutual labels:  hashing
tenjin
📝 A template engine.
Stars: ✭ 15 (-40%)
Mutual labels:  zero-allocation
tlsh
TLSH lib in Golang
Stars: ✭ 110 (+340%)
Mutual labels:  hashing

SipHash

Build Status Coverage Status

A Java implementation of the SipHash cryptographic hash family. Supports any variation, although defaults to the widely used SipHash-2-4. This library offers both a zero-allocation implementation, along with a streaming digest.

This library was heavily influenced by veorq's C implementation and Forward C&C's reference implementation - I just decided it was time a Java implementation of SipHash made it onto Maven :).

Setup

siphash is available on Maven central, via Sonatype OSS:

<dependency>
    <groupId>io.whitfin</groupId>
    <artifactId>siphash</artifactId>
    <version>2.0</version>
</dependency>

Usage

There are three main ways to use this library, and the appropriate choice will depend on your use case. For further usage, please visit the documentation.

Zero Allocation

The fastest use of this algorithm is to simply call SipHasher.hash/2 which will call a zero-allocation implementation of the SipHash algorithm. This implementation should be used in most cases; specifically cases where you have frequently differing seed keys.

// specify the key and data pair
String key = "0123456789ABCDEF".getBytes();
String data = "my-input".getBytes();

// hash using default compression (2-4)
long hash1 = SipHasher.hash(key, data);

// you can also specify compression rounds
long hash2 = SipHasher.hash(key, data, 2, 4);

Contained Hashing

This is an optimized implementation for cases where you have a single key (such as a hash table). In these cases, the seed values can be precomputed and re-used, rather than calculating them repeatedly on each call to hash. Although the initial call to create a container uses an allocation, there are no other allocations inside the container.

// create a container from our key
String key = "0123456789ABCDEF".getBytes();
SipHasherContainer container = SipHasher.container(key);

// hash using default compression (2-4)
long hash1 = container.hash(data);

// you can also specify compression rounds
long hash2 = container.hash(data, 2, 4);

Streaming Digest

The final way to use the library is as a streaming digest; meaning that you can apply chunks of input as they become available. The advantage here is that you can hash input of unknown length. Naturally, this is slower than the alternatives and should only be used when necessary. A digest cannot be re-used; one must be created on a per-hash basis.

// create a container from our key
String key = "0123456789ABCDEF".getBytes();
SipHasherStream hash = SipHasher.init(key);

// update several times
hash.update("chu".getBytes());
hash.update("nked".getBytes());
hash.update(" string".getBytes());

// retrieve the final result
long result = hash.digest();

Formatting

By default, as of v2.0.0, all hashes are returned as a long. However, you can use SipHasher.toHexString/1 to convert a hash to a hexidecimal String value.

// output will be padded (if necessary) to 16 bytes
SipHasher.toHexString(-3891084581787974112L); // ca0017304f874620
SipHasher.toHexString(   77813817455948350L); // 011473413414323e

Contributing

If you wish to contribute (awesome!), please file an issue first! All PRs should pass mvn clean verify and maintain 100% test coverage.

Testing

Tests are run using mvn. I aim to maintain 100% coverage where possible (both line and branch).

Tests can be run as follows:

$ mvn clean verify
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].