blake2b_final (&S, hash);
}
-void
+const char*
blake2b_load (void)
{
guint i;
}
}
}
+
+ return blake2b_opt->desc;
}
const unsigned char *key,
size_t keylen);
-void blake2b_load (void);
+const char* blake2b_load (void);
#if defined(__cplusplus)
}
return ((size_t) p & (sizeof(size_t) - 1)) == 0;
}
-void
+const char *
chacha_load (void)
{
guint i;
}
}
}
+
+ return chacha_impl->desc;
}
void chacha_init (chacha_state *S, const chacha_key *key,
const unsigned char *in, unsigned char *out, size_t inlen,
size_t rounds);
-void chacha_load (void);
+const char* chacha_load (void);
#endif /* CHACHA_H_ */
#include "blake2/blake2.h"
#include "siphash/siphash.h"
#include "ottery.h"
+#include "printf.h"
#ifdef HAVE_CPUID_H
#include <cpuid.h>
return ok == 1;
}
-void
+struct rspamd_cryptobox_library_ctx*
rspamd_cryptobox_init (void)
{
gint cpu[4], nid;
+ gulong bit;
+ static struct rspamd_cryptobox_library_ctx *ctx;
+ GString *buf;
if (cryptobox_loaded) {
/* Ignore reload attempts */
- return;
+ return ctx;
}
cryptobox_loaded = TRUE;
+ ctx = g_malloc0 (sizeof (*ctx));
+
rspamd_cryptobox_cpuid (cpu, 0);
nid = cpu[0];
rspamd_cryptobox_cpuid (cpu, 1);
}
}
+ buf = g_string_new ("");
+
+ for (bit = 0x1; bit != 0; bit <<= 1) {
+ if (cpu_config & bit) {
+ switch (bit) {
+ case CPUID_SSE2:
+ rspamd_printf_gstring (buf, "sse2, ");
+ break;
+ case CPUID_SSE3:
+ rspamd_printf_gstring (buf, "sse3, ");
+ break;
+ case CPUID_SSSE3:
+ rspamd_printf_gstring (buf, "ssse3, ");
+ break;
+ case CPUID_SSE41:
+ rspamd_printf_gstring (buf, "sse4.1, ");
+ break;
+ case CPUID_AVX:
+ rspamd_printf_gstring (buf, "avx, ");
+ break;
+ case CPUID_AVX2:
+ rspamd_printf_gstring (buf, "avx2, ");
+ break;
+ }
+ }
+ }
+
+ if (buf->len > 2) {
+ /* Trim last chars */
+ g_string_erase (buf, buf->len - 2, 2);
+ }
+
+ ctx->cpu_extensions = buf->str;
+ g_string_free (buf, FALSE);
+
+ ctx->chacha20_impl = chacha_load ();
+ ctx->poly1305_impl = poly1305_load ();
+ ctx->siphash_impl = siphash_load ();
+ ctx->curve25519_impl = curve25519_load ();
+ ctx->blake2_impl = blake2b_load ();
- chacha_load ();
- poly1305_load ();
- siphash_load ();
- curve25519_load ();
- blake2b_load ();
+ return ctx;
}
void
typedef guchar rspamd_nonce_t[rspamd_cryptobox_MAX_NONCEBYTES];
typedef guchar rspamd_sipkey_t[rspamd_cryptobox_SIPKEYBYTES];
+struct rspamd_cryptobox_library_ctx {
+ gchar *cpu_extensions;
+ const gchar *curve25519_impl;
+ const gchar *chacha20_impl;
+ const gchar *poly1305_impl;
+ const gchar *siphash_impl;
+ const gchar *blake2_impl;
+};
+
/**
* Init cryptobox library
*/
-void rspamd_cryptobox_init (void);
+struct rspamd_cryptobox_library_ctx* rspamd_cryptobox_init (void);
/**
* Generate new keypair
return TRUE;
}
-void
+const char*
curve25519_load (void)
{
guint i;
}
}
}
+
g_assert (curve25519_test_impl (curve25519_opt));
+
+ return curve25519_opt->desc;
}
int
int curve25519 (guchar *mypublic, const guchar *secret, const guchar *basepoint);
/* Call for optimized implementation of scalarmult if needed */
int curve25519_base (guchar *mypublic, const guchar *secret);
-void curve25519_load (void);
+const char* curve25519_load (void);
#endif
return ((size_t) p & (sizeof(size_t) - 1)) == 0;
}
-void poly1305_load(void)
+const char*
+poly1305_load(void)
{
guint i;
}
}
}
+
+ return poly1305_opt->desc;
}
/* processes inlen bytes (full blocks only), handling input alignment */
const poly1305_key *key);
int poly1305_verify(const unsigned char mac1[16], const unsigned char mac2[16]);
-void poly1305_load(void);
+const char* poly1305_load(void);
#if defined(__cplusplus)
}
static const siphash_impl_t *siphash_opt = &siphash_list[0];
-void
+const char *
siphash_load(void)
{
guint i;
}
}
}
+
+ return siphash_opt->desc;
}
void siphash24 (unsigned char *out, const unsigned char *in,
extern "C"
{
#endif
-void siphash_load (void);
+const char* siphash_load (void);
void siphash24 (unsigned char *out,
const unsigned char *in,
unsigned long long inlen,