]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] New abstract hashing API in cryptobox
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 10 May 2016 15:38:43 +0000 (16:38 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 10 May 2016 15:38:43 +0000 (16:38 +0100)
18 files changed:
src/libcryptobox/cryptobox.c
src/libcryptobox/cryptobox.h
src/libcryptobox/keypairs_cache.c
src/libmime/filter.c
src/libmime/message.c
src/libserver/cfg_rcl.c
src/libserver/cfg_utils.c
src/libserver/events.c
src/libserver/protocol.c
src/libserver/re_cache.c
src/libstat/tokenizers/osb.c
src/libutil/addr.c
src/libutil/bloom.c
src/libutil/logger.c
src/libutil/str_util.c
src/libutil/upstream.c
src/lua/lua_task.c
src/rspamd.c

index 1680f1848fdbd26807de6fda99e72b84467ef546..8fb0a7d56776e9b50263bfc410e8ff28001769e9 100644 (file)
@@ -31,6 +31,7 @@
 #include "catena/catena.h"
 #include "ottery.h"
 #include "printf.h"
+#include "xxhash.h"
 
 #ifdef HAVE_CPUID_H
 #include <cpuid.h>
@@ -1408,3 +1409,73 @@ void rspamd_cryptobox_hash (guchar *out,
        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);
+       }
+}
index 9631bd8d06dd2c32cb49d84078a4e3adca43aa2f..9bab560eeaefd4921bb78560df9f4968d1802c5a 100644 (file)
@@ -324,4 +324,46 @@ void rspamd_cryptobox_hash (guchar *out,
                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_ */
index 069158789eba068696c891700a0274d64e2650fd..887aaa85d86c49aa2b9b49abd34343e0942a5334 100644 (file)
@@ -18,7 +18,6 @@
 #include "keypairs_cache.h"
 #include "keypair_private.h"
 #include "hash.h"
-#include "xxhash.h"
 
 struct rspamd_keypair_elt {
        struct rspamd_cryptobox_nm *nm;
@@ -43,7 +42,8 @@ rspamd_keypair_hash (gconstpointer ptr)
 {
        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
index e1a33f3e2236be799de85a877cda33fb7ccb7480..6aaa19aaf9807d803d8cbcdb8ccf06ae6738f4bd 100644 (file)
@@ -19,7 +19,7 @@
 #include "rspamd.h"
 #include "message.h"
 #include "lua/lua_common.h"
-#include "xxhash.h"
+#include "cryptobox.h"
 #include <math.h>
 
 
@@ -273,7 +273,8 @@ rspamd_action_from_str (const gchar *data, gint *result)
 {
        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 */
index 4877fde9f9a0b4d7acfb62abdb3e2e84272c3988..d1fca6b870087dc48df6c215db423705899205e1 100644 (file)
@@ -24,7 +24,7 @@
 #include "email_addr.h"
 #include "utlist.h"
 #include "tokenizers/tokenizers.h"
-#include "xxhash.h"
+#include "cryptobox.h"
 
 #ifdef WITH_SNOWBALL
 #include "libstemmer.h"
@@ -42,6 +42,7 @@
 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)
@@ -1074,7 +1075,12 @@ rspamd_normalize_text_part (struct rspamd_task *task,
                        }
 
                        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);
                        }
                }
index b07819b78ed5010ef4981ef393ba1b8bcc788318..f774ac126c43c8c16bba4bc9211b71c492cf3dea 100644 (file)
@@ -2976,13 +2976,13 @@ static guint
 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
index 233051dcbcd7039dff64849fde8147552061e698..85fd6af80ab62fa7e0999f4b44f17e570217815f 100644 (file)
@@ -1177,7 +1177,7 @@ rspamd_ucl_fin_cb (struct map_cb_data *data)
                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,
index a8cb086cbf93847095636782897e52ca2c7d9b06..44a5d9191604c711dd72dd5f42047233a8a1dbef 100644 (file)
@@ -16,7 +16,7 @@
 #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)
@@ -81,7 +81,7 @@ static guint
 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;
@@ -89,11 +89,11 @@ rspamd_event_hash (gconstpointer a)
 
        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);
 }
 
 
index a394ddaff0473402e4f9bc4f1543befa545727d2..d314d3fdc2f134151f76e0a85581ca0a3d32c5f5 100644 (file)
@@ -23,7 +23,7 @@
 #include "http.h"
 #include "email_addr.h"
 #include "worker_private.h"
-#include "xxhash.h"
+#include "cryptobox.h"
 
 /* Max line size */
 #define OUTBUFSIZ BUFSIZ
@@ -401,7 +401,8 @@ rspamd_protocol_handle_headers (struct rspamd_task *task,
                                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",
index 5882114f93b8d396caffcc0604954454572d0b77..3e308415db2f915f5b8a151259a98812c011cf55 100644 (file)
@@ -15,7 +15,6 @@
  */
 #include "libmime/message.h"
 #include "re_cache.h"
-#include "xxhash.h"
 #include "cryptobox.h"
 #include "ref.h"
 #include "libserver/url.h"
@@ -123,16 +122,16 @@ rspamd_re_cache_class_id (enum rspamd_re_type type,
                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
@@ -1174,7 +1173,8 @@ rspamd_re_cache_type_from_string (const char *str)
         */
 
        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 */
index 906c1de254462ba9c6d401635bbc79f39ac381cf..c2e050f2332af28d136984eac6c9afbf606399a2 100644 (file)
@@ -19,7 +19,6 @@
 
 #include "tokenizers.h"
 #include "stat_internal.h"
-#include "xxhash.h"
 #include "cryptobox.h"
 
 /* Size for features pipe */
@@ -280,7 +279,8 @@ rspamd_tokenizer_osb (struct rspamd_stat_ctx *ctx,
        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;
@@ -300,7 +300,8 @@ rspamd_tokenizer_osb (struct rspamd_stat_ctx *ctx,
                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,
index 8fc85e6c71bc160ea9c32cf30637863f020692fe..18414a98cc6ef8bdc1769bd362e7bb197b149169 100644 (file)
@@ -17,7 +17,7 @@
 #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 */
@@ -1352,28 +1352,28 @@ guint
 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
index 8c8b80ae6d8e2ee9672afbb37d08a7f6d5fa17ee..2447b1b1093e0dae0dd4bab7016fb4b02a6db796 100644 (file)
@@ -15,7 +15,7 @@
  */
 #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
@@ -107,7 +107,8 @@ rspamd_bloom_add (rspamd_bloom_filter_t * bloom, const gchar *s)
        }
        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);
        }
 
@@ -126,7 +127,8 @@ rspamd_bloom_del (rspamd_bloom_filter_t * bloom, const gchar *s)
        }
        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);
        }
 
@@ -145,7 +147,8 @@ rspamd_bloom_check (rspamd_bloom_filter_t * bloom, const gchar *s)
        }
        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;
                }
index 21e489b098a0c47af32d338d8a828e5f34425ec1..f81730448df638500bab95afe822d6d94f19d2b5 100644 (file)
@@ -18,7 +18,7 @@
 #include "util.h"
 #include "rspamd.h"
 #include "map.h"
-#include "xxhash.h"
+#include "cryptobox.h"
 #include "unix-std.h"
 
 #ifdef HAVE_SYSLOG_H
@@ -82,12 +82,6 @@ static rspamd_logger_t *default_logger = NULL;
        }                                                                                       \
 } 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,
@@ -106,7 +100,7 @@ static void
 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 ());
 }
 
 /*
index 7d40b15fa41238dca1abef78c45cfe84b227826d..a25dc32d51552b6a3b84fbecd95eac4d6197caaf 100644 (file)
@@ -15,7 +15,7 @@
  */
 #include "config.h"
 #include "util.h"
-#include "xxhash.h"
+#include "cryptobox.h"
 #include "url.h"
 #include <math.h>
 
@@ -182,20 +182,6 @@ rspamd_strcase_equal (gconstpointer v, gconstpointer v2)
        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)
 {
@@ -208,10 +194,10 @@ 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];
@@ -219,7 +205,7 @@ rspamd_icase_hash (const gchar *in, gsize len)
                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;
@@ -230,11 +216,11 @@ rspamd_icase_hash (const gchar *in, gsize len)
                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
@@ -255,7 +241,7 @@ rspamd_str_hash (gconstpointer key)
 
        len = strlen ((const gchar *)key);
 
-       return XXH_ONESHOT (key, len, rspamd_hash_seed ());
+       return rspamd_cryptobox_fast_hash (key, len, rspamd_hash_seed ());
 }
 
 gboolean
@@ -1814,17 +1800,17 @@ guint
 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 */
index 020039d7139eb9e040806a2e75295bb64c1aa88f..fe07e89d217a3169ccc94c10bc884ec605de3e4d 100644 (file)
@@ -19,7 +19,7 @@
 #include "ref.h"
 #include "cfg_file.h"
 #include "rdns.h"
-#include "xxhash.h"
+#include "cryptobox.h"
 #include "utlist.h"
 
 struct upstream_inet_addr_entry {
@@ -785,7 +785,8 @@ rspamd_upstream_get_hashed (struct upstream_list *ups, const guint8 *key, guint
        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);
index 31b0aac765c5a40bb82a808814c8f88502238abb..7a756679b317dd9f44bd31aed90332309176509c 100644 (file)
@@ -23,7 +23,7 @@
 #include "cfg_file.h"
 #include "email_addr.h"
 #include "utlist.h"
-#include "xxhash.h"
+#include "cryptobox.h"
 
 /***
  * @module rspamd_task
@@ -1568,7 +1568,8 @@ lua_task_str_to_get_type (lua_State *L, gint pos)
                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 */
index e67977cbd502dde3ce3134734121ab28f5af16a2..72e676267fe6ef121783dd084d51a14818eb5791 100644 (file)
@@ -21,7 +21,7 @@
 #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 */
@@ -409,30 +409,30 @@ systemd_get_socket (struct rspamd_main *rspamd_main, gint number)
 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
@@ -959,7 +959,7 @@ rspamd_control_handler (gint fd, short what, gpointer arg)
 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