shared: expose siphash24() related functionality in nm-hash-utils.h

CSiphash is a first class citizen, it's fine to use everwhere where we
need it.

NMHash wraps CSiphash and provides three things:

1) Convenience macros that make hashing nicer to use.

2) it uses a randomly generated, per-run hash seed, that can be combined
   with a guint static seed.

3) it's a general API for hashing data. It nowhere promises that it
   actually uses siphash24, although currently it does everywhere.
   NMHash is not (officially) siphash24.

Add API nm_hash_siphash42_init() and nm_hash_siphash42() to "nm-hash-utils.h",
that exposes (2) for use with regular CSiphash. You of course no longer
get the convenice macros (1) but you get plain siphash24 (which
NMHash does not give (3)).

While at it, also add a nm_hash_complete_u64(). Usually, for hasing we
want guint types. But we don't need to hide the fact, that the
underlying value is first uint64. Expose it.
This commit is contained in:
Thomas Haller
2018-12-12 12:11:53 +01:00
parent 3e0177f7d5
commit db791db4e1
2 changed files with 59 additions and 9 deletions

View File

@@ -122,17 +122,17 @@ nm_hash_static (guint static_seed)
}
void
nm_hash_init (NMHashState *state, guint static_seed)
nm_hash_siphash42_init (CSipHash *h, guint static_seed)
{
const guint8 *g;
guint seed[HASH_KEY_SIZE_GUINT];
nm_assert (state);
nm_assert (h);
g = _get_hash_key ();
memcpy (seed, g, HASH_KEY_SIZE);
seed[0] ^= static_seed;
c_siphash_init (&state->_state, (const guint8 *) seed);
c_siphash_init (h, (const guint8 *) seed);
}
guint