Use __has_attribute() for target attribute.

... and bring aarch64/PMULL in similar shape as x86/PCLMUL.

Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
This commit is contained in:
Steffen Jaeckel 2026-05-04 10:03:16 +02:00
parent 42489a16cb
commit c05b3088b4
4 changed files with 23 additions and 9 deletions

View file

@ -71,6 +71,7 @@ sub check_source {
my $n = $1;
push @{$troubles->{invalid_macro_name}}, "$lineno($n)"
unless ($file eq 'src/headers/tomcrypt_cfg.h' && $n eq '__has_builtin') ||
($file eq 'src/headers/tomcrypt_cfg.h' && $n eq '__has_attribute') ||
($file eq 'src/headers/tomcrypt_cfg.h' && $n eq '_WIN32_WINNT') ||
($file eq 'src/prngs/rng_get_bytes.c' && $n eq '_WIN32_WINNT');
}

View file

@ -10,7 +10,7 @@
#if defined(LTC_GCM_MODE) || defined(LTC_LRW_MODE)
#if defined(LTC_GCM_PCLMUL)
#define LTC_GCM_PCLMUL_TARGET LTC_ATTRIBUTE((__target__("pclmul,ssse3")))
#define LTC_GCM_PCLMUL_TARGET LTC_TARGET("pclmul,ssse3")
#if defined(__GNUC__)
#pragma GCC diagnostic push
@ -135,6 +135,9 @@ static void s_gcm_gf_mult_pclmul(const unsigned char *a, const unsigned char *b,
#endif /* defined(LTC_GCM_PCLMUL) */
#if defined(LTC_GCM_PMULL)
#define LTC_GCM_PMULL_TARGET LTC_TARGET("+crypto")
#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wbad-function-cast"

View file

@ -339,6 +339,14 @@ typedef unsigned long ltc_mp_digit;
#endif
#endif
#if defined(__aarch64__) || defined(_M_ARM64)
#define LTC_ARCH_AARCH64
#if !defined(LTC_NO_GCM_PMULL)
#define LTC_GCM_PMULL
#undef LTC_GCM_TABLES
#endif
#endif
#if defined(__GNUC__)
#define LTC_ALIGN_MSVC(n)
#define LTC_ALIGN(n) __attribute__((aligned(n)))
@ -395,21 +403,20 @@ typedef unsigned long ltc_mp_digit;
#endif
#endif
#ifndef __has_attribute
# define __has_attribute(x) 0
#endif
#if defined(__GNUC__) || defined(__clang__)
# define LTC_ATTRIBUTE(x) __attribute__(x)
#else
# define LTC_ATTRIBUTE(x)
#endif
#if !defined(LTC_NO_GCM_PMULL) && (defined(__aarch64__) || defined(_M_ARM64))
#define LTC_GCM_PMULL
#undef LTC_GCM_TABLES
#if __has_attribute(target)
# define LTC_TARGET(x) LTC_ATTRIBUTE((target(x)))
#endif
#if defined(LTC_GCM_PMULL) && (defined(__clang__) || defined(__GNUC__))
#define LTC_GCM_PMULL_TARGET __attribute__((target("+crypto")))
#else
#define LTC_GCM_PMULL_TARGET
#ifndef LTC_TARGET
# define LTC_TARGET(x)
#endif
#endif /* TOMCRYPT_CFG_H */

View file

@ -438,6 +438,9 @@ const char *crypt_build_settings =
#if defined(LTC_ARCH_X86)
" LTC_ARCH_X86\n"
#endif
#if defined(LTC_ARCH_AARCH64)
" LTC_ARCH_AARCH64\n"
#endif
"\nVarious others: "
#if defined(ARGTYPE)