]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/basic/siphash24.h
hexdecoct: make unbase64mem and unhexmem always use SIZE_MAX
[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>
9bf3b535
LP
8#include <sys/types.h>
9
0b71a7e0 10#include "string-util.h"
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 24#define siphash24_compress_byte(byte, state) siphash24_compress((const uint8_t[]) { (byte) }, 1, (state))
c01a5c05
YW
25#define siphash24_compress_typesafe(in, state) \
26 siphash24_compress(&(in), sizeof(typeof(in)), (state))
d5115566 27
6c04fccb 28static inline void siphash24_compress_boolean(bool in, struct siphash *state) {
c01a5c05 29 siphash24_compress_byte(in, state);
6c04fccb
YW
30}
31
c2911d48 32static inline void siphash24_compress_usec_t(usec_t in, struct siphash *state) {
8722c7e7 33 uint64_t u = htole64(in);
c01a5c05 34 siphash24_compress_typesafe(u, state);
c2911d48
ZJS
35}
36
0b71a7e0
YW
37static inline void siphash24_compress_safe(const void *in, size_t inlen, struct siphash *state) {
38 if (inlen == 0)
1c568d65
YW
39 return;
40
0b71a7e0
YW
41 siphash24_compress(in, inlen, state);
42}
43
44static inline void siphash24_compress_string(const char *in, struct siphash *state) {
45 siphash24_compress_safe(in, strlen_ptr(in), state);
1c568d65
YW
46}
47
933f9cae 48uint64_t siphash24_finalize(struct siphash *state);
7c57f504 49
3042bbeb 50uint64_t siphash24(const void *in, size_t inlen, const uint8_t k[static 16]);
a53f90ca 51
3042bbeb 52static inline uint64_t siphash24_string(const char *s, const uint8_t k[static 16]) {
a53f90ca
LP
53 return siphash24(s, strlen(s) + 1, k);
54}