From 544fea1f9f6e29eda29a616bbafd47b908ad7b6f Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Sun, 8 Feb 2015 22:27:04 +0000 Subject: [PATCH] Unify align macro. --- config.h.in | 8 ++++++++ contrib/blake2/blake2.h | 6 ++++-- src/libcryptobox/cryptobox.c | 10 +++++----- test/rspamd_http_test.c | 2 +- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/config.h.in b/config.h.in index c1e819fb2..e45f95f4c 100644 --- a/config.h.in +++ b/config.h.in @@ -472,6 +472,14 @@ typedef off_t goffset; #include #endif +#ifndef ALIGN +#if defined(_MSC_VER) +# define ALIGN(x) __declspec(align(x)) +#else +# define ALIGN(x) __attribute__((aligned(x))) +#endif +#endif + /* Forwarded declaration */ struct module_ctx; struct rspamd_config; diff --git a/contrib/blake2/blake2.h b/contrib/blake2/blake2.h index 433c429e0..b0c852284 100644 --- a/contrib/blake2/blake2.h +++ b/contrib/blake2/blake2.h @@ -17,10 +17,12 @@ #include #include +#ifndef ALIGN #if defined(_MSC_VER) -#define ALIGN(x) __declspec(align(x)) +# define ALIGN(x) __declspec(align(x)) #else -#define ALIGN(x) __attribute__((aligned(x))) +# define ALIGN(x) __attribute__((aligned(x))) +#endif #endif #if defined(__cplusplus) diff --git a/src/libcryptobox/cryptobox.c b/src/libcryptobox/cryptobox.c index da43a137c..ecc3b5cfc 100644 --- a/src/libcryptobox/cryptobox.c +++ b/src/libcryptobox/cryptobox.c @@ -141,8 +141,8 @@ void rspamd_cryptobox_encrypt_nm_inplace (guchar *data, gsize len, const rspamd_nm_t nm, rspamd_sig_t sig) { poly1305_state mac_ctx; - guchar subkey[CHACHA_BLOCKBYTES]; - chacha_state s; + ALIGN(64) guchar subkey[CHACHA_BLOCKBYTES]; + ALIGN(64) chacha_state s; gsize r; xchacha_init (&s, (const chacha_key *)nm, (const chacha_iv24 *)nonce, 20); @@ -164,10 +164,10 @@ gboolean rspamd_cryptobox_decrypt_nm_inplace (guchar *data, gsize len, const rspamd_nonce_t nonce, const rspamd_nm_t nm, const rspamd_sig_t sig) { - poly1305_state mac_ctx; - guchar subkey[CHACHA_BLOCKBYTES]; + ALIGN(64) poly1305_state mac_ctx; + ALIGN(64) guchar subkey[CHACHA_BLOCKBYTES]; rspamd_sig_t mac; - chacha_state s; + ALIGN(64) chacha_state s; gsize r; gboolean ret = TRUE; diff --git a/test/rspamd_http_test.c b/test/rspamd_http_test.c index 94a12ee81..581a4c284 100644 --- a/test/rspamd_http_test.c +++ b/test/rspamd_http_test.c @@ -30,7 +30,7 @@ static const int file_blocks = 8; static const int pconns = 100; -static const int ntests = 100; +static const int ntests = 300; static void rspamd_server_error (struct rspamd_http_connection_entry *conn_ent, -- 2.39.5