aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/utils
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2018-01-09 10:08:08 -0500
committerJack Lloyd <[email protected]>2018-01-09 10:08:08 -0500
commit7eb7f80ab2cd2e9e087a7bc31af341926f6b509a (patch)
treeb24821f919b86556e67e907dddf1999d5062f806 /src/lib/utils
parent92749094c285d14a683b490042d79a960991490c (diff)
parent198775271eccdf8e197d2dce4cf9a3d99a6f9bbe (diff)
Merge GH #1393 Add cpuid support for POWER crypto extensions
Diffstat (limited to 'src/lib/utils')
-rw-r--r--src/lib/utils/cpuid/cpuid.cpp1
-rw-r--r--src/lib/utils/cpuid/cpuid.h10
-rw-r--r--src/lib/utils/cpuid/cpuid_ppc.cpp24
3 files changed, 34 insertions, 1 deletions
diff --git a/src/lib/utils/cpuid/cpuid.cpp b/src/lib/utils/cpuid/cpuid.cpp
index d4e15c16b..1638ab6c5 100644
--- a/src/lib/utils/cpuid/cpuid.cpp
+++ b/src/lib/utils/cpuid/cpuid.cpp
@@ -58,6 +58,7 @@ std::string CPUID::to_string()
#if defined(BOTAN_TARGET_CPU_IS_PPC_FAMILY)
CPUID_PRINT(altivec);
+ CPUID_PRINT(ppc_crypto);
#endif
#if defined(BOTAN_TARGET_CPU_IS_ARM_FAMILY)
diff --git a/src/lib/utils/cpuid/cpuid.h b/src/lib/utils/cpuid/cpuid.h
index f9186f918..f37063a99 100644
--- a/src/lib/utils/cpuid/cpuid.h
+++ b/src/lib/utils/cpuid/cpuid.h
@@ -108,7 +108,8 @@ class BOTAN_PUBLIC_API(2,1) CPUID final
#endif
#if defined(BOTAN_TARGET_CPU_IS_PPC_FAMILY)
- CPUID_ALTIVEC_BIT = (1ULL << 0),
+ CPUID_ALTIVEC_BIT = (1ULL << 0),
+ CPUID_PPC_CRYPTO_BIT = (1ULL << 1),
#endif
#if defined(BOTAN_TARGET_CPU_IS_ARM_FAMILY)
@@ -128,6 +129,13 @@ class BOTAN_PUBLIC_API(2,1) CPUID final
*/
static bool has_altivec()
{ return has_cpuid_bit(CPUID_ALTIVEC_BIT); }
+
+ /**
+ * Check if the processor supports POWER8 crypto extensions
+ */
+ static bool has_ppc_crypto()
+ { return has_cpuid_bit(CPUID_PPC_CRYPTO_BIT); }
+
#endif
#if defined(BOTAN_TARGET_CPU_IS_ARM_FAMILY)
diff --git a/src/lib/utils/cpuid/cpuid_ppc.cpp b/src/lib/utils/cpuid/cpuid_ppc.cpp
index 750cf3a47..d73912b86 100644
--- a/src/lib/utils/cpuid/cpuid_ppc.cpp
+++ b/src/lib/utils/cpuid/cpuid_ppc.cpp
@@ -19,6 +19,8 @@
#include <sys/param.h>
#include <sys/sysctl.h>
#include <machine/cpu.h>
+#elif defined(BOTAN_TARGET_OS_HAS_GETAUXVAL)
+ #include <sys/auxv.h>
#endif
#endif
@@ -51,6 +53,28 @@ uint64_t CPUID::detect_cpu_features(size_t* cache_line_size)
if(error == 0 && vector_type > 0)
return CPUID::CPUID_ALTIVEC_BIT;
+#elif defined(BOTAN_TARGET_OS_HAS_GETAUXVAL) && defined(BOTAN_TARGET_ARCH_IS_PPC64)
+
+ enum PPC_hwcap_bit {
+ ALTIVEC_bit = (1 << 28),
+ CRYPTO_bit = (1 << 25),
+
+ ARCH_hwcap_altivec = 16, // AT_HWCAP
+ ARCH_hwcap_crypto = 26, // AT_HWCAP2
+ };
+
+ uint64_t detected_features = 0;
+
+ const unsigned long hwcap_altivec = ::getauxval(PPC_hwcap_bit::ARCH_hwcap_altivec);
+ if(hwcap_altivec & PPC_hwcap_bit::ALTIVEC_bit)
+ detected_features |= CPUID::CPUID_ALTIVEC_BIT;
+
+ const unsigned long hwcap_crypto = ::getauxval(PPC_hwcap_bit::ARCH_hwcap_crypto);
+ if(hwcap_crypto & PPC_hwcap_bit::CRYPTO_bit)
+ detected_features |= CPUID::CPUID_PPC_CRYPTO_BIT;
+
+ return detected_features;
+
#else
/*