]> git.ipfire.org Git - thirdparty/systemd.git/blame_incremental - src/basic/siphash24.h
test-xattr-util.c: migrate to new assertion macros (#38025)
[thirdparty/systemd.git] / src / basic / siphash24.h
... / ...
CommitLineData
1/* SPDX-License-Identifier: CC0-1.0 */
2
3#pragma once
4
5#include "forward.h"
6
7struct siphash {
8 uint64_t v0;
9 uint64_t v1;
10 uint64_t v2;
11 uint64_t v3;
12 uint64_t padding;
13 size_t inlen;
14};
15
16void siphash24_init(struct siphash *state, const uint8_t k[static 16]);
17void siphash24_compress(const void *in, size_t inlen, struct siphash *state);
18#define siphash24_compress_byte(byte, state) siphash24_compress((const uint8_t[]) { (byte) }, 1, (state))
19#define siphash24_compress_typesafe(in, state) \
20 siphash24_compress(&(in), sizeof(typeof(in)), (state))
21
22static inline void siphash24_compress_boolean(bool in, struct siphash *state) {
23 siphash24_compress_byte(in, state);
24}
25
26static inline void siphash24_compress_usec_t(usec_t in, struct siphash *state) {
27 uint64_t u = htole64(in);
28 siphash24_compress_typesafe(u, state);
29}
30
31static inline void siphash24_compress_safe(const void *in, size_t inlen, struct siphash *state) {
32 if (inlen == 0)
33 return;
34
35 siphash24_compress(in, inlen, state);
36}
37
38void siphash24_compress_string(const char *in, struct siphash *state);
39
40uint64_t siphash24_finalize(struct siphash *state);
41
42uint64_t siphash24(const void *in, size_t inlen, const uint8_t k[static 16]);
43
44uint64_t siphash24_string(const char *s, const uint8_t k[static 16]);