diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/utils/cpuid/cpuid.cpp | 1 | ||||
-rw-r--r-- | src/lib/utils/cpuid/cpuid.h | 10 | ||||
-rw-r--r-- | src/lib/utils/cpuid/cpuid_ppc.cpp | 24 |
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 /* |