2020-10-27 18:32:27 +01:00
|
|
|
/* SPDX-License-Identifier: CC0-1.0 */
|
|
|
|
|
2013-12-22 19:59:12 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <inttypes.h>
|
2015-11-30 21:43:37 +01:00
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdint.h>
|
2013-12-22 19:59:12 +01:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
2020-12-29 17:44:04 +01:00
|
|
|
#include "string-util.h"
|
2020-08-28 12:21:48 +02:00
|
|
|
#include "time-util.h"
|
|
|
|
|
2015-10-04 00:23:25 +02:00
|
|
|
struct siphash {
|
2015-11-17 01:08:44 +01:00
|
|
|
uint64_t v0;
|
|
|
|
uint64_t v1;
|
|
|
|
uint64_t v2;
|
|
|
|
uint64_t v3;
|
|
|
|
uint64_t padding;
|
|
|
|
size_t inlen;
|
2015-10-04 00:23:25 +02:00
|
|
|
};
|
|
|
|
|
2019-01-04 12:30:45 +01:00
|
|
|
void siphash24_init(struct siphash *state, const uint8_t k[static 16]);
|
2015-10-04 00:23:25 +02:00
|
|
|
void siphash24_compress(const void *in, size_t inlen, struct siphash *state);
|
2016-01-08 01:11:55 +01:00
|
|
|
#define siphash24_compress_byte(byte, state) siphash24_compress((const uint8_t[]) { (byte) }, 1, (state))
|
|
|
|
|
2020-07-20 21:35:56 +02:00
|
|
|
static inline void siphash24_compress_boolean(bool in, struct siphash *state) {
|
|
|
|
uint8_t i = in;
|
|
|
|
|
|
|
|
siphash24_compress(&i, sizeof i, state);
|
|
|
|
}
|
|
|
|
|
2020-08-28 12:21:48 +02:00
|
|
|
static inline void siphash24_compress_usec_t(usec_t in, struct siphash *state) {
|
|
|
|
siphash24_compress(&in, sizeof in, state);
|
|
|
|
}
|
|
|
|
|
2020-12-29 17:44:04 +01:00
|
|
|
static inline void siphash24_compress_safe(const void *in, size_t inlen, struct siphash *state) {
|
|
|
|
if (inlen == 0)
|
2020-07-20 21:42:11 +02:00
|
|
|
return;
|
|
|
|
|
2020-12-29 17:44:04 +01:00
|
|
|
siphash24_compress(in, inlen, state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void siphash24_compress_string(const char *in, struct siphash *state) {
|
|
|
|
siphash24_compress_safe(in, strlen_ptr(in), state);
|
2020-07-20 21:42:11 +02:00
|
|
|
}
|
|
|
|
|
2015-11-16 23:17:52 +01:00
|
|
|
uint64_t siphash24_finalize(struct siphash *state);
|
2015-10-04 00:23:25 +02:00
|
|
|
|
2019-01-04 12:30:45 +01:00
|
|
|
uint64_t siphash24(const void *in, size_t inlen, const uint8_t k[static 16]);
|
2018-10-16 13:56:14 +02:00
|
|
|
|
2019-01-04 12:30:45 +01:00
|
|
|
static inline uint64_t siphash24_string(const char *s, const uint8_t k[static 16]) {
|
2018-10-16 13:56:14 +02:00
|
|
|
return siphash24(s, strlen(s) + 1, k);
|
|
|
|
}
|