Skip to content

Commit

Permalink
Aarch64: make code compile when no hardware crypto avail
Browse files Browse the repository at this point in the history
Detects availability of instructions for Aarch64.
  • Loading branch information
SparkiDev committed Dec 16, 2024
1 parent 9bec6da commit 585540b
Show file tree
Hide file tree
Showing 9 changed files with 1,709 additions and 710 deletions.
2 changes: 2 additions & 0 deletions .wolfssl_known_macro_extras
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,7 @@ WOLFCRYPT_FIPS_CORE_DYNAMIC_HASH_VALUE
WOLFSENTRY_H
WOLFSENTRY_NO_JSON
WOLFSSL_32BIT_MILLI_TIME
WOLFSSL_AARCH64_PRIVILEGE_MODE
WOLFSSL_AESNI_BY4
WOLFSSL_AESNI_BY6
WOLFSSL_AFTER_DATE_CLOCK_SKEW
Expand Down Expand Up @@ -906,6 +907,7 @@ __MINGW32__
__MINGW64_VERSION_MAJOR
__MINGW64__
__MWERKS__
__OpenBSD__
__PIE__
__POWERPC__
__PPC__
Expand Down
11 changes: 10 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2950,6 +2950,7 @@ then
fi


ENABLED_ARMASM_CRYPTO="unknown"
ENABLED_ARMASM_INLINE="no"
ENABLED_ARMASM_SHA3="no"
ENABLED_ARMASM_CRYPTO_SM4="no"
Expand All @@ -2971,6 +2972,9 @@ then
inline)
ENABLED_ARMASM_INLINE=yes
;;
no-crypto)
ENABLED_ARMASM_CRYPTO=no
;;
sha512-crypto | sha3-crypto)
case $host_cpu in
*aarch64*)
Expand Down Expand Up @@ -3046,7 +3050,9 @@ then
esac
# Include options.h
AM_CCASFLAGS="$AM_CCASFLAGS -DEXTERNAL_OPTS_OPENVPN"
ENABLED_ARMASM_CRYPTO=yes
if test "$ENABLED_ARMASM_CRYPTO" = "unknown"; then
ENABLED_ARMASM_CRYPTO=yes
fi
ENABLED_ARMASM_NEON=yes
ENABLED_ARM_64=yes

Expand Down Expand Up @@ -3147,6 +3153,9 @@ fi
if test "$ENABLED_ARMASM_SM4" = "yes"; then
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_ARMASM_CRYPTO_SM4"
fi
if test "$ENABLED_ARMASM_CRYPTO" = "unknown"; then
ENABLED_ARMASM_CRYPTO=no
fi
if test "$ENABLED_ARMASM_CRYPTO" = "no"; then
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_ARMASM_NO_HW_CRYPTO"
fi
Expand Down
46 changes: 46 additions & 0 deletions wolfcrypt/benchmark/benchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@
#include <wolfssl/wolfcrypt/async.h>
#endif

#include <wolfssl/wolfcrypt/cpuid.h>

#ifdef USE_FLAT_BENCHMARK_H
#include "benchmark.h"
#else
Expand Down Expand Up @@ -3939,6 +3941,46 @@ static void* benchmarks_do(void* args)
return NULL;
}

#if defined(HAVE_CPUID) && defined(WOLFSSL_TEST_STATIC_BUILD)
static void print_cpu_features(void)
{
word32 cpuid_flags = cpuid_get_flags();

printf("CPU: ");
#ifdef HAVE_CPUID_INTEL
printf("Intel");
#ifdef WOLFSSL_X86_64_BUILD
printf(" x86_64");
#else
printf(" x86");
#endif
printf(" -");
if (IS_INTEL_AVX1(cpuid_flags)) printf(" avx1");
if (IS_INTEL_AVX2(cpuid_flags)) printf(" avx2");
if (IS_INTEL_RDRAND(cpuid_flags)) printf(" rdrand");
if (IS_INTEL_RDSEED(cpuid_flags)) printf(" rdseed");
if (IS_INTEL_BMI2(cpuid_flags)) printf(" bmi2");
if (IS_INTEL_AESNI(cpuid_flags)) printf(" aesni");
if (IS_INTEL_ADX(cpuid_flags)) printf(" adx");
if (IS_INTEL_MOVBE(cpuid_flags)) printf(" movbe");
if (IS_INTEL_BMI1(cpuid_flags)) printf(" bmi1");
if (IS_INTEL_SHA(cpuid_flags)) printf(" sha");
#endif
#ifdef __aarch64__
printf("Aarch64 -");
if (IS_AARCH64_AES(cpuid_flags)) printf(" aes");
if (IS_AARCH64_PMULL(cpuid_flags)) printf(" pmull");
if (IS_AARCH64_SHA256(cpuid_flags)) printf(" sha256");
if (IS_AARCH64_SHA512(cpuid_flags)) printf(" sha512");
if (IS_AARCH64_RDM(cpuid_flags)) printf(" rdm");
if (IS_AARCH64_SHA3(cpuid_flags)) printf(" sha3");
if (IS_AARCH64_SM3(cpuid_flags)) printf(" sm3");
if (IS_AARCH64_SM4(cpuid_flags)) printf(" sm4");
#endif
printf("\n");
}
#endif

int benchmark_init(void)
{
int ret = 0;
Expand All @@ -3959,6 +4001,10 @@ int benchmark_init(void)
return EXIT_FAILURE;
}

#if defined(HAVE_CPUID) && defined(WOLFSSL_TEST_STATIC_BUILD)
print_cpu_features();
#endif

#ifdef HAVE_WC_INTROSPECTION
printf("Math: %s\n", wc_GetMathInfo());
#endif
Expand Down
Loading

0 comments on commit 585540b

Please sign in to comment.