commit 8f4a505: [Minor] Use cryptobox api in uthash functions
Vsevolod Stakhov
vsevolod at highsecure.ru
Mon Mar 4 18:14:07 UTC 2019
Author: Vsevolod Stakhov
Date: 2019-03-04 16:43:34 +0000
URL: https://github.com/rspamd/rspamd/commit/8f4a50554256a7e7e777bab8e82e7b5874aedd7d
[Minor] Use cryptobox api in uthash functions
---
src/libutil/uthash_strcase.h | 29 ++++++++++++++++-------------
1 file changed, 16 insertions(+), 13 deletions(-)
diff --git a/src/libutil/uthash_strcase.h b/src/libutil/uthash_strcase.h
index fba97d9b1..5d6f2773c 100644
--- a/src/libutil/uthash_strcase.h
+++ b/src/libutil/uthash_strcase.h
@@ -20,10 +20,13 @@
#error Invalid include order: uthash is already included
#endif
+#include "libcryptobox/cryptobox.h"
+#include "libutil/util.h"
+
/* Utils for uthash tuning */
#ifndef HASH_CASELESS
#define HASH_FUNCTION(key,keylen,num_bkts,hashv,bkt) do {\
- hashv = mum(key, keylen, 0xdeadbabe); \
+ hashv = rspamd_cryptobox_fast_hash(key, keylen, rspamd_hash_seed ()); \
bkt = (hashv) & (num_bkts-1); \
} while (0)
@@ -31,6 +34,7 @@
#else
#define HASH_FUNCTION(key,keylen,num_bkts,hashv,bkt) do {\
unsigned _len = keylen; \
+ rspamd_cryptobox_fast_hash_state_t _hst; \
unsigned _leftover = keylen % 8; \
unsigned _fp, _i; \
const uint8_t* _s = (const uint8_t*)(key); \
@@ -40,9 +44,8 @@
} c; \
uint64_t pp; \
} _u; \
- uint64_t _r; \
_fp = _len - _leftover; \
- _r = 0xdeadbabe; \
+ rspamd_cryptobox_fast_hash_init (&_hst, rspamd_hash_seed ()); \
for (_i = 0; _i != _fp; _i += 8) { \
_u.c.c1 = _s[_i], _u.c.c2 = _s[_i + 1], _u.c.c3 = _s[_i + 2], _u.c.c4 = _s[_i + 3]; \
_u.c.c5 = _s[_i + 4], _u.c.c6 = _s[_i + 5], _u.c.c7 = _s[_i + 6], _u.c.c8 = _s[_i + 7]; \
@@ -54,28 +57,28 @@
_u.c.c2 = lc_map[_u.c.c6]; \
_u.c.c3 = lc_map[_u.c.c7]; \
_u.c.c4 = lc_map[_u.c.c8]; \
- _r = mum_hash_step (_r, _u.pp); \
+ rspamd_cryptobox_fast_hash_update (&_hst, &_u, sizeof (_u)); \
} \
_u.pp = 0; \
switch (_leftover) { \
case 7: \
- _u.c.c7 = lc_map[(unsigned char)_s[_i++]]; \
+ /* fallthrough */ _u.c.c7 = lc_map[(unsigned char)_s[_i++]]; \
case 6: \
- _u.c.c6 = lc_map[(unsigned char)_s[_i++]]; \
+ /* fallthrough */ _u.c.c6 = lc_map[(unsigned char)_s[_i++]]; \
case 5: \
- _u.c.c5 = lc_map[(unsigned char)_s[_i++]]; \
+ /* fallthrough */ _u.c.c5 = lc_map[(unsigned char)_s[_i++]]; \
case 4: \
- _u.c.c4 = lc_map[(unsigned char)_s[_i++]]; \
+ /* fallthrough */ _u.c.c4 = lc_map[(unsigned char)_s[_i++]]; \
case 3: \
- _u.c.c3 = lc_map[(unsigned char)_s[_i++]]; \
+ /* fallthrough */ _u.c.c3 = lc_map[(unsigned char)_s[_i++]]; \
case 2: \
- _u.c.c2 = lc_map[(unsigned char)_s[_i++]]; \
+ /* fallthrough */ _u.c.c2 = lc_map[(unsigned char)_s[_i++]]; \
case 1: \
- _u.c.c1 = lc_map[(unsigned char)_s[_i]]; \
- _r = mum_hash_step (_r, _u.pp); \
+ /* fallthrough */ _u.c.c1 = lc_map[(unsigned char)_s[_i]]; \
+ rspamd_cryptobox_fast_hash_update (&_hst, &_u, sizeof (_u)); \
break; \
} \
- hashv = mum_hash_finish (_r); \
+ hashv = rspamd_cryptobox_fast_hash_final (&_hst); \
bkt = (hashv) & (num_bkts-1); \
} while (0)
#define HASH_KEYCMP(a,b,len) rspamd_lc_cmp(a,b,len)
More information about the Commits
mailing list