]>
Commit | Line | Data |
---|---|---|
448e7440 ZJS |
1 | /* SPDX-License-Identifier: CC0-1.0 */ |
2 | ||
9bf3b535 LP |
3 | #pragma once |
4 | ||
0c15577a | 5 | #include "forward.h" |
c2911d48 | 6 | |
7c57f504 | 7 | struct siphash { |
6059dab8 LP |
8 | uint64_t v0; |
9 | uint64_t v1; | |
10 | uint64_t v2; | |
11 | uint64_t v3; | |
12 | uint64_t padding; | |
13 | size_t inlen; | |
7c57f504 TG |
14 | }; |
15 | ||
3042bbeb | 16 | void siphash24_init(struct siphash *state, const uint8_t k[static 16]); |
7c57f504 | 17 | void siphash24_compress(const void *in, size_t inlen, struct siphash *state); |
d5115566 | 18 | #define siphash24_compress_byte(byte, state) siphash24_compress((const uint8_t[]) { (byte) }, 1, (state)) |
c01a5c05 YW |
19 | #define siphash24_compress_typesafe(in, state) \ |
20 | siphash24_compress(&(in), sizeof(typeof(in)), (state)) | |
d5115566 | 21 | |
6c04fccb | 22 | static inline void siphash24_compress_boolean(bool in, struct siphash *state) { |
c01a5c05 | 23 | siphash24_compress_byte(in, state); |
6c04fccb YW |
24 | } |
25 | ||
c2911d48 | 26 | static inline void siphash24_compress_usec_t(usec_t in, struct siphash *state) { |
8722c7e7 | 27 | uint64_t u = htole64(in); |
c01a5c05 | 28 | siphash24_compress_typesafe(u, state); |
c2911d48 ZJS |
29 | } |
30 | ||
0b71a7e0 YW |
31 | static inline void siphash24_compress_safe(const void *in, size_t inlen, struct siphash *state) { |
32 | if (inlen == 0) | |
1c568d65 YW |
33 | return; |
34 | ||
0b71a7e0 YW |
35 | siphash24_compress(in, inlen, state); |
36 | } | |
37 | ||
0c15577a | 38 | void siphash24_compress_string(const char *in, struct siphash *state); |
1c568d65 | 39 | |
933f9cae | 40 | uint64_t siphash24_finalize(struct siphash *state); |
7c57f504 | 41 | |
3042bbeb | 42 | uint64_t siphash24(const void *in, size_t inlen, const uint8_t k[static 16]); |
a53f90ca | 43 | |
0c15577a | 44 | uint64_t siphash24_string(const char *s, const uint8_t k[static 16]); |