CHECK_C_COMPILER_FLAG(-fanalyzer SUPPORT_FANALYZER)
if (SUPPORT_FANALYZER)
set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -fanalyzer")
- set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fanalyzer")
+ #set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fanalyzer")
endif()
endif ()
set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0 ${COMPILER_DEBUG_FLAGS}")
g_string_set_size (res, res->len + b32_len);
res->len -= b32_len;
olen = rspamd_encode_base32_buf (data, datalen, res->str + res->len,
- res->len + b32_len - 1);
+ res->len + b32_len - 1, RSPAMD_BASE32_DEFAULT);
if (olen > 0) {
res->len += olen;
ucl_object_emit_full (cfg->rcl_obj, UCL_EMIT_MSGPACK,
&f, cfg->config_comments);
rspamd_cryptobox_hash_final (&hs, cksumbuf);
- cfg->checksum = rspamd_encode_base32 (cksumbuf, sizeof (cksumbuf));
+ cfg->checksum = rspamd_encode_base32 (cksumbuf, sizeof (cksumbuf), RSPAMD_BASE32_DEFAULT);
/* Also change the tag of cfg pool to be equal to the checksum */
rspamd_strlcpy (cfg->cfg_pool->tag.uid, cfg->checksum,
MIN (sizeof (cfg->cfg_pool->tag.uid), strlen (cfg->checksum)));
}
rspamd_cryptobox_hash_final (&st, id_hash);
- backend->id = rspamd_encode_base32 (id_hash, sizeof (id_hash));
+ backend->id = rspamd_encode_base32 (id_hash, sizeof (id_hash), RSPAMD_BASE32_DEFAULT);
return backend;
}
}
rspamd_cryptobox_hash_final (&st, cksum);
- cksum_encoded = rspamd_encode_base32 (cksum, sizeof (cksum));
+ cksum_encoded = rspamd_encode_base32 (cksum, sizeof (cksum), RSPAMD_BASE32_DEFAULT);
rspamd_strlcpy (map->tag, cksum_encoded, sizeof (map->tag));
g_free (cksum_encoded);
}
rspamd_cryptobox_hash_update (&st, m->url, strlen (m->url));
rspamd_cryptobox_hash_update (&st, loc, strlen (loc));
rspamd_cryptobox_hash_final (&st, cksum);
- cksum_encoded = rspamd_encode_base32 (cksum, sizeof (cksum));
+ cksum_encoded = rspamd_encode_base32 (cksum, sizeof (cksum), RSPAMD_BASE32_DEFAULT);
rspamd_strlcpy (m->tag, cksum_encoded, sizeof (m->tag));
if (g_hash_table_lookup (ctx->helts, m->tag) != NULL) {
tk_conf = tokenizer->get_config (pool, stcf->clcf->tokenizer, &sz);
/* Encode to base32 */
- tok_conf_encoded = rspamd_encode_base32 (tk_conf, sz);
+ tok_conf_encoded = rspamd_encode_base32 (tk_conf, sz, RSPAMD_BASE32_DEFAULT);
if (rspamd_sqlite3_run_prstmt (pool, bk->sqlite, bk->prstmt,
RSPAMD_STAT_BACKEND_SAVE_TOKENIZER,
b32out = rspamd_mempool_alloc (task->task_pool,
sizeof (out) * 8 / 5 + 3);
i = rspamd_encode_base32_buf (out, sizeof (out), b32out,
- sizeof (out) * 8 / 5 + 2);
+ sizeof (out) * 8 / 5 + 2, RSPAMD_BASE32_DEFAULT);
if (i > 0) {
/* Zero terminate */
}
rspamd_cryptobox_hash_final (&hst, hout);
- b32_hout = rspamd_encode_base32 (hout, sizeof (hout));
+ b32_hout = rspamd_encode_base32 (hout, sizeof (hout), RSPAMD_BASE32_DEFAULT);
/*
* We need to strip it to 32 characters providing ~160 bits of
* hash distribution
}
}
- b32buf = rspamd_encode_base32 (p, slen);
+ b32buf = rspamd_encode_base32 (p, slen, RSPAMD_BASE32_DEFAULT);
if (b32buf) {
RSPAMD_PRINTF_APPEND (b32buf, strlen (b32buf));
rspamd_cryptobox_hash_final (&st, sigbuf);
- file->id = rspamd_encode_base32 (sigbuf, sizeof (sigbuf));
+ file->id = rspamd_encode_base32 (sigbuf, sizeof (sigbuf), RSPAMD_BASE32_DEFAULT);
}
}
*/
gint
-rspamd_encode_base32_buf (const guchar *in, gsize inlen, gchar *out,
- gsize outlen)
+rspamd_encode_base32_buf (const guchar *in, gsize inlen, gchar *out, gsize outlen,
+ enum rspamd_base32_type type)
{
- static const char b32[]="ybndrfg8ejkmcpqxot1uwisza345h769";
+ static const char b32_default[] = "ybndrfg8ejkmcpqxot1uwisza345h769",
+ b32_bleach[] = "qpzry9x8gf2tvdw0s3jn54khce6mua7l", *b32;
gchar *o, *end;
gsize i;
gint remain = -1, x;
end = out + outlen;
o = out;
+ switch (type) {
+ case RSPAMD_BASE32_DEFAULT:
+ b32 = b32_default;
+ break;
+ case RSPAMD_BASE32_BLEACH:
+ b32 = b32_bleach;
+ break;
+ default:
+ g_assert_not_reached ();
+ abort ();
+ }
+
for (i = 0; i < inlen && o < end - 1; i++) {
switch (i % 5) {
case 0:
}
gchar *
-rspamd_encode_base32 (const guchar *in, gsize inlen)
+rspamd_encode_base32 (const guchar *in, gsize inlen, enum rspamd_base32_type type)
{
gsize allocated_len = inlen * 8 / 5 + 2;
gchar *out;
gint outlen;
out = g_malloc (allocated_len);
- outlen = rspamd_encode_base32_buf (in, inlen, out, allocated_len - 1);
+ outlen = rspamd_encode_base32_buf (in, inlen, out,
+ allocated_len - 1, type);
if (outlen >= 0) {
out[outlen] = 0;
gpointer rspamd_str_pool_copy (gconstpointer data, gpointer ud);
/**
- * Encode string using base32 encoding
+ * Encode string using hex encoding
* @param in input
* @param inlen input length
* @return freshly allocated base32 encoding of a specified string
*/
-gchar *rspamd_encode_base32 (const guchar *in, gsize inlen);
+gchar *rspamd_encode_hex (const guchar *in, gsize inlen);
/**
- * Decode string using base32 encoding
+ * Decode string using hex encoding
* @param in input
* @param inlen input length
* @return freshly allocated base32 decoded value or NULL if input is invalid
*/
-guchar *rspamd_decode_base32 (const gchar *in, gsize inlen, gsize *outlen);
+guchar *rspamd_decode_hex (const gchar *in, gsize inlen);
+
+enum rspamd_base32_type {
+ RSPAMD_BASE32_DEFAULT = 0,
+ RSPAMD_BASE32_ZBASE = 0,
+ RSPAMD_BASE32_BLEACH
+};
/**
- * Encode string using hex encoding
+ * Encode string using base32 encoding
* @param in input
* @param inlen input length
* @return freshly allocated base32 encoding of a specified string
*/
-gchar *rspamd_encode_hex (const guchar *in, gsize inlen);
+gchar *rspamd_encode_base32 (const guchar *in, gsize inlen,
+ enum rspamd_base32_type type);
/**
- * Decode string using hex encoding
+ * Decode string using base32 encoding
* @param in input
* @param inlen input length
* @return freshly allocated base32 decoded value or NULL if input is invalid
*/
-guchar *rspamd_decode_hex (const gchar *in, gsize inlen);
+guchar *rspamd_decode_base32 (const gchar *in, gsize inlen, gsize *outlen);
/**
* Encode string using base32 encoding
* @return encoded len if `outlen` is enough to encode `inlen`
*/
gint rspamd_encode_base32_buf (const guchar *in, gsize inlen, gchar *out,
- gsize outlen);
+ gsize outlen, enum rspamd_base32_type type);
/**
* Decode string using base32 encoding
guint h = rspamd_cryptobox_fast_hash (upstream->name,
strlen (upstream->name), 0);
memset (upstream->uid, 0, sizeof (upstream->uid));
- rspamd_encode_base32_buf ((const guchar *)&h, sizeof (h),
- upstream->uid, sizeof (upstream->uid) - 1);
+ rspamd_encode_base32_buf ((const guchar *) &h, sizeof (h),
+ upstream->uid, sizeof (upstream->uid) - 1, RSPAMD_BASE32_DEFAULT);
msg_debug_upstream ("added upstream %s (%s)", upstream->name,
upstream->flags & RSPAMD_UPSTREAM_FLAG_NORESOLVE ? "numeric ip" : "DNS name");
gchar *encoded;
if (sig) {
- encoded = rspamd_encode_base32 (sig->str, sig->len);
+ encoded = rspamd_encode_base32 (sig->str, sig->len, RSPAMD_BASE32_DEFAULT);
lua_pushstring (L, encoded);
g_free (encoded);
}
}
}
- rspamd_encode_base32_buf (r, dlen, out_b32, sizeof (out_b32));
+ rspamd_encode_base32_buf (r, dlen, out_b32, sizeof (out_b32), RSPAMD_BASE32_DEFAULT);
lua_pushstring (L, out_b32);
h->is_finished = TRUE;
}
salt, pbkdf->salt_len, key, pbkdf->key_len, pbkdf->complexity,
pbkdf->type);
- encoded_salt = rspamd_encode_base32 (salt, pbkdf->salt_len);
- encoded_key = rspamd_encode_base32 (key, pbkdf->key_len);
+ encoded_salt = rspamd_encode_base32 (salt, pbkdf->salt_len, RSPAMD_BASE32_DEFAULT);
+ encoded_key = rspamd_encode_base32 (key, pbkdf->key_len, RSPAMD_BASE32_DEFAULT);
result = g_string_new ("");
rspamd_printf_gstring (result, "$%d$%s$%s", pbkdf->id, encoded_salt,
lua_pushnil (L);
}
else {
- out = rspamd_encode_base32 (s, inlen);
+ out = rspamd_encode_base32 (s, inlen, RSPAMD_BASE32_DEFAULT);
if (out != NULL) {
t = lua_newuserdata (L, sizeof (*t));
salt, pbkdf->salt_len, key, pbkdf->key_len, pbkdf->complexity,
pbkdf->type);
- encoded_salt = rspamd_encode_base32 (salt, pbkdf->salt_len);
- encoded_key = rspamd_encode_base32 (key, pbkdf->key_len);
+ encoded_salt = rspamd_encode_base32 (salt, pbkdf->salt_len, RSPAMD_BASE32_DEFAULT);
+ encoded_key = rspamd_encode_base32 (key, pbkdf->key_len, RSPAMD_BASE32_DEFAULT);
result = g_string_new ("");
rspamd_printf_gstring (result, "$%d$%s$%s", pbkdf->id, encoded_salt,