static const int mapping_size = 64 * 8192 + 1;
static const int max_seg = 32;
static const int random_fuzz_cnt = 10000;
+enum rspamd_cryptobox_mode mode = RSPAMD_CRYPTOBOX_MODE_25519;
static void *
create_mapping (int mapping_len, guchar **beg, guchar **end)
guint64 *t = (guint64 *)begin;
g_assert (rspamd_cryptobox_decrypt_nm_inplace (begin, end - begin, nonce, key,
- mac));
+ mac, mode));
while (t < (guint64 *)end) {
g_assert (*t == 0);
/* Test baseline */
t1 = rspamd_get_ticks ();
- rspamd_cryptobox_encrypt_nm_inplace (begin, end - begin, nonce, key, mac);
+ rspamd_cryptobox_encrypt_nm_inplace (begin, end - begin, nonce, key, mac,
+ mode);
t2 = rspamd_get_ticks ();
check_result (key, nonce, mac, begin, end);
msg_info ("baseline encryption: %.6f", t2 - t1);
- if (rspamd_cryptobox_openssl_mode (TRUE)) {
- t1 = rspamd_get_ticks ();
- rspamd_cryptobox_encrypt_nm_inplace (begin,
- end - begin,
- nonce,
- key,
- mac);
- t2 = rspamd_get_ticks ();
- check_result (key, nonce, mac, begin, end);
+ mode = RSPAMD_CRYPTOBOX_MODE_NIST;
+ t1 = rspamd_get_ticks ();
+ rspamd_cryptobox_encrypt_nm_inplace (begin,
+ end - begin,
+ nonce,
+ key,
+ mac,
+ mode);
+ t2 = rspamd_get_ticks ();
+ check_result (key, nonce, mac, begin, end);
- msg_info ("openssl baseline encryption: %.6f", t2 - t1);
- rspamd_cryptobox_openssl_mode (FALSE);
- }
+ msg_info ("openssl baseline encryption: %.6f", t2 - t1);
+ mode = RSPAMD_CRYPTOBOX_MODE_25519;
start:
/* A single chunk as vector */
seg[0].data = begin;
seg[0].len = end - begin;
t1 = rspamd_get_ticks ();
- rspamd_cryptobox_encryptv_nm_inplace (seg, 1, nonce, key, mac);
+ rspamd_cryptobox_encryptv_nm_inplace (seg, 1, nonce, key, mac, mode);
t2 = rspamd_get_ticks ();
check_result (key, nonce, mac, begin, end);
seg[1].data = begin + seg[0].len;
seg[1].len = (end - begin) - seg[0].len;
t1 = rspamd_get_ticks ();
- rspamd_cryptobox_encryptv_nm_inplace (seg, 2, nonce, key, mac);
+ rspamd_cryptobox_encryptv_nm_inplace (seg, 2, nonce, key, mac, mode);
t2 = rspamd_get_ticks ();
check_result (key, nonce, mac, begin, end);
seg[1].data = begin + seg[0].len;
seg[1].len = (end - begin) - seg[0].len;
t1 = rspamd_get_ticks ();
- rspamd_cryptobox_encryptv_nm_inplace (seg, 2, nonce, key, mac);
+ rspamd_cryptobox_encryptv_nm_inplace (seg, 2, nonce, key, mac, mode);
t2 = rspamd_get_ticks ();
check_result (key, nonce, mac, begin, end);
seg[1].data = begin + seg[0].len;
seg[1].len = (end - begin) - seg[0].len;
t1 = rspamd_get_ticks ();
- rspamd_cryptobox_encryptv_nm_inplace (seg, 2, nonce, key, mac);
+ rspamd_cryptobox_encryptv_nm_inplace (seg, 2, nonce, key, mac, mode);
t2 = rspamd_get_ticks ();
check_result (key, nonce, mac, begin, end);
seg[1].data = begin + seg[0].len;
seg[1].len = (end - begin) - seg[0].len;
t1 = rspamd_get_ticks ();
- rspamd_cryptobox_encryptv_nm_inplace (seg, 2, nonce, key, mac);
+ rspamd_cryptobox_encryptv_nm_inplace (seg, 2, nonce, key, mac, mode);
t2 = rspamd_get_ticks ();
check_result (key, nonce, mac, begin, end);
seg[2].data = begin + seg[0].len + seg[1].len;
seg[2].len = (end - begin) - seg[0].len - seg[1].len;
t1 = rspamd_get_ticks ();
- rspamd_cryptobox_encryptv_nm_inplace (seg, 3, nonce, key, mac);
+ rspamd_cryptobox_encryptv_nm_inplace (seg, 3, nonce, key, mac, mode);
t2 = rspamd_get_ticks ();
check_result (key, nonce, mac, begin, end);
cnt = create_random_split (seg, max_seg, begin, end);
t1 = rspamd_get_ticks ();
- rspamd_cryptobox_encryptv_nm_inplace (seg, cnt, nonce, key, mac);
+ rspamd_cryptobox_encryptv_nm_inplace (seg, cnt, nonce, key, mac, mode);
t2 = rspamd_get_ticks ();
check_result (key, nonce, mac, begin, end);
cnt = create_realistic_split (seg, max_seg, begin, end);
t1 = rspamd_get_ticks ();
- rspamd_cryptobox_encryptv_nm_inplace (seg, cnt, nonce, key, mac);
+ rspamd_cryptobox_encryptv_nm_inplace (seg, cnt, nonce, key, mac, mode);
t2 = rspamd_get_ticks ();
check_result (key, nonce, mac, begin, end);
cnt = create_constrainted_split (seg, max_seg + 1, 32, begin, end);
t1 = rspamd_get_ticks ();
- rspamd_cryptobox_encryptv_nm_inplace (seg, cnt, nonce, key, mac);
+ rspamd_cryptobox_encryptv_nm_inplace (seg, cnt, nonce, key, mac, mode);
t2 = rspamd_get_ticks ();
check_result (key, nonce, mac, begin, end);
ms = ottery_rand_range (i % max_seg * 2) + 1;
cnt = create_random_split (seg, ms, begin, end);
t1 = rspamd_get_ticks ();
- rspamd_cryptobox_encryptv_nm_inplace (seg, cnt, nonce, key, mac);
+ rspamd_cryptobox_encryptv_nm_inplace (seg, cnt, nonce, key, mac, mode);
t2 = rspamd_get_ticks ();
check_result (key, nonce, mac, begin, end);
ms = ottery_rand_range (i % max_seg * 2) + 1;
cnt = create_realistic_split (seg, ms, begin, end);
t1 = rspamd_get_ticks ();
- rspamd_cryptobox_encryptv_nm_inplace (seg, cnt, nonce, key, mac);
+ rspamd_cryptobox_encryptv_nm_inplace (seg, cnt, nonce, key, mac, mode);
t2 = rspamd_get_ticks ();
check_result (key, nonce, mac, begin, end);
ms = ottery_rand_range (i % max_seg * 10) + 1;
cnt = create_constrainted_split (seg, ms, i, begin, end);
t1 = rspamd_get_ticks ();
- rspamd_cryptobox_encryptv_nm_inplace (seg, cnt, nonce, key, mac);
+ rspamd_cryptobox_encryptv_nm_inplace (seg, cnt, nonce, key, mac, mode);
t2 = rspamd_get_ticks ();
check_result (key, nonce, mac, begin, end);
}
}
- if (!checked_openssl && rspamd_cryptobox_openssl_mode (TRUE)) {
+ if (!checked_openssl) {
checked_openssl = TRUE;
+ mode = RSPAMD_CRYPTOBOX_MODE_NIST;
goto start;
}
}
#include "tests.h"
#include "ottery.h"
#include "cryptobox.h"
+#include "keypair.h"
#include "unix-std.h"
#include <math.h>
static void
rspamd_http_server_func (gint fd, const gchar *path, rspamd_inet_addr_t *addr,
- gpointer kp, struct rspamd_keypair_cache *c)
+ struct rspamd_cryptobox_keypair *kp, struct rspamd_keypair_cache *c)
{
struct rspamd_http_connection_router *rt;
struct event_base *ev_base = event_init ();
static void
rspamd_http_client_func (const gchar *path, rspamd_inet_addr_t *addr,
- gpointer kp, gpointer peer_kp, struct rspamd_keypair_cache *c,
+ struct rspamd_cryptobox_keypair *kp,
+ struct rspamd_cryptobox_pubkey *peer_kp,
+ struct rspamd_keypair_cache *c,
struct event_base *ev_base, double *latency)
{
struct rspamd_http_message *msg;
if (kp != NULL) {
g_assert (peer_kp != NULL);
rspamd_http_connection_set_key (conn, kp);
- msg->peer_key = rspamd_http_connection_key_ref (peer_kp);
+ msg->peer_key = rspamd_pubkey_ref (peer_kp);
}
cb = g_malloc (sizeof (*cb));
static void
rspamd_http_start_servers (pid_t *sfd, rspamd_inet_addr_t *addr,
- gpointer serv_key, struct rspamd_keypair_cache *c)
+ struct rspamd_cryptobox_keypair *serv_key,
+ struct rspamd_keypair_cache *c)
{
guint i;
gint fd;
{
struct event_base *ev_base = event_init ();
rspamd_mempool_t *pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), NULL);
- gpointer serv_key, client_key, peer_key;
+ struct rspamd_cryptobox_keypair *serv_key, *client_key;
+ struct rspamd_cryptobox_pubkey *peer_key;
struct rspamd_keypair_cache *c;
rspamd_mempool_mutex_t *mtx;
rspamd_inet_addr_t *addr;
rspamd_parse_inet_address (&addr, "127.0.0.1", 0);
rspamd_inet_address_set_port (addr, 43898);
- serv_key = rspamd_http_connection_gen_key ();
- client_key = rspamd_http_connection_gen_key ();
+ serv_key = rspamd_keypair_new (RSPAMD_KEYPAIR_KEX,
+ RSPAMD_CRYPTOBOX_MODE_25519);
+ client_key = rspamd_keypair_new (RSPAMD_KEYPAIR_KEX,
+ RSPAMD_CRYPTOBOX_MODE_25519);
c = rspamd_keypair_cache_new (16);
rspamd_http_start_servers (sfd, addr, serv_key, NULL);
//rspamd_mempool_lock_mutex (mtx);
usleep (100000);
- b32_key = rspamd_http_connection_print_key (serv_key,
+ b32_key = rspamd_keypair_print (serv_key,
RSPAMD_KEYPAIR_PUBKEY|RSPAMD_KEYPAIR_BASE32);
g_assert (b32_key != NULL);
- peer_key = rspamd_http_connection_make_peer_key (b32_key->str);
+ peer_key = rspamd_pubkey_from_base32 (b32_key->str, b32_key->len,
+ RSPAMD_KEYPAIR_KEX, RSPAMD_CRYPTOBOX_MODE_25519);
g_assert (peer_key != NULL);
total_diff = 0.0;
mean, std);
/* AES mode */
- if (rspamd_cryptobox_openssl_mode (TRUE)) {
- serv_key = rspamd_http_connection_gen_key ();
- client_key = rspamd_http_connection_gen_key ();
- c = rspamd_keypair_cache_new (16);
-
- /* Restart server */
- rspamd_http_stop_servers (sfd);
- /* No keypairs cache */
- rspamd_http_start_servers (sfd, addr, serv_key, c);
-
- //rspamd_mempool_lock_mutex (mtx);
- usleep (100000);
- b32_key = rspamd_http_connection_print_key (serv_key,
- RSPAMD_KEYPAIR_PUBKEY | RSPAMD_KEYPAIR_BASE32);
- g_assert (b32_key != NULL);
- peer_key = rspamd_http_connection_make_peer_key (b32_key->str);
- g_assert (peer_key != NULL);
- total_diff = 0.0;
-
- gperf_profiler_init (NULL, "cached-http-client-aes");
- for (i = 0; i < ntests; i++) {
- for (j = 0; j < pconns; j++) {
- rspamd_http_client_func (filepath + sizeof ("/tmp") - 1,
- addr,
- client_key,
- peer_key,
- NULL,
- ev_base,
- &latency[i * pconns + j]);
- }
- ts1 = rspamd_get_ticks ();
- event_base_loop (ev_base, 0);
- ts2 = rspamd_get_ticks ();
- diff = (ts2 - ts1) * 1000.0;
- total_diff += diff;
+ serv_key = rspamd_keypair_new (RSPAMD_KEYPAIR_KEX,
+ RSPAMD_CRYPTOBOX_MODE_NIST);
+ client_key = rspamd_keypair_new (RSPAMD_KEYPAIR_KEX,
+ RSPAMD_CRYPTOBOX_MODE_NIST);
+ c = rspamd_keypair_cache_new (16);
+
+ /* Restart server */
+ rspamd_http_stop_servers (sfd);
+ /* No keypairs cache */
+ rspamd_http_start_servers (sfd, addr, serv_key, c);
+
+ //rspamd_mempool_lock_mutex (mtx);
+ usleep (100000);
+ b32_key = rspamd_keypair_print (serv_key,
+ RSPAMD_KEYPAIR_PUBKEY | RSPAMD_KEYPAIR_BASE32);
+ g_assert (b32_key != NULL);
+ peer_key = rspamd_pubkey_from_base32 (b32_key->str, b32_key->len,
+ RSPAMD_KEYPAIR_KEX, RSPAMD_CRYPTOBOX_MODE_NIST);
+ g_assert (peer_key != NULL);
+ total_diff = 0.0;
+
+ gperf_profiler_init (NULL, "cached-http-client-aes");
+ for (i = 0; i < ntests; i++) {
+ for (j = 0; j < pconns; j++) {
+ rspamd_http_client_func (filepath + sizeof ("/tmp") - 1,
+ addr,
+ client_key,
+ peer_key,
+ NULL,
+ ev_base,
+ &latency[i * pconns + j]);
}
- gperf_profiler_stop ();
-
- msg_info (
- "Made %d aes encrypted connections of size %d in %.6f ms, %.6f cps",
- ntests * pconns,
- file_size,
- total_diff,
- ntests * pconns / total_diff * 1000.);
- mean = rspamd_http_calculate_mean (latency, &std);
- msg_info ("Latency: %.6f ms mean, %.6f dev",
- mean, std);
-
- /* Restart server */
- rspamd_http_stop_servers (sfd);
- /* No keypairs cache */
- rspamd_http_start_servers (sfd, addr, serv_key, NULL);
-
- //rspamd_mempool_lock_mutex (mtx);
- usleep (100000);
- total_diff = 0.0;
-
- gperf_profiler_init (NULL, "fair-http-client-aes");
- for (i = 0; i < ntests; i++) {
- for (j = 0; j < pconns; j++) {
- rspamd_http_client_func (filepath + sizeof ("/tmp") - 1,
- addr,
- client_key,
- peer_key,
- c,
- ev_base,
- &latency[i * pconns + j]);
- }
- ts1 = rspamd_get_ticks ();
- event_base_loop (ev_base, 0);
- ts2 = rspamd_get_ticks ();
- diff = (ts2 - ts1) * 1000.0;
- total_diff += diff;
+ ts1 = rspamd_get_ticks ();
+ event_base_loop (ev_base, 0);
+ ts2 = rspamd_get_ticks ();
+ diff = (ts2 - ts1) * 1000.0;
+ total_diff += diff;
+ }
+ gperf_profiler_stop ();
+
+ msg_info (
+ "Made %d aes encrypted connections of size %d in %.6f ms, %.6f cps",
+ ntests * pconns,
+ file_size,
+ total_diff,
+ ntests * pconns / total_diff * 1000.);
+ mean = rspamd_http_calculate_mean (latency, &std);
+ msg_info ("Latency: %.6f ms mean, %.6f dev",
+ mean, std);
+
+ /* Restart server */
+ rspamd_http_stop_servers (sfd);
+ /* No keypairs cache */
+ rspamd_http_start_servers (sfd, addr, serv_key, NULL);
+
+ //rspamd_mempool_lock_mutex (mtx);
+ usleep (100000);
+ total_diff = 0.0;
+
+ gperf_profiler_init (NULL, "fair-http-client-aes");
+ for (i = 0; i < ntests; i++) {
+ for (j = 0; j < pconns; j++) {
+ rspamd_http_client_func (filepath + sizeof ("/tmp") - 1,
+ addr,
+ client_key,
+ peer_key,
+ c,
+ ev_base,
+ &latency[i * pconns + j]);
}
- gperf_profiler_stop ();
-
- msg_info (
- "Made %d uncached aes encrypted connections of size %d in %.6f ms, %.6f cps",
- ntests * pconns,
- file_size,
- total_diff,
- ntests * pconns / total_diff * 1000.);
- mean = rspamd_http_calculate_mean (latency, &std);
- msg_info ("Latency: %.6f ms mean, %.6f dev",
- mean, std);
+ ts1 = rspamd_get_ticks ();
+ event_base_loop (ev_base, 0);
+ ts2 = rspamd_get_ticks ();
+ diff = (ts2 - ts1) * 1000.0;
+ total_diff += diff;
}
+ gperf_profiler_stop ();
+
+ msg_info (
+ "Made %d uncached aes encrypted connections of size %d in %.6f ms, %.6f cps",
+ ntests * pconns,
+ file_size,
+ total_diff,
+ ntests * pconns / total_diff * 1000.);
+ mean = rspamd_http_calculate_mean (latency, &std);
+ msg_info ("Latency: %.6f ms mean, %.6f dev",
+ mean, std);
close (fd);
unlink (filepath);