aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-10-25 23:30:27 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-10-25 23:30:27 +0000
commitb2a31b2fa2e7b8279af0568f36e657b0375ecad6 (patch)
treeea055b6e27607175253cfa42cde73911091c1f87
parent293fbe463c776c1d169d4030db62fff6cf1fbba4 (diff)
downloadrspamd-b2a31b2fa2e7b8279af0568f36e657b0375ecad6.tar.gz
rspamd-b2a31b2fa2e7b8279af0568f36e657b0375ecad6.zip
Adopt the rest of rspamd for new hash api.
-rw-r--r--src/fuzzy_storage.h2
-rw-r--r--src/libserver/cfg_rcl.c6
-rw-r--r--src/libstat/learn_cache/sqlite3_cache.c12
-rw-r--r--src/plugins/fuzzy_check.c32
4 files changed, 26 insertions, 26 deletions
diff --git a/src/fuzzy_storage.h b/src/fuzzy_storage.h
index e2e959087..c19c6d00e 100644
--- a/src/fuzzy_storage.h
+++ b/src/fuzzy_storage.h
@@ -20,7 +20,7 @@ RSPAMD_PACKED(rspamd_fuzzy_cmd) {
guint8 flag;
gint32 value;
guint32 tag;
- gchar digest[64];
+ gchar digest[rspamd_cryptobox_HASHBYTES];
};
RSPAMD_PACKED(rspamd_fuzzy_shingle_cmd) {
diff --git a/src/libserver/cfg_rcl.c b/src/libserver/cfg_rcl.c
index 7180d8d70..5cf7e31ce 100644
--- a/src/libserver/cfg_rcl.c
+++ b/src/libserver/cfg_rcl.c
@@ -21,7 +21,6 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include <blake2.h>
#include "cfg_rcl.h"
#include "rspamd.h"
#include "uthash_strcase.h"
@@ -32,6 +31,7 @@
#include "composites.h"
#include "libserver/worker_util.h"
#include "unix-std.h"
+#include "cryptobox.h"
#ifdef HAVE_SYSLOG_H
#include <syslog.h>
@@ -2516,7 +2516,7 @@ rspamd_config_read (struct rspamd_config *cfg, const gchar *filename,
GError *err = NULL;
struct rspamd_rcl_section *top, *logger;
struct ucl_parser *parser;
- unsigned char cksumbuf[BLAKE2B_OUTBYTES];
+ unsigned char cksumbuf[rspamd_cryptobox_HASHBYTES];
if (stat (filename, &st) == -1) {
msg_err_config ("cannot stat %s: %s", filename, strerror (errno));
@@ -2536,7 +2536,7 @@ rspamd_config_read (struct rspamd_config *cfg, const gchar *filename,
}
close (fd);
- blake2b (cksumbuf, data, NULL, sizeof (cksumbuf), st.st_size, 0);
+ rspamd_cryptobox_hash (cksumbuf, data, st.st_size, NULL, 0);
cfg->checksum = rspamd_encode_base32 (cksumbuf, sizeof (cksumbuf));
/* Also change the tag of cfg pool to be equal to the checksum */
rspamd_strlcpy (cfg->cfg_pool->tag.uid, cfg->checksum,
diff --git a/src/libstat/learn_cache/sqlite3_cache.c b/src/libstat/learn_cache/sqlite3_cache.c
index 987f6cb0c..889395b4d 100644
--- a/src/libstat/learn_cache/sqlite3_cache.c
+++ b/src/libstat/learn_cache/sqlite3_cache.c
@@ -26,7 +26,7 @@
#include "rspamd.h"
#include "stat_api.h"
#include "stat_internal.h"
-#include "blake2.h"
+#include "cryptobox.h"
#include "ucl.h"
#include "fstring.h"
#include "message.h"
@@ -246,13 +246,13 @@ rspamd_stat_cache_sqlite3_process (struct rspamd_task *task,
{
struct rspamd_stat_sqlite3_ctx *ctx = (struct rspamd_stat_sqlite3_ctx *)c;
struct mime_text_part *part;
- blake2b_state st;
+ rspamd_cryptobox_hash_state_t st;
rspamd_ftok_t *word;
- guchar out[BLAKE2B_OUTBYTES];
+ guchar out[rspamd_cryptobox_HASHBYTES];
guint i, j;
if (ctx != NULL && ctx->db != NULL) {
- blake2b_init (&st, sizeof (out));
+ rspamd_cryptobox_hash_init (&st, NULL, 0);
for (i = 0; i < task->text_parts->len; i ++) {
part = g_ptr_array_index (task->text_parts, i);
@@ -260,12 +260,12 @@ rspamd_stat_cache_sqlite3_process (struct rspamd_task *task,
if (part->words != NULL) {
for (j = 0; j < part->words->len; j ++) {
word = &g_array_index (part->words, rspamd_ftok_t, j);
- blake2b_update (&st, word->begin, word->len);
+ rspamd_cryptobox_hash_update (&st, word->begin, word->len);
}
}
}
- blake2b_final (&st, out, sizeof (out));
+ rspamd_cryptobox_hash_final (&st, out);
return rspamd_stat_cache_sqlite3_check (task->task_pool,
out, sizeof (out), is_spam, ctx);
diff --git a/src/plugins/fuzzy_check.c b/src/plugins/fuzzy_check.c
index e7c932c99..e7af9f42e 100644
--- a/src/plugins/fuzzy_check.c
+++ b/src/plugins/fuzzy_check.c
@@ -46,7 +46,7 @@
#include "libserver/worker_util.h"
#include "fuzzy_storage.h"
#include "utlist.h"
-#include "blake2.h"
+#include "cryptobox.h"
#include "ottery.h"
#include "keypair_private.h"
#include "unix-std.h"
@@ -401,9 +401,10 @@ fuzzy_parse_rule (struct rspamd_config *cfg, const ucl_object_t *obj, gint cb_id
/* Use some default key for all ops */
k = "rspamd";
}
- rule->hash_key = g_string_sized_new (BLAKE2B_KEYBYTES);
- blake2 (rule->hash_key->str, k, NULL, BLAKE2B_KEYBYTES, strlen (k), 0);
- rule->hash_key->len = BLAKE2B_KEYBYTES;
+
+ rule->hash_key = g_string_sized_new (rspamd_cryptobox_HASHBYTES);
+ rspamd_cryptobox_hash (rule->hash_key->str, k, strlen (k), NULL, 0);
+ rule->hash_key->len = rspamd_cryptobox_HASHKEYBYTES;
if ((value = ucl_object_find_key (obj, "fuzzy_shingles_key")) != NULL) {
k = ucl_object_tostring (value);
@@ -411,8 +412,9 @@ fuzzy_parse_rule (struct rspamd_config *cfg, const ucl_object_t *obj, gint cb_id
if (k == NULL) {
k = "rspamd";
}
- rule->shingles_key = g_string_sized_new (16);
- blake2 (rule->shingles_key->str, k, NULL, 16, strlen (k), 0);
+
+ rule->shingles_key = g_string_sized_new (rspamd_cryptobox_HASHBYTES);
+ rspamd_cryptobox_hash (rule->shingles_key->str, k, strlen (k), NULL, 0);
rule->shingles_key->len = 16;
if (rspamd_upstreams_count (rule->servers) == 0) {
@@ -618,7 +620,7 @@ fuzzy_cmd_from_text_part (struct fuzzy_rule *rule,
struct rspamd_fuzzy_encrypted_shingle_cmd *encshcmd;
struct rspamd_shingle *sh;
guint i;
- blake2b_state st;
+ rspamd_cryptobox_hash_state_t st;
rspamd_ftok_t *word;
GArray *words;
struct fuzzy_cmd_io *io;
@@ -638,15 +640,14 @@ fuzzy_cmd_from_text_part (struct fuzzy_rule *rule,
/*
* Generate hash from all words in the part
*/
- g_assert (blake2b_init_key (&st, BLAKE2B_OUTBYTES, rule->hash_key->str,
- rule->hash_key->len) != -1);
+ rspamd_cryptobox_hash_init (&st, rule->hash_key->str, rule->hash_key->len);
words = fuzzy_preprocess_words (part, pool);
for (i = 0; i < words->len; i ++) {
word = &g_array_index (words, rspamd_ftok_t, i);
- blake2b_update (&st, word->begin, word->len);
+ rspamd_cryptobox_hash_update (&st, word->begin, word->len);
}
- blake2b_final (&st, shcmd->basic.digest, sizeof (shcmd->basic.digest));
+ rspamd_cryptobox_hash_final (&st, shcmd->basic.digest);
msg_debug_pool ("loading shingles with key %*xs", 16,
rule->shingles_key->str);
@@ -705,7 +706,7 @@ fuzzy_cmd_from_data_part (struct fuzzy_rule *rule,
struct rspamd_fuzzy_cmd *cmd;
struct rspamd_fuzzy_encrypted_cmd *enccmd;
struct fuzzy_cmd_io *io;
- blake2b_state st;
+ rspamd_cryptobox_hash_state_t st;
struct rspamd_http_keypair *lk, *rk;
if (rule->peer_key) {
@@ -727,10 +728,9 @@ fuzzy_cmd_from_data_part (struct fuzzy_rule *rule,
cmd->shingles_count = 0;
cmd->tag = ottery_rand_uint32 ();
/* Use blake2b for digest */
- g_assert (blake2b_init_key (&st, BLAKE2B_OUTBYTES, rule->hash_key->str,
- rule->hash_key->len) != -1);
- blake2b_update (&st, data, datalen);
- blake2b_final (&st, cmd->digest, sizeof (cmd->digest));
+ rspamd_cryptobox_hash_init (&st, rule->hash_key->str, rule->hash_key->len);
+ rspamd_cryptobox_hash_update (&st, data, datalen);
+ rspamd_cryptobox_hash_final (&st, cmd->digest);
io = rspamd_mempool_alloc (pool, sizeof (*io));
io->replied = FALSE;