aboutsummaryrefslogtreecommitdiffstats
path: root/src/libutil
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-04-08 13:32:53 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-04-08 13:32:53 +0100
commit4cc70328cf728643450ad25eb4c8718942a19e1d (patch)
treed724a566b7e4dbcbecf6118194f05f854389976e /src/libutil
parentf33dfad9746ac11d187fc2b1d6330106c8d59d17 (diff)
downloadrspamd-4cc70328cf728643450ad25eb4c8718942a19e1d.tar.gz
rspamd-4cc70328cf728643450ad25eb4c8718942a19e1d.zip
Use new siphash implementation.
Diffstat (limited to 'src/libutil')
-rw-r--r--src/libutil/shingles.c36
1 files changed, 13 insertions, 23 deletions
diff --git a/src/libutil/shingles.c b/src/libutil/shingles.c
index fa49fdadd..776ecfa96 100644
--- a/src/libutil/shingles.c
+++ b/src/libutil/shingles.c
@@ -23,21 +23,11 @@
#include "shingles.h"
#include "fstring.h"
-#include "siphash.h"
+#include "cryptobox.h"
#include "blake2.h"
#define SHINGLES_WINDOW 3
-static void
-rspamd_shingles_update_row (rspamd_fstring_t *in, struct siphash *h)
-{
- int i;
-
- for (i = 0; i < RSPAMD_SHINGLE_SIZE; i ++) {
- sip24_update (&h[i], in->begin, in->len);
- }
-}
-
struct rspamd_shingle*
rspamd_shingles_generate (GArray *input,
const guchar key[16],
@@ -47,11 +37,13 @@ rspamd_shingles_generate (GArray *input,
{
struct rspamd_shingle *res;
GArray *hashes[RSPAMD_SHINGLE_SIZE];
- struct sipkey keys[RSPAMD_SHINGLE_SIZE];
- struct siphash h[RSPAMD_SHINGLE_SIZE];
+ rspamd_sipkey_t keys[RSPAMD_SHINGLE_SIZE];
guchar shabuf[BLAKE2B_OUTBYTES], *out_key;
const guchar *cur_key;
+ GString *row;
+ rspamd_fstring_t *word;
blake2b_state bs;
+ guint64 val;
gint i, j, beg = 0;
guint8 shalen;
@@ -63,7 +55,7 @@ rspamd_shingles_generate (GArray *input,
}
blake2b_init (&bs, BLAKE2B_OUTBYTES);
- memset (h, 0, sizeof (h));
+ row = g_string_sized_new (256);
cur_key = key;
out_key = (guchar *)&keys[0];
@@ -86,28 +78,24 @@ rspamd_shingles_generate (GArray *input,
blake2b_init (&bs, BLAKE2B_OUTBYTES);
cur_key = out_key;
out_key += 16;
- sip24_init (&h[i], &keys[i]);
}
/* Now parse input words into a vector of hashes using rolling window */
for (i = 0; i <= (gint)input->len; i ++) {
if (i - beg >= SHINGLES_WINDOW || i == (gint)input->len) {
for (j = beg; j < i; j ++) {
- rspamd_shingles_update_row (&g_array_index (input,
- rspamd_fstring_t, j), h);
+ word = &g_array_index (input, rspamd_fstring_t, j);
+ g_string_append_len (row, word->begin, word->len);
}
beg++;
/* Now we need to create a new row here */
for (j = 0; j < RSPAMD_SHINGLE_SIZE; j ++) {
- guint64 val;
-
- val = sip24_final (&h[j]);
- /* Reinit siphash state */
- memset (&h[j], 0, sizeof (h[0]));
- sip24_init (&h[j], &keys[j]);
+ rspamd_cryptobox_siphash ((guchar *)&val, row->str, row->len,
+ keys[j]);
g_array_append_val (hashes[j], val);
}
+ g_string_assign (row, "");
}
}
@@ -118,6 +106,8 @@ rspamd_shingles_generate (GArray *input,
g_array_free (hashes[i], TRUE);
}
+ g_string_free (row, TRUE);
+
return res;
}