aboutsummaryrefslogtreecommitdiffstats
path: root/src/libutil/shingles.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-12-09 18:47:15 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-12-09 18:47:15 +0000
commitae78cac6dc23367df1df09aee9ea9fade9b7a937 (patch)
tree754dfaf449678da7c6f8c2ac6aa37c54b3539231 /src/libutil/shingles.c
parentfc1eb3ca9480c9550926dfabb39aa8b84cc19c9a (diff)
downloadrspamd-ae78cac6dc23367df1df09aee9ea9fade9b7a937.tar.gz
rspamd-ae78cac6dc23367df1df09aee9ea9fade9b7a937.zip
[Fix] Simplify images shingles
Diffstat (limited to 'src/libutil/shingles.c')
-rw-r--r--src/libutil/shingles.c44
1 files changed, 14 insertions, 30 deletions
diff --git a/src/libutil/shingles.c b/src/libutil/shingles.c
index 9d1068c31..e957a72cc 100644
--- a/src/libutil/shingles.c
+++ b/src/libutil/shingles.c
@@ -16,6 +16,7 @@
#include "shingles.h"
#include "fstring.h"
#include "cryptobox.h"
+#include "images.h"
#define SHINGLES_WINDOW 3
@@ -161,7 +162,7 @@ rspamd_shingles_from_text (GArray *input,
}
struct rspamd_shingle* RSPAMD_OPTIMIZE("unroll-loops")
-rspamd_shingles_from_image (gdouble *dct,
+rspamd_shingles_from_image (guchar *dct,
const guchar key[16],
rspamd_mempool_t *pool,
rspamd_shingles_filter filter,
@@ -173,7 +174,7 @@ rspamd_shingles_from_image (gdouble *dct,
rspamd_sipkey_t keys[RSPAMD_SHINGLE_SIZE];
guchar shabuf[rspamd_cryptobox_HASHBYTES], *out_key;
const guchar *cur_key;
- gdouble d;
+ guint64 d;
rspamd_cryptobox_hash_state_t bs;
guint64 val;
gint i, j, k;
@@ -194,7 +195,7 @@ rspamd_shingles_from_image (gdouble *dct,
/* Init hashes pipes and keys */
hashes = g_slice_alloc (sizeof (*hashes) * RSPAMD_SHINGLE_SIZE);
- hlen = 64 - SHINGLES_WINDOW + 1;
+ hlen = RSPAMD_DCT_LEN / NBBY + 1;
for (i = 0; i < RSPAMD_SHINGLE_SIZE; i ++) {
hashes[i] = g_slice_alloc (hlen * sizeof (guint64));
@@ -232,33 +233,17 @@ rspamd_shingles_from_image (gdouble *dct,
memset (res, 0, sizeof (res));
- for (i = 0; i <= 64; i ++) {
- if (i - beg >= SHINGLES_WINDOW || i == 64) {
- for (j = 0; j < RSPAMD_SHINGLE_SIZE; j ++) {
- /* Shift hashes window to right */
- for (k = 0; k < SHINGLES_WINDOW - 1; k ++) {
- res[j * SHINGLES_WINDOW + k] =
- res[j * SHINGLES_WINDOW + k + 1];
- }
-
- d = dct[beg];
- /* Insert the last element to the pipe */
- memcpy (&seed, keys[j], sizeof (seed));
- res[j * SHINGLES_WINDOW + SHINGLES_WINDOW - 1] =
- rspamd_cryptobox_fast_hash_specific (ht,
- &d, sizeof (d),
- seed);
- val = 0;
- for (k = 0; k < SHINGLES_WINDOW; k ++) {
- val ^= res[j * SHINGLES_WINDOW + k] >>
- (8 * (SHINGLES_WINDOW - k - 1));
- }
-
- g_assert (hlen > beg);
- hashes[j][beg] = val;
- }
- beg++;
+ for (i = 0; i <= RSPAMD_DCT_LEN / NBBY; i ++) {
+ for (j = 0; j < RSPAMD_SHINGLE_SIZE; j ++) {
+ d = dct[beg];
+ /* Insert the last element to the pipe */
+ memcpy (&seed, keys[j], sizeof (seed));
+ val = rspamd_cryptobox_fast_hash_specific (ht,
+ &d, sizeof (d),
+ seed);
+ hashes[j][beg] = val;
}
+ beg++;
}
/* Now we need to filter all hashes and make a shingles result */
@@ -273,7 +258,6 @@ rspamd_shingles_from_image (gdouble *dct,
return shingle;
}
-
guint64
rspamd_shingles_default_filter (guint64 *input, gsize count,
gint shno, const guchar *key, gpointer ud)