aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-06-20 15:48:21 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-06-20 15:48:21 +0100
commitfd4b04ee901c78b8831681df36603e459bfe0f81 (patch)
treee626c6e80877536ff1b569195f39c069de5c4a78
parent742d8fab29b89ebcb711b44ab7abf3193ae548c5 (diff)
downloadrspamd-fd4b04ee901c78b8831681df36603e459bfe0f81.tar.gz
rspamd-fd4b04ee901c78b8831681df36603e459bfe0f81.zip
[Feature] Use mumhash by default for incremental hashing
-rw-r--r--src/libcryptobox/cryptobox.c71
-rw-r--r--src/libcryptobox/cryptobox.h2
-rw-r--r--src/rspamd.c1
3 files changed, 54 insertions, 20 deletions
diff --git a/src/libcryptobox/cryptobox.c b/src/libcryptobox/cryptobox.c
index 71180da12..08ae1fd8f 100644
--- a/src/libcryptobox/cryptobox.c
+++ b/src/libcryptobox/cryptobox.c
@@ -1412,44 +1412,77 @@ void rspamd_cryptobox_hash (guchar *out,
rspamd_cryptobox_hash_final (&st, out);
}
+/* MUST be 64 bytes at maximum */
+struct rspamd_cryptobox_fast_hash_state_real {
+ guint64 h; /* current hash value */
+ guint64 pos; /* pos in bytes in the buf */
+ guint64 buf;
+};
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
+ struct rspamd_cryptobox_fast_hash_state_real *rst =
+ (struct rspamd_cryptobox_fast_hash_state_real *)st;
+
+ memset (rst, 0, sizeof (*rst));
+ rst->h = seed;
}
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);
+ struct rspamd_cryptobox_fast_hash_state_real *rst =
+ (struct rspamd_cryptobox_fast_hash_state_real *)st;
+ const guchar *d = data;
+ guint leftover;
+ guint64 n;
+
+ leftover = rst->pos;
+
+ if (leftover > 0 && len + leftover >= 8) {
+ n = sizeof (rst->buf) - leftover;
+ memcpy (((guchar *)&rst->buf) + leftover, d, n);
+ d += n;
+ len -= n;
+ rst->h = mum_hash_step (rst->h, rst->buf);
+ rst->buf = 0;
+ }
+
+ while (len > 8) {
+#ifdef _MUM_UNALIGNED_ACCESS
+ rst->h = mum_hash_step (rst->h, *(guint64 *)d);
#else
- XXH32_state_t *rst = (XXH32_state_t *)st;
- XXH32_update (rst, data, len);
+ memcpy (&n, d, sizeof (n));
+ rst->h = mum_hash_step (rst->h, n);
#endif
+ len -= 8;
+ d += 8;
+ }
+
+ if (len > 0 && rst->pos + len <= 8) {
+ memcpy (((guchar *)&rst->buf) + rst->pos, d, len);
+ rst->pos += len;
+ }
}
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
+ struct rspamd_cryptobox_fast_hash_state_real *rst =
+ (struct rspamd_cryptobox_fast_hash_state_real *)st;
+ guint leftover;
+
+ leftover = rst->pos;
+
+ if (leftover > 0) {
+ memset (((guchar *)&rst->buf) + leftover, 0, sizeof (rst->buf) - leftover);
+ rst->h = mum_hash_step (rst->h, rst->buf);
+ }
+ return rst->h;
}
/**
diff --git a/src/libcryptobox/cryptobox.h b/src/libcryptobox/cryptobox.h
index 6facf0a0e..13a3b9121 100644
--- a/src/libcryptobox/cryptobox.h
+++ b/src/libcryptobox/cryptobox.h
@@ -326,7 +326,7 @@ void rspamd_cryptobox_hash (guchar *out,
/* Non crypto hash IUF interface */
typedef struct RSPAMD_ALIGNED(32) rspamd_cryptobox_fast_hash_state_s {
- unsigned char opaque[88];
+ unsigned char opaque[64];
} rspamd_cryptobox_fast_hash_state_t;
/**
diff --git a/src/rspamd.c b/src/rspamd.c
index 922327f38..eaf6c6d30 100644
--- a/src/rspamd.c
+++ b/src/rspamd.c
@@ -508,6 +508,7 @@ spawn_workers (struct rspamd_main *rspamd_main, struct event_base *ev_base)
if (cf->worker->flags & RSPAMD_WORKER_HAS_SOCKET) {
LL_FOREACH (cf->bind_conf, bcf) {
key = make_listen_key (bcf);
+
if ((p =
g_hash_table_lookup (listen_sockets,
GINT_TO_POINTER (key))) == NULL) {