diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-07-12 18:16:01 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-07-12 18:16:31 +0100 |
commit | e5762e0dea4859e028d15be692cbcf8113248971 (patch) | |
tree | b6bbae6475f599e97d8e2d810d06fe8a35713823 /src/libmime | |
parent | 9dd08d98d42df99892663e4aabc8f47c5489df61 (diff) | |
download | rspamd-e5762e0dea4859e028d15be692cbcf8113248971.tar.gz rspamd-e5762e0dea4859e028d15be692cbcf8113248971.zip |
[Minor] Use t1ha128 to avoid libsodium version enforcement
Diffstat (limited to 'src/libmime')
-rw-r--r-- | src/libmime/message.c | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/src/libmime/message.c b/src/libmime/message.c index 3efd30da0..6483be0d9 100644 --- a/src/libmime/message.c +++ b/src/libmime/message.c @@ -38,6 +38,7 @@ #include "libserver/cfg_file_private.h" #include "lua/lua_common.h" #include "contrib/uthash/utlist.h" +#include "contrib/t1ha/t1ha.h" #define GTUBE_SYMBOL "GTUBE" @@ -53,7 +54,6 @@ static const gchar gtube_pattern_rewrite_subject[] = "ZJS*C4JDBQADN1.NSBN3*2IDNE struct rspamd_multipattern *gtube_matcher = NULL; static const guint64 words_hash_seed = 0xdeadbabe; - static void free_byte_array_callback (void *pointer) { @@ -1163,6 +1163,7 @@ rspamd_message_parse (struct rspamd_task *task) gsize len; guint i; GError *err = NULL; + guint64 n[2], seed; if (RSPAMD_TASK_IS_EMPTY (task)) { /* Don't do anything with empty task */ @@ -1362,18 +1363,26 @@ rspamd_message_parse (struct rspamd_task *task) 0x30,0x1e,0x70,0x2e,0xb7,0x12,0x09,0xfe, }; + memcpy (&seed, hash_key, sizeof (seed)); + PTR_ARRAY_FOREACH (MESSAGE_FIELD (task, parts), i, part) { - crypto_shorthash_siphashx24 (MESSAGE_FIELD (task, digest), + n[0] = t1ha2_atonce128 (&n[1], part->digest, sizeof (part->digest), - i == 0 ? hash_key : MESSAGE_FIELD (task, digest)); + seed); + + seed = n[0] ^ n[1]; } + memcpy (MESSAGE_FIELD (task, digest), n, sizeof (n)); + /* Parse urls inside Subject header */ if (MESSAGE_FIELD (task, subject)) { p = MESSAGE_FIELD (task, subject); len = strlen (p); - crypto_shorthash_siphashx24 (MESSAGE_FIELD (task, digest), p, len, - MESSAGE_FIELD (task, digest)); + n[0] = t1ha2_atonce128 (&n[1], + p, len, + seed); + memcpy (MESSAGE_FIELD (task, digest), n, sizeof (n)); rspamd_url_find_multiple (task->task_pool, p, len, RSPAMD_URL_FIND_STRICT, NULL, rspamd_url_task_subject_callback, task); @@ -1577,13 +1586,11 @@ void rspamd_message_unref (struct rspamd_message *msg) void rspamd_message_update_digest (struct rspamd_message *msg, const void *input, gsize len) { - guchar RSPAMD_ALIGNED(32) ex_key[crypto_shorthash_siphashx24_KEYBYTES]; - + guint64 n[2]; /* Sanity */ - G_STATIC_ASSERT (sizeof (ex_key) == sizeof (msg->digest)); - G_STATIC_ASSERT (crypto_shorthash_siphashx24_BYTES == sizeof (msg->digest)); - - memcpy (ex_key, msg->digest, sizeof (msg->digest)); + G_STATIC_ASSERT (sizeof (n) == sizeof (msg->digest)); - crypto_shorthash_siphashx24 (msg->digest, input, len, ex_key); + memcpy (n, msg->digest, sizeof (msg->digest)); + n[0] = t1ha2_atonce128 (&n[1], input, len, n[0]); + memcpy (msg->digest, n, sizeof (msg->digest)); }
\ No newline at end of file |