#include "catena/catena.h"
#include "ottery.h"
#include "printf.h"
+#include "xxhash.h"
#ifdef HAVE_CPUID_H
#include <cpuid.h>
rspamd_cryptobox_hash_update (&st, data, len);
rspamd_cryptobox_hash_final (&st, out);
}
+
+
+void
+rspamd_cryptobox_fast_hash_init (rspamd_cryptobox_fast_hash_state_t *st,
+ guint64 seed)
+{
+#if defined(__LP64__) || defined(_LP64)
+ XXH64_state_t *rst = (XXH64_state_t *)st;
+ XXH64_reset (rst, seed);
+#else
+ XXH32_state_t *rst = (XXH32_state_t *)st;
+ XXH32_reset (rst, seed);
+#endif
+}
+
+void
+rspamd_cryptobox_fast_hash_update (rspamd_cryptobox_fast_hash_state_t *st,
+ const void *data, gsize len)
+{
+#if defined(__LP64__) || defined(_LP64)
+ XXH64_state_t *rst = (XXH64_state_t *)st;
+ XXH64_update (rst, data, len);
+#else
+ XXH32_state_t *rst = (XXH32_state_t *)st;
+ XXH32_update (rst, data, len);
+#endif
+}
+
+guint64
+rspamd_cryptobox_fast_hash_final (rspamd_cryptobox_fast_hash_state_t *st)
+{
+#if defined(__LP64__) || defined(_LP64)
+ XXH64_state_t *rst = (XXH64_state_t *)st;
+ return XXH64_digest (rst);
+#else
+ XXH32_state_t *rst = (XXH32_state_t *)st;
+ XXH32_digest (rst);
+#endif
+
+}
+
+/**
+ * One in all function
+ */
+guint64
+rspamd_cryptobox_fast_hash (const void *data,
+ gsize len, guint64 seed)
+{
+#if defined(__LP64__) || defined(_LP64)
+ return XXH64 (data, len, seed);
+#else
+ return XXH32 (data, len, seed);
+#endif
+}
+
+
+guint64
+rspamd_cryptobox_fast_hash_specific (
+ enum rspamd_cryptobox_fast_hash_type type,
+ const void *data,
+ gsize len, guint64 seed)
+{
+ switch (type) {
+ case RSPAMD_CRYPTOBOX_XXHASH32:
+ return XXH32 (data, len, seed);
+ case RSPAMD_CRYPTOBOX_XXHASH64:
+ default:
+ return XXH64 (data, len, seed);
+ }
+}
const guchar *key,
gsize keylen);
+/* Non crypto hash IUF interface */
+typedef struct RSPAMD_ALIGNED(32) rspamd_cryptobox_fast_hash_state_s {
+ unsigned char opaque[88];
+} rspamd_cryptobox_fast_hash_state_t;
+
+/**
+ * Init cryptobox hash state using key if needed, `st` must point to the buffer
+ * with at least rspamd_cryptobox_HASHSTATEBYTES bytes length. If keylen == 0, then
+ * non-keyed hash is generated
+ */
+void rspamd_cryptobox_fast_hash_init (rspamd_cryptobox_fast_hash_state_t *st,
+ guint64 seed);
+
+/**
+ * Update hash with data portion
+ */
+void rspamd_cryptobox_fast_hash_update (rspamd_cryptobox_fast_hash_state_t *st,
+ const void *data, gsize len);
+
+/**
+ * Output hash to the buffer of rspamd_cryptobox_HASHBYTES length
+ */
+guint64 rspamd_cryptobox_fast_hash_final (rspamd_cryptobox_fast_hash_state_t *st);
+
+/**
+ * One in all function
+ */
+guint64 rspamd_cryptobox_fast_hash (const void *data,
+ gsize len, guint64 seed);
+
+enum rspamd_cryptobox_fast_hash_type {
+ RSPAMD_CRYPTOBOX_XXHASH64 = 0,
+ RSPAMD_CRYPTOBOX_XXHASH32
+};
+/**
+ * Platform independent version
+ */
+guint64 rspamd_cryptobox_fast_hash_specific (
+ enum rspamd_cryptobox_fast_hash_type type,
+ const void *data,
+ gsize len, guint64 seed);
+
#endif /* CRYPTOBOX_H_ */
#include "keypairs_cache.h"
#include "keypair_private.h"
#include "hash.h"
-#include "xxhash.h"
struct rspamd_keypair_elt {
struct rspamd_cryptobox_nm *nm;
{
struct rspamd_keypair_elt *elt = (struct rspamd_keypair_elt *)ptr;
- return XXH64 (elt->pair, sizeof (elt->pair), rspamd_hash_seed ());
+ return rspamd_cryptobox_fast_hash (elt->pair, sizeof (elt->pair),
+ rspamd_hash_seed ());
}
static gboolean
#include "rspamd.h"
#include "message.h"
#include "lua/lua_common.h"
-#include "xxhash.h"
+#include "cryptobox.h"
#include <math.h>
{
guint64 h;
- h = XXH64 (data, strlen (data), 0xdeadbabe);
+ h = rspamd_cryptobox_fast_hash_specific (RSPAMD_CRYPTOBOX_XXHASH64,
+ data, strlen (data), 0xdeadbabe);
switch (h) {
case 0x9917BFDB46332B8CULL: /* reject */
#include "email_addr.h"
#include "utlist.h"
#include "tokenizers/tokenizers.h"
-#include "xxhash.h"
+#include "cryptobox.h"
#ifdef WITH_SNOWBALL
#include "libstemmer.h"
static const gchar gtube_pattern[] = "XJS*C4JDBQADN1.NSBN3*2IDNEN*"
"GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X";
static rspamd_regexp_t *utf_compatible_re = NULL;
+static const guint64 words_hash_seed = 0xdeadbabe;
static GQuark
rspamd_message_quark (void)
}
if (w->len > 0) {
- h = XXH64 (w->begin, w->len, rspamd_hash_seed ());
+ /*
+ * We use static hash seed if we would want to use that in shingles
+ * computation in future
+ */
+ h = rspamd_cryptobox_fast_hash_specific (RSPAMD_CRYPTOBOX_XXHASH64,
+ w->begin, w->len, words_hash_seed);
g_array_append_val (part->normalized_hashes, h);
}
}
rspamd_worker_param_key_hash (gconstpointer p)
{
const struct rspamd_worker_param_key *k = p;
- XXH64_state_t st;
+ rspamd_cryptobox_fast_hash_state_t st;
- XXH64_reset (&st, rspamd_hash_seed ());
- XXH64_update (&st, k->name, strlen (k->name));
- XXH64_update (&st, &k->ptr, sizeof (gpointer));
+ rspamd_cryptobox_fast_hash_init (&st, rspamd_hash_seed ());
+ rspamd_cryptobox_fast_hash_update (&st, k->name, strlen (k->name));
+ rspamd_cryptobox_fast_hash_update (&st, &k->ptr, sizeof (gpointer));
- return XXH64_digest (&st);
+ return rspamd_cryptobox_fast_hash_final (&st);
}
static gboolean
return;
}
- checksum = XXH64 (cbdata->buf->str, cbdata->buf->len, 0);
+ checksum = rspamd_cryptobox_fast_hash (cbdata->buf->str, cbdata->buf->len, 0);
/* New data available */
parser = ucl_parser_new (0);
if (!ucl_parser_add_chunk (parser, cbdata->buf->str,
#include "config.h"
#include "rspamd.h"
#include "events.h"
-#include "xxhash.h"
+#include "cryptobox.h"
#define RSPAMD_SESSION_FLAG_WATCHING (1 << 0)
#define RSPAMD_SESSION_FLAG_DESTROYING (1 << 1)
rspamd_event_hash (gconstpointer a)
{
const struct rspamd_async_event *ev = a;
- XXH64_state_t st;
+ rspamd_cryptobox_fast_hash_state_t st;
union {
event_finalizer_t f;
gpointer p;
u.f = ev->fin;
- XXH64_reset (&st, rspamd_hash_seed ());
- XXH64_update (&st, &ev->user_data, sizeof (gpointer));
- XXH64_update (&st, &u, sizeof (u));
+ rspamd_cryptobox_fast_hash_init (&st, rspamd_hash_seed ());
+ rspamd_cryptobox_fast_hash_update (&st, &ev->user_data, sizeof (gpointer));
+ rspamd_cryptobox_fast_hash_update (&st, &u, sizeof (u));
- return XXH64_digest (&st);
+ return rspamd_cryptobox_fast_hash_final (&st);
}
#include "http.h"
#include "email_addr.h"
#include "worker_private.h"
-#include "xxhash.h"
+#include "cryptobox.h"
/* Max line size */
#define OUTBUFSIZ BUFSIZ
guint64 h;
guint32 *hp;
- h = XXH64 (hv_tok->begin, hv_tok->len, 0xdeadbabe);
+ h = rspamd_cryptobox_fast_hash_specific (RSPAMD_CRYPTOBOX_XXHASH64,
+ hv_tok->begin, hv_tok->len, 0xdeadbabe);
hp = rspamd_mempool_alloc (task->task_pool, sizeof (*hp));
memcpy (hp, &h, sizeof (*hp));
rspamd_mempool_set_variable (task->task_pool, "settings_hash",
*/
#include "libmime/message.h"
#include "re_cache.h"
-#include "xxhash.h"
#include "cryptobox.h"
#include "ref.h"
#include "libserver/url.h"
gpointer type_data,
gsize datalen)
{
- XXH64_state_t st;
+ rspamd_cryptobox_fast_hash_state_t st;
- XXH64_reset (&st, 0xdeadbabe);
- XXH64_update (&st, &type, sizeof (type));
+ rspamd_cryptobox_fast_hash_init (&st, 0xdeadbabe);
+ rspamd_cryptobox_fast_hash_update (&st, &type, sizeof (type));
if (datalen > 0) {
- XXH64_update (&st, type_data, datalen);
+ rspamd_cryptobox_fast_hash_update (&st, type_data, datalen);
}
- return XXH64_digest (&st);
+ return rspamd_cryptobox_fast_hash_final (&st);
}
static void
*/
if (str != NULL) {
- h = XXH64 (str, strlen (str), 0xdeadbabe);
+ h = rspamd_cryptobox_fast_hash_specific (RSPAMD_CRYPTOBOX_XXHASH64,
+ str, strlen (str), 0xdeadbabe);
switch (h) {
case G_GUINT64_CONSTANT(0x298b9c8a58887d44): /* header */
#include "tokenizers.h"
#include "stat_internal.h"
-#include "xxhash.h"
#include "cryptobox.h"
/* Size for features pipe */
window_size = osb_cf->window_size;
if (prefix) {
- seed = XXH64 (prefix, strlen (prefix), osb_cf->seed);
+ seed = rspamd_cryptobox_fast_hash_specific (RSPAMD_CRYPTOBOX_XXHASH64,
+ prefix, strlen (prefix), osb_cf->seed);
}
else {
seed = osb_cf->seed;
else {
/* We know that the words are normalized */
if (osb_cf->ht == RSPAMD_OSB_HASH_XXHASH) {
- cur = XXH64 (token->begin, token->len, osb_cf->seed);
+ cur = rspamd_cryptobox_fast_hash_specific (RSPAMD_CRYPTOBOX_XXHASH64,
+ token->begin, token->len, osb_cf->seed);
}
else {
rspamd_cryptobox_siphash ((guchar *)&cur, token->begin,
#include "addr.h"
#include "util.h"
#include "logger.h"
-#include "xxhash.h"
+#include "cryptobox.h"
#include "radix.h"
#include "unix-std.h"
/* pwd and grp */
rspamd_inet_address_hash (gconstpointer a)
{
const rspamd_inet_addr_t *addr = a;
- XXH64_state_t st;
+ rspamd_cryptobox_fast_hash_state_t st;
- XXH64_reset (&st, rspamd_hash_seed ());
- XXH64_update (&st, &addr->af, sizeof (addr->af));
+ rspamd_cryptobox_fast_hash_init (&st, rspamd_hash_seed ());
+ rspamd_cryptobox_fast_hash_update (&st, &addr->af, sizeof (addr->af));
if (addr->af == AF_UNIX && addr->u.un) {
- XXH64_update (&st, addr->u.un, sizeof (*addr->u.un));
+ rspamd_cryptobox_fast_hash_update (&st, addr->u.un, sizeof (*addr->u.un));
}
else {
/* We ignore port part here */
if (addr->af == AF_INET) {
- XXH64_update (&st, &addr->u.in.addr.s4.sin_addr,
+ rspamd_cryptobox_fast_hash_update (&st, &addr->u.in.addr.s4.sin_addr,
sizeof (addr->u.in.addr.s4.sin_addr));
}
else {
- XXH64_update (&st, &addr->u.in.addr.s6.sin6_addr,
+ rspamd_cryptobox_fast_hash_update (&st, &addr->u.in.addr.s6.sin6_addr,
sizeof (addr->u.in.addr.s6.sin6_addr));
}
}
- return XXH64_digest (&st);
+ return rspamd_cryptobox_fast_hash_final (&st);
}
gboolean
*/
#include "config.h"
#include "bloom.h"
-#include "xxhash.h"
+#include "cryptobox.h"
/* 4 bits are used for counting (implementing delete operation) */
#define SIZE_BIT 4
}
len = strlen (s);
for (n = 0; n < bloom->nfuncs; ++n) {
- v = XXH64 (s, len, bloom->seeds[n]) % bloom->asize;
+ v = rspamd_cryptobox_fast_hash_specific (RSPAMD_CRYPTOBOX_XXHASH64,
+ s, len, bloom->seeds[n]) % bloom->asize;
INCBIT (bloom->a, v, t);
}
}
len = strlen (s);
for (n = 0; n < bloom->nfuncs; ++n) {
- v = XXH64 (s, len, bloom->seeds[n]) % bloom->asize;
+ v = rspamd_cryptobox_fast_hash_specific (RSPAMD_CRYPTOBOX_XXHASH64,
+ s, len, bloom->seeds[n]) % bloom->asize;
DECBIT (bloom->a, v, t);
}
}
len = strlen (s);
for (n = 0; n < bloom->nfuncs; ++n) {
- v = XXH64 (s, len, bloom->seeds[n]) % bloom->asize;
+ v = rspamd_cryptobox_fast_hash_specific (RSPAMD_CRYPTOBOX_XXHASH64,
+ s, len, bloom->seeds[n]) % bloom->asize;
if (!(GETBIT (bloom->a, v))) {
return FALSE;
}
#include "util.h"
#include "rspamd.h"
#include "map.h"
-#include "xxhash.h"
+#include "cryptobox.h"
#include "unix-std.h"
#ifdef HAVE_SYSLOG_H
} \
} while (0)
-#if defined(__LP64__) || defined(_LP64)
-#define XXH_ONESHOT XXH64
-#else
-#define XXH_ONESHOT XXH32
-#endif
-
static void
syslog_log_function (const gchar *log_domain, const gchar *module,
const gchar *id, const gchar *function,
static inline guint64
rspamd_log_calculate_cksum (const gchar *message, size_t mlen)
{
- return XXH_ONESHOT (message, mlen, rspamd_hash_seed ());
+ return rspamd_cryptobox_fast_hash (message, mlen, rspamd_hash_seed ());
}
/*
*/
#include "config.h"
#include "util.h"
-#include "xxhash.h"
+#include "cryptobox.h"
#include "url.h"
#include <math.h>
return FALSE;
}
-#if defined(__LP64__) || defined(_LP64)
-#define XXH_STATE XXH64_state_t
-#define XXH_RESET XXH64_reset
-#define XXH_UPDATE XXH64_update
-#define XXH_DIGEST XXH64_digest
-#define XXH_ONESHOT XXH64
-#else
-#define XXH_STATE XXH32_state_t
-#define XXH_RESET XXH32_reset
-#define XXH_UPDATE XXH32_update
-#define XXH_DIGEST XXH32_digest
-#define XXH_ONESHOT XXH32
-#endif
-
static guint
rspamd_icase_hash (const gchar *in, gsize len)
{
} c;
guint32 pp;
} u;
- XXH_STATE st;
+ rspamd_cryptobox_fast_hash_state_t st;
fp = len - leftover;
- XXH_RESET (&st, rspamd_hash_seed ());
+ rspamd_cryptobox_fast_hash_init (&st, rspamd_hash_seed ());
for (i = 0; i != fp; i += 4) {
u.c.c1 = s[i], u.c.c2 = s[i + 1], u.c.c3 = s[i + 2], u.c.c4 = s[i + 3];
u.c.c2 = lc_map[u.c.c2];
u.c.c3 = lc_map[u.c.c3];
u.c.c4 = lc_map[u.c.c4];
- XXH_UPDATE (&st, &u.pp, sizeof (u));
+ rspamd_cryptobox_fast_hash_update (&st, &u.pp, sizeof (u));
}
u.pp = 0;
u.c.c2 = lc_map[(guchar)s[i++]];
case 1:
u.c.c1 = lc_map[(guchar)s[i]];
- XXH_UPDATE (&st, &u.pp, leftover);
+ rspamd_cryptobox_fast_hash_update (&st, &u.pp, leftover);
break;
}
- return XXH_DIGEST (&st);
+ return rspamd_cryptobox_fast_hash_final (&st);
}
guint
len = strlen ((const gchar *)key);
- return XXH_ONESHOT (key, len, rspamd_hash_seed ());
+ return rspamd_cryptobox_fast_hash (key, len, rspamd_hash_seed ());
}
gboolean
rspamd_url_hash (gconstpointer u)
{
const struct rspamd_url *url = u;
- XXH_STATE st;
+ rspamd_cryptobox_fast_hash_state_t st;
- XXH_RESET (&st, rspamd_hash_seed ());
+ rspamd_cryptobox_fast_hash_init (&st, rspamd_hash_seed ());
if (url->urllen > 0) {
- XXH_UPDATE (&st, url->string, url->urllen);
+ rspamd_cryptobox_fast_hash_update (&st, url->string, url->urllen);
}
- XXH_UPDATE (&st, &url->flags, sizeof (url->flags));
+ rspamd_cryptobox_fast_hash_update (&st, &url->flags, sizeof (url->flags));
- return XXH_DIGEST (&st);
+ return rspamd_cryptobox_fast_hash_final (&st);
}
/* Compare two emails for building emails tree */
#include "ref.h"
#include "cfg_file.h"
#include "rdns.h"
-#include "xxhash.h"
+#include "cryptobox.h"
#include "utlist.h"
struct upstream_inet_addr_entry {
guint32 idx;
/* Generate 64 bits input key */
- k = XXH64 (key, keylen, ups->hash_seed);
+ k = rspamd_cryptobox_fast_hash_specific (RSPAMD_CRYPTOBOX_XXHASH64,
+ key, keylen, ups->hash_seed);
rspamd_mutex_lock (ups->lock);
idx = rspamd_consistent_hash (k, ups->alive->len);
#include "cfg_file.h"
#include "email_addr.h"
#include "utlist.h"
-#include "xxhash.h"
+#include "cryptobox.h"
/***
* @module rspamd_task
type = lua_tolstring (L, pos, &sz);
if (type && sz > 0) {
- h = XXH64 (type, sz, 0xdeadbabe);
+ h = rspamd_cryptobox_fast_hash_specific (RSPAMD_CRYPTOBOX_XXHASH64,
+ type, sz, 0xdeadbabe);
switch (h) {
case 0xDA081341FB600389ULL: /* mime */
#include "libserver/worker_util.h"
#include "libserver/rspamd_control.h"
#include "ottery.h"
-#include "xxhash.h"
+#include "cryptobox.h"
#include "utlist.h"
#include "unix-std.h"
/* sysexits */
static inline uintptr_t
make_listen_key (struct rspamd_worker_bind_conf *cf)
{
- XXH64_state_t st;
+ rspamd_cryptobox_fast_hash_state_t st;
guint i, keylen;
guint8 *key;
rspamd_inet_addr_t *addr;
guint16 port;
- XXH64_reset (&st, rspamd_hash_seed ());
+ rspamd_cryptobox_fast_hash_init (&st, rspamd_hash_seed ());
if (cf->is_systemd) {
- XXH64_update (&st, "systemd", sizeof ("systemd"));
- XXH64_update (&st, &cf->cnt, sizeof (cf->cnt));
+ rspamd_cryptobox_fast_hash_update (&st, "systemd", sizeof ("systemd"));
+ rspamd_cryptobox_fast_hash_update (&st, &cf->cnt, sizeof (cf->cnt));
}
else {
- XXH64_update (&st, cf->name, strlen (cf->name));
+ rspamd_cryptobox_fast_hash_update (&st, cf->name, strlen (cf->name));
for (i = 0; i < cf->cnt; i ++) {
addr = g_ptr_array_index (cf->addrs, i);
key = rspamd_inet_address_get_radix_key (
addr, &keylen);
- XXH64_update (&st, key, keylen);
+ rspamd_cryptobox_fast_hash_update (&st, key, keylen);
port = rspamd_inet_address_get_port (addr);
- XXH64_update (&st, &port, sizeof (port));
+ rspamd_cryptobox_fast_hash_update (&st, &port, sizeof (port));
}
}
- return XXH64_digest (&st);
+ return rspamd_cryptobox_fast_hash_final (&st);
}
static void
static guint
rspamd_spair_hash (gconstpointer p)
{
- return XXH64 (p, PAIR_ID_LEN, rspamd_hash_seed ());
+ return rspamd_cryptobox_fast_hash (p, PAIR_ID_LEN, rspamd_hash_seed ());
}
static gboolean