aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/controller.c36
-rw-r--r--src/libutil/util.c35
-rw-r--r--src/libutil/util.h5
3 files changed, 40 insertions, 36 deletions
diff --git a/src/controller.c b/src/controller.c
index f21e3c51a..f5d7e7637 100644
--- a/src/controller.c
+++ b/src/controller.c
@@ -102,8 +102,6 @@
#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)
diff --git a/src/libutil/util.c b/src/libutil/util.c
index 506940171..fd66cc321 100644
--- a/src/libutil/util.c
+++ b/src/libutil/util.c
@@ -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 */
@@ -61,6 +63,15 @@
/* 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)
diff --git a/src/libutil/util.h b/src/libutil/util.h
index b0a165004..df1c30e7d 100644
--- a/src/libutil/util.h
+++ b/src/libutil/util.h
@@ -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);