guint rspamd_cryptobox_mac_bytes (void);
/* Hash IUF interface */
+typedef struct RSPAMD_ALIGNED(32) rspamd_cryptobox_hash_state_s {
+ unsigned char opaque[256];
+} rspamd_cryptobox_hash_state_t;
/**
* Init cryptobox hash state using key if needed, `st` must point to the buffer
#include "printf.h"
#include "logger.h"
#include "ref.h"
-#include "blake2.h"
#include "ottery.h"
#include "keypair_private.h"
#include "cryptobox.h"
gboolean encrypted = FALSE;
gchar *b32_key, *b32_id;
guchar nonce[rspamd_cryptobox_MAX_NONCEBYTES], mac[rspamd_cryptobox_MAX_MACBYTES],
- id[BLAKE2B_OUTBYTES];
+ id[rspamd_cryptobox_HASHBYTES];
guchar *np = NULL, *mp = NULL, *meth_pos = NULL;
struct rspamd_http_keypair *peer_key = NULL;
gchar *semicolon;
gsize decoded_len;
struct rspamd_http_keypair *kp;
+ guchar kh[rspamd_cryptobox_HASHBYTES];
semicolon = memchr (key, ':', keylen);
REF_INIT_RETAIN (kp, rspamd_http_keypair_dtor);
memcpy (kp->sk, decoded_sk, rspamd_cryptobox_sk_bytes ());
memcpy (kp->pk, decoded_pk, rspamd_cryptobox_pk_bytes ());
- blake2b (kp->id, kp->pk, NULL, sizeof (kp->id),
- rspamd_cryptobox_pk_bytes (), 0);
+ rspamd_cryptobox_hash (kh, kp->pk, rspamd_cryptobox_pk_bytes (),
+ NULL, 0);
+ memcpy (kp->id, kh, sizeof (kp->id));
return (gpointer) kp;
}
rspamd_http_connection_gen_key (void)
{
struct rspamd_http_keypair *kp;
+ guchar kh[rspamd_cryptobox_HASHBYTES];
kp = g_slice_alloc (sizeof (*kp));
REF_INIT_RETAIN (kp, rspamd_http_keypair_dtor);
rspamd_cryptobox_keypair (kp->pk, kp->sk);
- blake2b (kp->id, kp->pk, NULL, sizeof (kp->id),
- rspamd_cryptobox_pk_bytes (), 0);
+ rspamd_cryptobox_hash (kh, kp->pk, rspamd_cryptobox_pk_bytes (),
+ NULL, 0);
+ memcpy (kp->id, kh, sizeof (kp->id));
return (gpointer)kp;
}
guchar *pk_decoded;
gsize dec_len;
struct rspamd_http_keypair *kp = NULL;
+ guchar kh[rspamd_cryptobox_HASHBYTES];
pk_decoded = rspamd_decode_base32 (key, strlen (key), &dec_len);
kp = g_slice_alloc0 (sizeof (*kp));
REF_INIT_RETAIN (kp, rspamd_http_keypair_dtor);
memcpy (kp->pk, pk_decoded, rspamd_cryptobox_pk_bytes ());
- blake2b (kp->id, kp->pk, NULL, sizeof (kp->id),
- rspamd_cryptobox_pk_bytes (), 0);
+ rspamd_cryptobox_hash (kh, kp->pk, rspamd_cryptobox_pk_bytes (),
+ NULL, 0);
+ memcpy (kp->id, kh, sizeof (kp->id));
}
g_free (pk_decoded);
#include "config.h"
#include "ref.h"
-#include "blake2.h"
#include "cryptobox.h"
struct RSPAMD_ALIGNED(32) rspamd_http_keypair {
guchar RSPAMD_ALIGNED(32) sk[rspamd_cryptobox_MAX_SKBYTES];
guchar RSPAMD_ALIGNED(32) nm[rspamd_cryptobox_MAX_NMBYTES];
guchar RSPAMD_ALIGNED(32) pk[rspamd_cryptobox_MAX_PKBYTES];
- guchar id[BLAKE2B_OUTBYTES];
+ guchar id[rspamd_cryptobox_HASHBYTES];
gboolean has_nm;
ref_entry_t ref;
};
#include "map.h"
#include "http.h"
#include "rspamd.h"
-#include "util.h"
-#include "mem_pool.h"
-#include "blake2.h"
+#include "cryptobox.h"
#include "unix-std.h"
static const gchar *hash_fill = "1";
const gchar *def, *p, *hostend;
struct file_map_data *fdata;
struct http_map_data *hdata;
- gchar portbuf[6], *cksum_encoded, cksum[BLAKE2B_OUTBYTES];
+ gchar portbuf[6], *cksum_encoded, cksum[rspamd_cryptobox_HASHBYTES];
gint i, s, r;
struct addrinfo hints, *res;
rspamd_mempool_t *pool;
new_map->map_data = hdata;
}
/* Temp pool */
- blake2b (cksum, new_map->uri, NULL, sizeof (cksum), strlen (new_map->uri), 0);
+ rspamd_cryptobox_hash (cksum, new_map->uri, strlen (new_map->uri), NULL, 0);
cksum_encoded = rspamd_encode_base32 (cksum, sizeof (cksum));
new_map->pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), "map");
memcpy (new_map->pool->tag.uid, cksum_encoded,
#include "config.h"
#include "regexp.h"
-#include "blake2.h"
+#include "cryptobox.h"
#include "ref.h"
#include "util.h"
#include "rspamd.h"
#include <pcre.h>
-typedef guchar regexp_id_t[BLAKE2B_OUTBYTES];
+typedef guchar regexp_id_t[rspamd_cryptobox_HASHBYTES];
#define RSPAMD_REGEXP_FLAG_RAW (1 << 1)
#define RSPAMD_REGEXP_FLAG_NOOPT (1 << 2)
rspamd_regexp_generate_id (const gchar *pattern, const gchar *flags,
regexp_id_t out)
{
- blake2b_state st;
+ rspamd_cryptobox_hash_state_t st;
- blake2b_init (&st, sizeof (regexp_id_t));
+ rspamd_cryptobox_hash_init (&st, NULL, 0);
if (flags) {
- blake2b_update (&st, flags, strlen (flags));
+ rspamd_cryptobox_hash_update (&st, flags, strlen (flags));
}
- blake2b_update (&st, pattern, strlen (pattern));
- blake2b_final (&st, out, sizeof (regexp_id_t));
+ rspamd_cryptobox_hash_update (&st, pattern, strlen (pattern));
+ rspamd_cryptobox_hash_final (&st, out);
}
static void
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include <blake2.h>
#include "config.h"
#include "rrd.h"
#include "util.h"
#include "logger.h"
#include "unix-std.h"
+#include "cryptobox.h"
#include <math.h>
#define msg_err_rrd(...) rspamd_default_log_function (G_LOG_LEVEL_CRITICAL, \
static void
rspamd_rrd_calculate_checksum (struct rspamd_rrd_file *file)
{
- guchar sigbuf[BLAKE2B_OUTBYTES];
+ guchar sigbuf[rspamd_cryptobox_HASHBYTES];
struct rrd_ds_def *ds;
guint i;
- blake2b_state st;
+ rspamd_cryptobox_hash_state_t st;
if (file->finalized) {
- blake2b_init (&st, BLAKE2B_OUTBYTES);
- blake2b_update (&st, file->filename, strlen (file->filename));
+ rspamd_cryptobox_hash_init (&st, NULL, 0);
+ rspamd_cryptobox_hash_update (&st, file->filename, strlen (file->filename));
for (i = 0; i < file->stat_head->ds_cnt; i ++) {
ds = &file->ds_def[i];
- blake2b_update (&st, ds->ds_nam, sizeof (ds->ds_nam));
+ rspamd_cryptobox_hash_update (&st, ds->ds_nam, sizeof (ds->ds_nam));
}
- blake2b_final (&st, sigbuf, BLAKE2B_OUTBYTES);
+ rspamd_cryptobox_hash_final (&st, sigbuf);
file->id = rspamd_encode_base32 (sigbuf, sizeof (sigbuf));
}
#include "shingles.h"
#include "fstring.h"
#include "cryptobox.h"
-#include "blake2.h"
#define SHINGLES_WINDOW 3
struct rspamd_shingle *res;
GArray *hashes[RSPAMD_SHINGLE_SIZE];
rspamd_sipkey_t keys[RSPAMD_SHINGLE_SIZE];
- guchar shabuf[BLAKE2B_OUTBYTES], *out_key;
+ guchar shabuf[rspamd_cryptobox_HASHBYTES], *out_key;
const guchar *cur_key;
GString *row;
rspamd_ftok_t *word;
- blake2b_state bs;
+ rspamd_cryptobox_hash_state_t bs;
guint64 val;
gint i, j, beg = 0;
- guint8 shalen;
if (pool != NULL) {
res = rspamd_mempool_alloc (pool, sizeof (*res));
res = g_malloc (sizeof (*res));
}
- blake2b_init (&bs, BLAKE2B_OUTBYTES);
+ rspamd_cryptobox_hash_init (&bs, NULL, 0);
row = g_string_sized_new (256);
cur_key = key;
out_key = (guchar *)&keys[0];
* initial key as many times as many hashes are required and
* xor left and right parts of sha256 to get a single 16 bytes SIP key.
*/
- shalen = sizeof (shabuf);
- blake2b_update (&bs, cur_key, 16);
- blake2b_final (&bs, shabuf, shalen);
+ rspamd_cryptobox_hash_update (&bs, cur_key, 16);
+ rspamd_cryptobox_hash_final (&bs, shabuf);
for (j = 0; j < 16; j ++) {
out_key[j] = shabuf[j];
}
- blake2b_init (&bs, BLAKE2B_OUTBYTES);
+
+ rspamd_cryptobox_hash_init (&bs, NULL, 0);
cur_key = out_key;
out_key += 16;
}
#include <sys/resource.h>
#endif
-#include "blake2.h"
+#include "cryptobox.h"
/* Check log messages intensity once per minute */
#define CHECK_TIME 60
.id = RSPAMD_PBKDF_ID_V1,
.rounds = 16000,
.salt_len = 20,
- .key_len = BLAKE2B_OUTBYTES / 2
+ .key_len = rspamd_cryptobox_HASHBYTES / 2
}
};