diff --git a/src/aegis128x2/aegis128x2.c b/src/aegis128x2/aegis128x2.c index dda159d..bd436f5 100644 --- a/src/aegis128x2/aegis128x2.c +++ b/src/aegis128x2/aegis128x2.c @@ -187,10 +187,12 @@ aegis128x2_pick_best_implementation(void) #endif #if defined(__x86_64__) || defined(_M_AMD64) || defined(__i386__) || defined(_M_IX86) +# ifdef HAVE_VAESINTRIN_H if (aegis_runtime_has_vaes() && aegis_runtime_has_avx2()) { implementation = &aegis128x2_avx2_implementation; return 0; } +# endif if (aegis_runtime_has_aesni() && aegis_runtime_has_avx()) { implementation = &aegis128x2_aesni_implementation; return 0; diff --git a/src/aegis128x2/aegis128x2_avx2.c b/src/aegis128x2/aegis128x2_avx2.c index 44af2f6..88bb4b3 100644 --- a/src/aegis128x2/aegis128x2_avx2.c +++ b/src/aegis128x2/aegis128x2_avx2.c @@ -10,26 +10,28 @@ # include "aegis128x2.h" # include "aegis128x2_avx2.h" -# ifdef __clang__ -# pragma clang attribute push(__attribute__((target("vaes,avx2"))), apply_to = function) -# elif defined(__GNUC__) -# pragma GCC target("vaes,avx2") -# endif +# ifdef HAVE_VAESINTRIN_H + +# ifdef __clang__ +# pragma clang attribute push(__attribute__((target("vaes,avx2"))), apply_to = function) +# elif defined(__GNUC__) +# pragma GCC target("vaes,avx2") +# endif -# include +# include -# define AES_BLOCK_LENGTH 32 +# define AES_BLOCK_LENGTH 32 typedef __m256i aes_block_t; -# define AES_BLOCK_XOR(A, B) _mm256_xor_si256((A), (B)) -# define AES_BLOCK_AND(A, B) _mm256_and_si256((A), (B)) -# define AES_BLOCK_LOAD128_BROADCAST(A) \ - _mm256_broadcastsi128_si256(_mm_loadu_si128((const void *) (A))) -# define AES_BLOCK_LOAD(A) _mm256_loadu_si256((const aes_block_t *) (const void *) (A)) -# define AES_BLOCK_LOAD_64x2(A, B) _mm256_broadcastsi128_si256(_mm_set_epi64x((A), (B))) -# define AES_BLOCK_STORE(A, B) _mm256_storeu_si256((aes_block_t *) (void *) (A), (B)) -# define AES_ENC(A, B) _mm256_aesenc_epi128((A), (B)) +# define AES_BLOCK_XOR(A, B) _mm256_xor_si256((A), (B)) +# define AES_BLOCK_AND(A, B) _mm256_and_si256((A), (B)) +# define AES_BLOCK_LOAD128_BROADCAST(A) \ + _mm256_broadcastsi128_si256(_mm_loadu_si128((const void *) (A))) +# define AES_BLOCK_LOAD(A) _mm256_loadu_si256((const aes_block_t *) (const void *) (A)) +# define AES_BLOCK_LOAD_64x2(A, B) _mm256_broadcastsi128_si256(_mm_set_epi64x((A), (B))) +# define AES_BLOCK_STORE(A, B) _mm256_storeu_si256((aes_block_t *) (void *) (A), (B)) +# define AES_ENC(A, B) _mm256_aesenc_epi128((A), (B)) static inline void aegis128x2_update(aes_block_t *const state, const aes_block_t d1, const aes_block_t d2) @@ -50,7 +52,7 @@ aegis128x2_update(aes_block_t *const state, const aes_block_t d1, const aes_bloc state[4] = AES_BLOCK_XOR(state[4], d2); } -# include "aegis128x2_common.h" +# include "aegis128x2_common.h" struct aegis128x2_implementation aegis128x2_avx2_implementation = { .encrypt_detached = encrypt_detached, @@ -66,8 +68,10 @@ struct aegis128x2_implementation aegis128x2_avx2_implementation = { .state_decrypt_detached_final = state_decrypt_detached_final, }; -# ifdef __clang__ -# pragma clang attribute pop +# ifdef __clang__ +# pragma clang attribute pop +# endif + # endif #endif diff --git a/src/aegis128x2/aegis128x2_avx2.h b/src/aegis128x2/aegis128x2_avx2.h index cdc18b8..6567b92 100644 --- a/src/aegis128x2/aegis128x2_avx2.h +++ b/src/aegis128x2/aegis128x2_avx2.h @@ -4,6 +4,8 @@ #include "../common/common.h" #include "implementations.h" +#ifdef HAVE_VAESINTRIN_H extern struct aegis128x2_implementation aegis128x2_avx2_implementation; +#endif #endif \ No newline at end of file diff --git a/src/aegis128x4/aegis128x4.c b/src/aegis128x4/aegis128x4.c index c68c356..da30d14 100644 --- a/src/aegis128x4/aegis128x4.c +++ b/src/aegis128x4/aegis128x4.c @@ -193,11 +193,11 @@ aegis128x4_pick_best_implementation(void) implementation = &aegis128x4_avx512_implementation; return 0; } -# endif if (aegis_runtime_has_vaes() && aegis_runtime_has_avx2()) { implementation = &aegis128x4_avx2_implementation; return 0; } +# endif if (aegis_runtime_has_aesni() && aegis_runtime_has_avx()) { implementation = &aegis128x4_aesni_implementation; return 0; diff --git a/src/aegis128x4/aegis128x4_avx2.c b/src/aegis128x4/aegis128x4_avx2.c index f704a4b..aa54fba 100644 --- a/src/aegis128x4/aegis128x4_avx2.c +++ b/src/aegis128x4/aegis128x4_avx2.c @@ -10,15 +10,17 @@ # include "aegis128x4.h" # include "aegis128x4_avx2.h" -# ifdef __clang__ -# pragma clang attribute push(__attribute__((target("vaes,avx2"))), apply_to = function) -# elif defined(__GNUC__) -# pragma GCC target("vaes,avx2") -# endif +# ifdef HAVE_VAESINTRIN_H + +# ifdef __clang__ +# pragma clang attribute push(__attribute__((target("vaes,avx2"))), apply_to = function) +# elif defined(__GNUC__) +# pragma GCC target("vaes,avx2") +# endif -# include +# include -# define AES_BLOCK_LENGTH 64 +# define AES_BLOCK_LENGTH 64 typedef struct { __m256i b0; @@ -83,7 +85,7 @@ aegis128x4_update(aes_block_t *const state, const aes_block_t d1, const aes_bloc state[4] = AES_BLOCK_XOR(state[4], d2); } -# include "aegis128x4_common.h" +# include "aegis128x4_common.h" struct aegis128x4_implementation aegis128x4_avx2_implementation = { .encrypt_detached = encrypt_detached, @@ -99,8 +101,10 @@ struct aegis128x4_implementation aegis128x4_avx2_implementation = { .state_decrypt_detached_final = state_decrypt_detached_final, }; -# ifdef __clang__ -# pragma clang attribute pop +# ifdef __clang__ +# pragma clang attribute pop +# endif + # endif -#endif +#endif \ No newline at end of file diff --git a/src/aegis128x4/aegis128x4_avx2.h b/src/aegis128x4/aegis128x4_avx2.h index bd99052..62ca093 100644 --- a/src/aegis128x4/aegis128x4_avx2.h +++ b/src/aegis128x4/aegis128x4_avx2.h @@ -4,6 +4,8 @@ #include "../common/common.h" #include "implementations.h" +#ifdef HAVE_VAESINTRIN_H extern struct aegis128x4_implementation aegis128x4_avx2_implementation; +#endif #endif \ No newline at end of file diff --git a/src/aegis256x2/aegis256x2.c b/src/aegis256x2/aegis256x2.c index 787b7e9..98b6960 100644 --- a/src/aegis256x2/aegis256x2.c +++ b/src/aegis256x2/aegis256x2.c @@ -187,10 +187,12 @@ aegis256x2_pick_best_implementation(void) #endif #if defined(__x86_64__) || defined(_M_AMD64) || defined(__i386__) || defined(_M_IX86) +# ifdef HAVE_VAESINTRIN_H if (aegis_runtime_has_vaes() && aegis_runtime_has_avx2()) { implementation = &aegis256x2_avx2_implementation; return 0; } +# endif if (aegis_runtime_has_aesni() && aegis_runtime_has_avx()) { implementation = &aegis256x2_aesni_implementation; return 0; diff --git a/src/aegis256x2/aegis256x2_avx2.c b/src/aegis256x2/aegis256x2_avx2.c index ed8aa13..c17ce5c 100644 --- a/src/aegis256x2/aegis256x2_avx2.c +++ b/src/aegis256x2/aegis256x2_avx2.c @@ -10,26 +10,28 @@ # include "aegis256x2.h" # include "aegis256x2_avx2.h" -# ifdef __clang__ -# pragma clang attribute push(__attribute__((target("vaes,avx2"))), apply_to = function) -# elif defined(__GNUC__) -# pragma GCC target("vaes,avx2") -# endif +# ifdef HAVE_VAESINTRIN_H + +# ifdef __clang__ +# pragma clang attribute push(__attribute__((target("vaes,avx2"))), apply_to = function) +# elif defined(__GNUC__) +# pragma GCC target("vaes,avx2") +# endif -# include +# include -# define AES_BLOCK_LENGTH 32 +# define AES_BLOCK_LENGTH 32 typedef __m256i aes_block_t; -# define AES_BLOCK_XOR(A, B) _mm256_xor_si256((A), (B)) -# define AES_BLOCK_AND(A, B) _mm256_and_si256((A), (B)) -# define AES_BLOCK_LOAD128_BROADCAST(A) \ - _mm256_broadcastsi128_si256(_mm_loadu_si128((const void *) (A))) -# define AES_BLOCK_LOAD(A) _mm256_loadu_si256((const aes_block_t *) (const void *) (A)) -# define AES_BLOCK_LOAD_64x2(A, B) _mm256_broadcastsi128_si256(_mm_set_epi64x((A), (B))) -# define AES_BLOCK_STORE(A, B) _mm256_storeu_si256((aes_block_t *) (void *) (A), (B)) -# define AES_ENC(A, B) _mm256_aesenc_epi128((A), (B)) +# define AES_BLOCK_XOR(A, B) _mm256_xor_si256((A), (B)) +# define AES_BLOCK_AND(A, B) _mm256_and_si256((A), (B)) +# define AES_BLOCK_LOAD128_BROADCAST(A) \ + _mm256_broadcastsi128_si256(_mm_loadu_si128((const void *) (A))) +# define AES_BLOCK_LOAD(A) _mm256_loadu_si256((const aes_block_t *) (const void *) (A)) +# define AES_BLOCK_LOAD_64x2(A, B) _mm256_broadcastsi128_si256(_mm_set_epi64x((A), (B))) +# define AES_BLOCK_STORE(A, B) _mm256_storeu_si256((aes_block_t *) (void *) (A), (B)) +# define AES_ENC(A, B) _mm256_aesenc_epi128((A), (B)) static inline void aegis256x2_update(aes_block_t *const state, const aes_block_t d) @@ -45,7 +47,7 @@ aegis256x2_update(aes_block_t *const state, const aes_block_t d) state[0] = AES_BLOCK_XOR(AES_ENC(tmp, state[0]), d); } -# include "aegis256x2_common.h" +# include "aegis256x2_common.h" struct aegis256x2_implementation aegis256x2_avx2_implementation = { .encrypt_detached = encrypt_detached, @@ -61,8 +63,10 @@ struct aegis256x2_implementation aegis256x2_avx2_implementation = { .state_decrypt_detached_final = state_decrypt_detached_final, }; -# ifdef __clang__ -# pragma clang attribute pop +# ifdef __clang__ +# pragma clang attribute pop +# endif + # endif -#endif +#endif \ No newline at end of file diff --git a/src/aegis256x2/aegis256x2_avx2.h b/src/aegis256x2/aegis256x2_avx2.h index 223095a..ec78360 100644 --- a/src/aegis256x2/aegis256x2_avx2.h +++ b/src/aegis256x2/aegis256x2_avx2.h @@ -4,6 +4,8 @@ #include "../common/common.h" #include "implementations.h" +#ifdef HAVE_VAESINTRIN_H extern struct aegis256x2_implementation aegis256x2_avx2_implementation; +#endif #endif \ No newline at end of file diff --git a/src/aegis256x4/aegis256x4.c b/src/aegis256x4/aegis256x4.c index f11f9c4..2c8dea7 100644 --- a/src/aegis256x4/aegis256x4.c +++ b/src/aegis256x4/aegis256x4.c @@ -193,11 +193,11 @@ aegis256x4_pick_best_implementation(void) implementation = &aegis256x4_avx512_implementation; return 0; } -# endif if (aegis_runtime_has_vaes() && aegis_runtime_has_avx2()) { implementation = &aegis256x4_avx2_implementation; return 0; } +# endif if (aegis_runtime_has_aesni() && aegis_runtime_has_avx()) { implementation = &aegis256x4_aesni_implementation; return 0; diff --git a/src/aegis256x4/aegis256x4_avx2.c b/src/aegis256x4/aegis256x4_avx2.c index 404fcda..a1bd5ba 100644 --- a/src/aegis256x4/aegis256x4_avx2.c +++ b/src/aegis256x4/aegis256x4_avx2.c @@ -10,15 +10,17 @@ # include "aegis256x4.h" # include "aegis256x4_avx2.h" -# ifdef __clang__ -# pragma clang attribute push(__attribute__((target("vaes,avx2"))), apply_to = function) -# elif defined(__GNUC__) -# pragma GCC target("vaes,avx2") -# endif +# ifdef HAVE_VAESINTRIN_H + +# ifdef __clang__ +# pragma clang attribute push(__attribute__((target("vaes,avx2"))), apply_to = function) +# elif defined(__GNUC__) +# pragma GCC target("vaes,avx2") +# endif -# include +# include -# define AES_BLOCK_LENGTH 64 +# define AES_BLOCK_LENGTH 64 typedef struct { __m256i b0; @@ -78,7 +80,7 @@ aegis256x4_update(aes_block_t *const state, const aes_block_t d) state[0] = AES_BLOCK_XOR(AES_ENC(tmp, state[0]), d); } -# include "aegis256x4_common.h" +# include "aegis256x4_common.h" struct aegis256x4_implementation aegis256x4_avx2_implementation = { .encrypt_detached = encrypt_detached, @@ -94,8 +96,10 @@ struct aegis256x4_implementation aegis256x4_avx2_implementation = { .state_decrypt_detached_final = state_decrypt_detached_final, }; -# ifdef __clang__ -# pragma clang attribute pop +# ifdef __clang__ +# pragma clang attribute pop +# endif + # endif #endif \ No newline at end of file diff --git a/src/aegis256x4/aegis256x4_avx2.h b/src/aegis256x4/aegis256x4_avx2.h index 31a16b8..e46700c 100644 --- a/src/aegis256x4/aegis256x4_avx2.h +++ b/src/aegis256x4/aegis256x4_avx2.h @@ -4,6 +4,8 @@ #include "../common/common.h" #include "implementations.h" +#ifdef HAVE_VAESINTRIN_H extern struct aegis256x4_implementation aegis256x4_avx2_implementation; +#endif #endif \ No newline at end of file