blob: 367376f62e21bf4541b6139b4233bc7b18b3e42a (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
#include <s.h>
#include <assert.h>
#include <stdbool.h>
#include <stdio.h>
#include <siphash.h>
#include "logerr.h"
#include "random.h"
#include "hash.h"
static bool
SEED_INITIALIZED = false;
static u8
HASH_KEY[SIPHASH_KEY_LENGTH];
int
hash_setup(void) {
int rc = -1;
if (random_bytes(SIPHASH_KEY_LENGTH, &HASH_KEY)) {
logerr("urandom_bytes()");
goto out;
}
SEED_INITIALIZED = true;
rc = 0;
out:
return rc;
}
void
hash(
const size_t inlen,
const void *const restrict in,
u8 out[HASH_OUTPUT_LENGTH]
) {
assert(SEED_INITIALIZED == true);
siphash(HASH_KEY, inlen, in, out);
}
|