]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
Move constant_memcmp to libutil code.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 24 Sep 2015 16:59:40 +0000 (17:59 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 24 Sep 2015 16:59:40 +0000 (17:59 +0100)
src/controller.c
src/libutil/util.c
src/libutil/util.h

index f21e3c51a01ffca5f8be320fd9c145552db1aa58..f5d7e7637b8fa5206c5ee446a24ae706c67ea310 100644 (file)
 #define COLOR_REJECT "#CB4B4B"
 #define COLOR_TOTAL "#9440ED"
 
-#define RSPAMD_PBKDF_ID_V1 1
-
 const struct timeval rrd_update_time = {
                .tv_sec = 1,
                .tv_usec = 0
@@ -187,40 +185,6 @@ struct rspamd_controller_session {
        gboolean is_spam;
 };
 
-
-const struct rspamd_controller_pbkdf pbkdf_list[] = {
-       {
-               .id = RSPAMD_PBKDF_ID_V1,
-               .rounds = 16000,
-               .salt_len = 20,
-               .key_len = BLAKE2B_OUTBYTES / 2
-       }
-};
-
-static gboolean
-rspamd_constant_memcmp (const guchar *a, const guchar *b, gsize len)
-{
-       gsize lena, lenb, i;
-       gint acc = 0;
-
-       if (len == 0) {
-               lena = strlen (a);
-               lenb = strlen (b);
-
-               if (lena != lenb) {
-                       return FALSE;
-               }
-
-               len = lena;
-       }
-
-       for (i = 0; i < len; i ++) {
-               acc |= a[i] ^ b[i];
-       }
-
-       return acc == 0;
-}
-
 static gboolean
 rspamd_is_encrypted_password (const gchar *password,
                struct rspamd_controller_pbkdf const **pbkdf)
index 5069401713deaa79cb31ae9c02c16561e56014ce..fd66cc321a9353d23115c0038d4e7ac4da0f0f9c 100644 (file)
@@ -54,6 +54,8 @@
 #include <mach/mach_time.h>
 #endif
 
+#include "blake2.h"
+
 /* Check log messages intensity once per minute */
 #define CHECK_TIME 60
 /* More than 2 log messages per second */
 /* Default connect timeout for sync sockets */
 #define CONNECT_TIMEOUT 3
 
+const struct rspamd_controller_pbkdf pbkdf_list[] = {
+               {
+                               .id = RSPAMD_PBKDF_ID_V1,
+                               .rounds = 16000,
+                               .salt_len = 20,
+                               .key_len = BLAKE2B_OUTBYTES / 2
+               }
+};
+
 gint
 rspamd_socket_nonblocking (gint fd)
 {
@@ -1990,6 +2001,30 @@ rspamd_time_jitter (gdouble in, gdouble jitter)
        return in + jitter * res;
 }
 
+gboolean
+rspamd_constant_memcmp (const guchar *a, const guchar *b, gsize len)
+{
+       gsize lena, lenb, i;
+       gint acc = 0;
+
+       if (len == 0) {
+               lena = strlen (a);
+               lenb = strlen (b);
+
+               if (lena != lenb) {
+                       return FALSE;
+               }
+
+               len = lena;
+       }
+
+       for (i = 0; i < len; i++) {
+               acc |= a[i] ^ b[i];
+       }
+
+       return acc == 0;
+}
+
 #if !defined(LIBEVENT_VERSION_NUMBER) || LIBEVENT_VERSION_NUMBER < 0x02000000UL
 struct event_base *
 event_get_base (struct event *ev)
index b0a1650043fb46ce75c67d6f61aa051937c5d13e..df1c30e7d66bd56889013f739f10ad25b823d916 100644 (file)
@@ -402,6 +402,11 @@ guint64 rspamd_hash_seed (void);
  */
 gdouble rspamd_time_jitter (gdouble in, gdouble jitter);
 
+/**
+ * Constant time version of memcmp
+ */
+gboolean rspamd_constant_memcmp (const guchar *a, const guchar *b, gsize len);
+
 /* Special case for ancient libevent */
 #if !defined(LIBEVENT_VERSION_NUMBER) || LIBEVENT_VERSION_NUMBER < 0x02000000UL
 struct event_base * event_get_base (struct event *ev);