Skip to content

Commit 6eb368b

Browse files
committed
gcc and clang compiler version checks refined and msvc guards added
1 parent b312844 commit 6eb368b

3 files changed

Lines changed: 45 additions & 17 deletions

File tree

crypto/aes/aes_ctr_vaes_intrinsic.c

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717

1818
#if defined(__x86_64__) || defined(__x86_64) || defined(_M_AMD64) || defined(_M_X64)
1919

20-
#if ((defined(__GNUC__) && !defined(__clang__) && (__GNUC__ >= 10)) || (defined(__clang__) && (__clang_major__ >= 11)))
20+
#if ((defined(__GNUC__) && !defined(__clang__) && (__GNUC__ >= 8)) \
21+
|| (defined(__clang__) && (__clang_major__ >= 7)) || (defined(_MSC_VER) && (_MSC_VER >= 1927)))
2122

2223
#include <openssl/modes.h>
2324

@@ -32,23 +33,41 @@ int ossl_aes_ctr_vaes_eligible(void);
3233
void aesni_encrypt(const unsigned char *in, unsigned char *out, const AES_KEY *key);
3334

3435
/* Portable compiler abstractions for inlining and ISA target selection */
35-
#if defined(__GNUC__) || defined(__clang__) /* GCC, Clang, and clang-cl */
36-
#define OSSL_FUNC_ALWAYS_INLINE __attribute__((always_inline))
37-
#define OSSL_FUNC_NOINLINE __attribute__((noinline))
38-
#if defined(__GNUC__) && !defined(__clang__) && (__GNUC__ >= 10)
39-
#pragma GCC target("avx512f,avx512dq,avx512bw,vaes,aes")
36+
#define STRINGIFY_IMPL_(a) #a
37+
#define STRINGIFY_(a) STRINGIFY_IMPL_(a)
38+
39+
#ifdef __clang__
40+
# define OPENSSL_TARGET_VAES512 \
41+
_Pragma(STRINGIFY_(clang attribute push( \
42+
__attribute__((target("avx512f,avx512dq,avx512bw,vaes,aes"))), \
43+
apply_to = function)))
44+
# define OPENSSL_UNTARGET_VAES512 _Pragma("clang attribute pop")
45+
#elif defined(__GNUC__)
46+
# define OPENSSL_TARGET_VAES512 \
47+
_Pragma("GCC push_options") \
48+
_Pragma(STRINGIFY_(GCC target("avx512f,avx512dq,avx512bw,vaes,aes")))
49+
# define OPENSSL_UNTARGET_VAES512 _Pragma("GCC pop_options")
50+
#else
51+
/* MSVC: all intrinsics are always available via <immintrin.h>. */
52+
# define OPENSSL_TARGET_VAES512
53+
# define OPENSSL_UNTARGET_VAES512
4054
#endif
41-
/* GCC/Clang require this pragma to make AVX-512/VAES intrinsics available.
42-
* MSVC does not need it: all intrinsics are always declared in <immintrin.h>. */
43-
#elif defined(_MSC_VER) /* MSVC */
44-
#define OSSL_FUNC_ALWAYS_INLINE __forceinline
45-
#define OSSL_FUNC_NOINLINE __declspec(noinline)
46-
#else /* Other compilers */
47-
#define OSSL_FUNC_ALWAYS_INLINE
48-
#define OSSL_FUNC_NOINLINE
55+
56+
#if defined(__GNUC__) || defined(__clang__)
57+
# define OSSL_FUNC_ALWAYS_INLINE __attribute__((always_inline))
58+
# define OSSL_FUNC_NOINLINE __attribute__((noinline))
59+
#elif defined(_MSC_VER)
60+
# define OSSL_FUNC_ALWAYS_INLINE __forceinline
61+
# define OSSL_FUNC_NOINLINE __declspec(noinline)
62+
#else
63+
# define OSSL_FUNC_ALWAYS_INLINE
64+
# define OSSL_FUNC_NOINLINE
4965
#endif
66+
5067
#include <immintrin.h>
5168

69+
OPENSSL_TARGET_VAES512
70+
5271
#define AES_BLOCK_SIZE 16
5372

5473
/* ------------------------------------------------------------------ */
@@ -413,8 +432,13 @@ int ossl_aes_ctr_vaes_eligible(void)
413432
&& (OPENSSL_ia32cap_P[3] & (1 << 9)); /* AVX512VAES */
414433
}
415434

435+
OPENSSL_UNTARGET_VAES512
436+
437+
#undef OPENSSL_TARGET_VAES512
438+
#undef OPENSSL_UNTARGET_VAES512
439+
#undef STRINGIFY_IMPL_
440+
#undef STRINGIFY_
416441
#undef OSSL_FUNC_ALWAYS_INLINE
417442
#undef OSSL_FUNC_NOINLINE
418-
419-
#endif /* compiler version guard */
443+
#endif /* GCC >= 8 || Clang >= 7 || MSVC */
420444
#endif /* __x86_64__ || _M_AMD64 */

include/crypto/aes_platform.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,13 +204,16 @@ void ossl_aes_cfb128_vaes_enc(const unsigned char *in, unsigned char *out,
204204
void ossl_aes_cfb128_vaes_dec(const unsigned char *in, unsigned char *out,
205205
size_t len, const AES_KEY *ks,
206206
const unsigned char ivec[16], ossl_ssize_t *num);
207+
#if ((defined(__GNUC__) && !defined(__clang__) && (__GNUC__ >= 8)) \
208+
|| (defined(__clang__) && (__clang_major__ >= 7)) || (defined(_MSC_VER) && (_MSC_VER >= 1927)))
207209

208210
void ossl_aes_ctr_vaes(const unsigned char *in, unsigned char *out,
209211
size_t length, const AES_KEY *key,
210212
unsigned char *counter,
211213
unsigned char *ecount_buf, unsigned int *num);
212214
int ossl_aes_ctr_vaes_eligible(void);
213215

216+
#endif
214217
int ossl_aes_cfb128_vaes_eligible(void);
215218

216219
void aesni_encrypt(const unsigned char *in, unsigned char *out,

providers/implementations/ciphers/cipher_aes_hw_aesni.inc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
#define cipher_hw_aesni_ofb128 ossl_cipher_hw_generic_ofb128
1616

1717
#if !(defined(__x86_64) || defined(__x86_64__) || defined(_M_AMD64) || defined(_M_X64)) \
18-
|| (!((defined(__GNUC__) && !defined(__clang__) && (__GNUC__ >= 10)) || (defined(__clang__) && (__clang_major__ >= 11))))
18+
|| (!((defined(__GNUC__) && !defined(__clang__) && (__GNUC__ >= 8)) || (defined(__clang__) && (__clang_major__ >= 7)) || (defined(_MSC_VER) && (_MSC_VER >= 1927))))
1919
#define cipher_hw_vaes_ctr ossl_cipher_hw_generic_ctr
20+
#define cipher_hw_aesni_ctr ossl_cipher_hw_generic_ctr
2021
#else
2122

2223
/* active in 64-bit builds when AES-NI, AVX512F, and VAES are detected */

0 commit comments

Comments
 (0)