From: Vsevolod Stakhov Date: Mon, 3 Apr 2017 13:21:44 +0000 (+0100) Subject: [Minor] Add images shingles keys caching X-Git-Tag: 1.5.5~60 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=5852f300295f0637cda9a53c4271f0b65cafe4c3;p=rspamd.git [Minor] Add images shingles keys caching --- diff --git a/src/libutil/shingles.c b/src/libutil/shingles.c index ddac12ac4..73fa04ea1 100644 --- a/src/libutil/shingles.c +++ b/src/libutil/shingles.c @@ -243,11 +243,8 @@ rspamd_shingles_from_image (guchar *dct, { struct rspamd_shingle *shingle; guint64 **hashes; - rspamd_sipkey_t keys[RSPAMD_SHINGLE_SIZE]; - guchar shabuf[rspamd_cryptobox_HASHBYTES], *out_key; - const guchar *cur_key; + guchar **keys; guint64 d; - rspamd_cryptobox_hash_state_t bs; guint64 val; gint i, j; gsize hlen, beg = 0; @@ -261,31 +258,13 @@ rspamd_shingles_from_image (guchar *dct, shingle = g_malloc (sizeof (*shingle)); } - rspamd_cryptobox_hash_init (&bs, NULL, 0); - cur_key = key; - out_key = (guchar *)&keys[0]; - /* Init hashes pipes and keys */ hashes = g_slice_alloc (sizeof (*hashes) * RSPAMD_SHINGLE_SIZE); hlen = RSPAMD_DCT_LEN / NBBY + 1; + keys = rspamd_shingles_get_keys_cached (key); for (i = 0; i < RSPAMD_SHINGLE_SIZE; i ++) { hashes[i] = g_slice_alloc (hlen * sizeof (guint64)); - /* - * To generate a set of hashes we just apply sha256 to the - * initial key as many times as many hashes are required and - * xor left and right parts of sha256 to get a single 16 bytes SIP key. - */ - rspamd_cryptobox_hash_update (&bs, cur_key, 16); - rspamd_cryptobox_hash_final (&bs, shabuf); - - for (j = 0; j < 16; j ++) { - out_key[j] = shabuf[j]; - } - - rspamd_cryptobox_hash_init (&bs, NULL, 0); - cur_key = out_key; - out_key += 16; } switch (alg) {