Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

SipHash in Java; zero-allocation and streaming implementations

License

NotificationsYou must be signed in to change notification settings

whitfin/siphash-java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build StatusCoverage Status

A Java implementation of the SipHash cryptographic hash family. Supports any variation, although defaults to the widely used SipHash-2-4. Can be used with either full input, or used as a streaming digest.

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

Setup

siphash is (soon to be) available on Maven central, via Sonatype OSS:

<dependency>    <groupId>com.zackehh</groupId>    <artifactId>siphash</artifactId>    <version>1.0.0</version></dependency>

Usage

There are two ways of using SipHash (see below). Both return aSipHashResult which can be used to retrieve the result in various forms. For further usage, please visit thedocumentation.

Full Input Hash

The first is to simple create aSipHash instance and use it to repeatedly hash using the same key.

The internal state is immutable, so you can hash many inputs without having to recreate a newSipHash instance (unless you want a new key).

SipHashhasher =newSipHash("0123456789ABCDEF".getBytes());SipHashResultresult =hasher.hash("my-input".getBytes());System.out.println(result.get());// 182795880124085484 <-- this can overflowSystem.out.println(result.getHex());//  "2896be26d3374ec"System.out.println(result.getHex(true));// "02896be26d3374ec"System.out.println(result.getHex(SipHashCase.UPPER));//  "2896BE26D3374EC"System.out.println(result.getHex(true,SipHashCase.UPPER));// "02896BE26D3374EC"

Streaming Hash

The second is to use the library as a streaming hash, meaning you can apply chunks of bytes to the hash as they become available.

Using this method you must create a new digest every time you want to hash a different input as the internal state is mutable.

SipHashDigestdigest =newSipHashDigest("0123456789ABCDEF".getBytes());digest.update("chu".getBytes());digest.update("nked".getBytes());digest.update(" string".getBytes());SipHashResultresult =digest.finish();System.out.println(result.get());// 3502906798476177428 <-- this can overflowSystem.out.println(result.getHex());//  "309cd32c8c793014"System.out.println(result.getHex(true));//  "309cd32c8c793014"System.out.println(result.getHex(SipHashCase.UPPER));//  "309CD32C8C793014"System.out.println(result.getHex(true,SipHashCase.UPPER));//  "309CD32C8C793014"

Contributing

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

Testing

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

Tests can be run as follows:

$ mvn clean verify

About

SipHash in Java; zero-allocation and streaming implementations

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp