]> git.proxmox.com Git - systemd.git/blame - src/basic/siphash24.h
bump version to 252.11-pve1
[systemd.git] / src / basic / siphash24.h
CommitLineData
a032b68d
MB
1/* SPDX-License-Identifier: CC0-1.0 */
2
60f067b4
JS
3#pragma once
4
5#include <inttypes.h>
4c89c718
MP
6#include <stddef.h>
7#include <stdint.h>
60f067b4
JS
8#include <sys/types.h>
9
1ce460ce 10#include "string-util.h"
129ef395
MB
11#include "time-util.h"
12
6300502b 13struct siphash {
db2df898
MP
14 uint64_t v0;
15 uint64_t v1;
16 uint64_t v2;
17 uint64_t v3;
18 uint64_t padding;
19 size_t inlen;
6300502b
MP
20};
21
7c20daf6 22void siphash24_init(struct siphash *state, const uint8_t k[static 16]);
6300502b 23void siphash24_compress(const void *in, size_t inlen, struct siphash *state);
4c89c718
MP
24#define siphash24_compress_byte(byte, state) siphash24_compress((const uint8_t[]) { (byte) }, 1, (state))
25
a10f5d05
MB
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
129ef395
MB
32static inline void siphash24_compress_usec_t(usec_t in, struct siphash *state) {
33 siphash24_compress(&in, sizeof in, state);
34}
35
1ce460ce
MB
36static inline void siphash24_compress_safe(const void *in, size_t inlen, struct siphash *state) {
37 if (inlen == 0)
a10f5d05
MB
38 return;
39
1ce460ce
MB
40 siphash24_compress(in, inlen, state);
41}
42
43static inline void siphash24_compress_string(const char *in, struct siphash *state) {
44 siphash24_compress_safe(in, strlen_ptr(in), state);
a10f5d05
MB
45}
46
db2df898 47uint64_t siphash24_finalize(struct siphash *state);
6300502b 48
7c20daf6 49uint64_t siphash24(const void *in, size_t inlen, const uint8_t k[static 16]);
6e866b33 50
7c20daf6 51static inline uint64_t siphash24_string(const char *s, const uint8_t k[static 16]) {
6e866b33
MB
52 return siphash24(s, strlen(s) + 1, k);
53}