~blainsmith/libseahash

A C port of the SeaHash algorithm.
bd9d8f87 — Blain Smith 1 year, 23 days ago
remove WIP from readme
0a677d75 — Blain Smith 1 year, 23 days ago
update the example and readme
704066f4 — Blain Smith 1 year, 23 days ago
fixing failing tests to get correct hashes

refs

master
browse  log 

clone

read-only
https://git.sr.ht/~blainsmith/libseahash
read/write
git@git.sr.ht:~blainsmith/libseahash

You can also use your local clone with git send-email.

libseahash

libseahash is a C library that implements SeaHash, a non-cryptographic hash function created by http://ticki.github.io. This is a port of the Go library here.

Use

I used the same conventions as the other C hashing libraries such as SHA1 and MD5 so the functions should be familiar.

Example

#include <stdint.h>
#include <stdio.h>
#include <string.h>

#include "src/seahash.h"

int main(int argc, char **argv) {
    // This is the verbose method of
    // computing a hash by initializing
    // a context first and then updating
    // and finalizing it for the results.
    unsigned char digest[SEAHASH_DIGEST_LENGTH+1];
    const char *string = "to be or not to be";

    struct seahash_ctx context;
    seahash_init(&context);
    seahash_update(&context, (const unsigned char *)string, strlen(string));
    seahash_final(digest, &context);

    for (uint8_t i = 0; i < SEAHASH_DIGEST_LENGTH; i++) {
        printf("0x%02x, ", digest[i]);
    }
    // Prints "0x79, 0xb2, 0x6b, 0x5a, 0x61, 0x6e, 0x2d, 0x4a"

    // This is a convenience function
    // for perorming the same hashing
    // above, but with a lot less steps.
    unsigned char hash[SEAHASH_DIGEST_LENGTH+1];
    const char *str = "to be or not to be";
    seahash(hash, (const unsigned char *)str, strlen(str));

    for (uint8_t i = 0; i < SEAHASH_DIGEST_LENGTH; i++) {
        printf("0x%02x, ", hash[i]);
    }
    // Prints "0x79, 0xb2, 0x6b, 0x5a, 0x61, 0x6e, 0x2d, 0x4a"
}

Source is available in example.c.