]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/basic/siphash24.h
headers: add spdx tags to imported files with a known license
[thirdparty/systemd.git] / src / basic / siphash24.h
CommitLineData
448e7440
ZJS
1/* SPDX-License-Identifier: CC0-1.0 */
2
9bf3b535
LP
3#pragma once
4
5#include <inttypes.h>
11c3a366
TA
6#include <stddef.h>
7#include <stdint.h>
a53f90ca 8#include <string.h>
9bf3b535
LP
9#include <sys/types.h>
10
c2911d48
ZJS
11#include "time-util.h"
12
7c57f504 13struct siphash {
6059dab8
LP
14 uint64_t v0;
15 uint64_t v1;
16 uint64_t v2;
17 uint64_t v3;
18 uint64_t padding;
19 size_t inlen;
7c57f504
TG
20};
21
3042bbeb 22void siphash24_init(struct siphash *state, const uint8_t k[static 16]);
7c57f504 23void siphash24_compress(const void *in, size_t inlen, struct siphash *state);
d5115566
LP
24#define siphash24_compress_byte(byte, state) siphash24_compress((const uint8_t[]) { (byte) }, 1, (state))
25
6c04fccb
YW
26static inline void siphash24_compress_boolean(bool in, struct siphash *state) {
27 uint8_t i = in;
28
29 siphash24_compress(&i, sizeof i, state);
30}
31
c2911d48
ZJS
32static inline void siphash24_compress_usec_t(usec_t in, struct siphash *state) {
33 siphash24_compress(&in, sizeof in, state);
34}
35
1c568d65
YW
36static inline void siphash24_compress_string(const char *in, struct siphash *state) {
37 if (!in)
38 return;
39
40 siphash24_compress(in, strlen(in), state);
41}
42
933f9cae 43uint64_t siphash24_finalize(struct siphash *state);
7c57f504 44
3042bbeb 45uint64_t siphash24(const void *in, size_t inlen, const uint8_t k[static 16]);
a53f90ca 46
3042bbeb 47static inline uint64_t siphash24_string(const char *s, const uint8_t k[static 16]) {
a53f90ca
LP
48 return siphash24(s, strlen(s) + 1, k);
49}