armcap: fix Mac M1 SHA512 support.
authorDavid CARLIER <devnexen@gmail.com>
Mon, 19 Apr 2021 20:26:50 +0000 (21:26 +0100)
committerTomas Mraz <tomas@openssl.org>
Tue, 11 May 2021 08:00:27 +0000 (10:00 +0200)
The SIGILL catch/trap works however disabled purposely for Darwin,
 thus relying on native api instead.

Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14935)

crypto/armcap.c

index dc2326f8f6573d54cdef688530db3718b8ef0877..28cadfbb2ecec8fd3f0bff6a33be79408dfa2ca9 100644 (file)
@@ -13,6 +13,9 @@
 #include <setjmp.h>
 #include <signal.h>
 #include <openssl/crypto.h>
+#ifdef __APPLE__
+#include <sys/sysctl.h>
+#endif
 #include "internal/cryptlib.h"
 
 #include "arm_arch.h"
@@ -135,7 +138,8 @@ void OPENSSL_cpuid_setup(void)
         return;
     }
 
-# if defined(__APPLE__) && !defined(__aarch64__)
+# if defined(__APPLE__)
+#   if !defined(__aarch64__)
     /*
      * Capability probing by catching SIGILL appears to be problematic
      * on iOS. But since Apple universe is "monocultural", it's actually
@@ -151,6 +155,15 @@ void OPENSSL_cpuid_setup(void)
      * Unified code works because it never triggers SIGILL on Apple
      * devices...
      */
+#   else
+    {
+        unsigned int sha512;
+        size_t len = sizeof(sha512);
+
+        if (sysctlbyname("hw.optional.armv8_2_sha512", &sha512, &len, NULL, 0) == 0 && sha512 == 1)
+            OPENSSL_armcap_P |= ARMV8_SHA512;
+    }
+#   endif
 # endif
 
     OPENSSL_armcap_P = 0;