Add linux runtime detection
Signed-off-by: Jerry Yu <jerry.h.yu@arm.com>
diff --git a/library/aesce.c b/library/aesce.c
index 608e5e3..f33d593 100644
--- a/library/aesce.c
+++ b/library/aesce.c
@@ -45,6 +45,26 @@
#include <arm_neon.h>
+#if defined(__linux__)
+#include <asm/hwcap.h>
+#include <sys/auxv.h>
+#endif
+
+/*
+ * AES instruction support detection routine
+ */
+int mbedtls_aesce_has_support(void)
+{
+#if defined(__linux__)
+ unsigned long auxval = getauxval(AT_HWCAP);
+ return (auxval & (HWCAP_ASIMD | HWCAP_AES)) ==
+ (HWCAP_ASIMD | HWCAP_AES);
+#else
+ /* Suppose aes instructions are supported. */
+ return 1;
+#endif
+}
+
#endif /* MBEDTLS_HAVE_ARM64 */
#endif /* MBEDTLS_AESCE_C */
diff --git a/library/aesce.h b/library/aesce.h
index 4968fed..2d5dde9 100644
--- a/library/aesce.h
+++ b/library/aesce.h
@@ -31,8 +31,8 @@
#include "mbedtls/aes.h"
-#if !defined(MBEDTLS_HAVE_ARM64) && \
- (defined(__aarch64__) || defined(_M_ARM64))
+#if defined(MBEDTLS_HAVE_ASM) && defined(__GNUC__) && \
+ defined(__aarch64__) && !defined(MBEDTLS_HAVE_ARM64)
#define MBEDTLS_HAVE_ARM64
#endif
@@ -41,6 +41,14 @@
#ifdef __cplusplus
extern "C" {
#endif
+
+/**
+ * \brief Internal function to detect the crypto engine in CPUs.
+ *
+ * \return 1 if CPU has support for the feature, 0 otherwise
+ */
+int mbedtls_aesce_has_support(void);
+
#ifdef __cplusplus
}
#endif