highwayhash(3)

✨ highwayhash β€” the manual page, but make it cute ✨

okay so bestie, you're reading the highwayhash(3) page from the Library Functions Manual and honestly? it's giving "fast strong 64-bit hash functions" energy and I am obsessed. let's get into it πŸ’–


🌸 NAME 🌸

highwayhash β€” fast strong 64-bit hash functions. yes that's it, that's the whole name, slay.


πŸŽ€ SYNOPSIS πŸŽ€

first up, the C girlies:

#include <highwayhash/c_bindings.h> /* C */

    uint64_t SipHashC(const uint64_t* key, const char* bytes, const
uint64_t size);

    uint64_t SipHash13C(const uint64_t* key, const char* bytes, const
uint64_t size);

    uint64_t HighwayHash64(const HHKey key, const char* bytes, const
uint64_t size);

and now the C++ besties:

#include <highwayhash/highwayhash.h> /* C++ */

    using namespace highwayhash;

    void HighwayHashT(State* HH_RESTRICT state,
                      const char* HH_RESTRICT bytes, const size_t size,
                      Result* HH_RESTRICT hash);
#include <highwayhash/sip_hash.h> /* C++ */

    using namespace highwayhash;

    HH_U64 SipHash(const SipHashState::Key& key, const char* bytes,const
HH_U64 size);

and when you link, you link with -lhighwayhash 🫢 don't forget her, she's the whole reason it works.


πŸ’… DESCRIPTION πŸ’…

so hash functions are used everywhere, right? which means obviously we want them faster and safer. this package serves you two 'strong' hash functions β€” and by strong we mean well-distributed and unpredictable, not just "vibes are good":

  • a faster version of SipHash
  • and an even faster algorithm that they literally named HighwayHash πŸ›£οΈβœ¨

SipHash is a fast but 'cryptographically strong' pseudo-random function, and it was made by Aumasson and Bernstein β€” the paper lives at https://www.131002.net/siphash/siphash.pdf if you want the lore.

HighwayHash is a new way of mixing inputs which may inspire new cryptographically strong hashes πŸ‘‘ and the numbers?? iconic:

  • Large inputs are processed at a rate of 0.24 cycles per byte ⚑
  • latency stays low even for small inputs
  • HighwayHash is faster than SipHash for all input sizes
  • with 5 times higher throughput at 1 KiB

they discuss design choices and give you statistical analysis plus preliminary cryptanalysis over at https://arxiv.org/abs/1612.06257 β€” go read it, iykyk πŸ“–

⚠️ also important bestie: note that SipHash wants an uint64_t[2] key while HighwayHash wants uint64_t[4]. do not mix those up, that's a whole different vibe and not the good kind πŸ’€

🌈 EXAMPLES 🌈

64-bit SipHash for any CPU:

#include "highwayhash/sip_hash.h"
using namespace highwayhash;
const HH_U64 key2[2] HH_ALIGNAS(16) = {1234, 5678};
char in[8] = {1};
return SipHash(key2, in, 8);

64, 128 or 256 bit HighwayHash for the CPU determined by compiler flags:

#include "highwayhash/highwayhash.h"
using namespace highwayhash;
const HHKey key HH_ALIGNAS(32) = {1, 2, 3, 4};
char in[8] = {1};
HHResult64 result;  // or HHResult128 or HHResult256
HHStateT<HH_TARGET> state(key);
HighwayHashT(&state, in, 8, &result);

64, 128 or 256 bit HighwayHash for the CPU on which we're currently running:

#include "highwayhash/highwayhash_target.h"
#include "highwayhash/instruction_sets.h"
using namespace highwayhash;
const HHKey key HH_ALIGNAS(32) = {1, 2, 3, 4};
char in[8] = {1};
HHResult64 result;  // or HHResult128 or HHResult256
InstructionSets::Run<HighwayHash>(key, in, 8, &result);

C-callable 64-bit HighwayHash for the CPU on which we're currently running:

#include "highwayhash/c_bindings.h"
const uint64_t key[4] = {1, 2, 3, 4};
char in[8] = {1};
return HighwayHash64(key, in, 8);

like... four whole flavours of the same gorgeous algorithm?? we ate πŸ“


πŸ‘€ SEE ALSO πŸ‘€

  • /usr/include/highwayhash/c_bindings.h (C)
  • /usr/include/highwayhash/highwayhash.h (C++)

go read the headers, they're right there, they're free πŸ’œ


πŸ’€ BUGS πŸ’€

found something cursed? take it straight to the source, bestie:


πŸ‘‘ AUTHOR πŸ‘‘

the upstream authors are Jan Wassenberg <jan.wassenberg@gmail.com> and Jyrki Alakuijala <jyrki.alakuijala@gmail.com>, updated 2017-02-07 β€” legends, no cap.

this manpage was created by Adam Borowski <kilobyte@angband.pl>, and completed by Zhou Mo <cdluminate@gmail.com> according to upstream readme and header files. 🫢


and that's the whole page!! this highwayhash(3) manual was brought to you by Library Functions Manual energy, dated April 25, 2017 β€” go hash something beautiful, mwah πŸ’…βœ¨