whitfin / siphash-c

A C (89) implementation of the SipHash cryptographic hash family, using a single pass algorithm
MIT License
3 stars 4 forks source link

SipHash

Build Status

A C89 implementation of the SipHash cryptographic hash family. Supports any variation, although defaults to the widely used SipHash-2-4.

This library was heavily influenced by veorq's C implementation, but modified to be made a little more user-friendly (IMO).

Usage

You can use this library as either an extension of your own project, or via the command line using a wrapper.

Library Setup

This project provides clib friendly configurations, so it should be easy to pull into your project.

If you're intending to use this project from another project, simply grab it from clib:

$ clib install zackehh/siphash-c

This will place it into ./deps, and from there you can just include it. You can always just include it manually, too.

From there it's pretty simple to use; you just provide a 16-byte key, some input data, and the rounds of compression to use (if you dunno what to do for these, use 2 and 4).

char key[16] = "0123456789ABCDEF";
char data[]  = "hello";
int c = 2, d = 4;

uint64_t output = siphash(key, data, c, d);

If you provide a key larger than 16 bytes, we'll simply use the first 16. This is slightly riskier but it saves time measuring the key and error handling.

Command Line Setup

At the moment, clib doesn't support both executables and source files in the same project so you have to build manually if you want to create the command line interface:

$ cd /tmp
$ git clone https://github.com/zackehh/siphash-c.git
$ cd siphash-c
$ make install

From there you can access siphash through your terminal, as follows:

$ siphash -k "0123456789ABCDEF" -i "hello" -c 2 -d 4

The applicable options exist of:

Note:

Testing

The tests are very barebones at the moment, but you can run them as follows:

$ make siphash_test
$ ./build/test/siphash_test