aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/build-data/arch/ppc64.txt1
-rw-r--r--src/build-data/buildh.in2
-rw-r--r--src/build-data/cc/gcc.txt1
-rw-r--r--src/lib/entropy/entropy_srcs.cpp11
-rw-r--r--src/lib/entropy/p9_darn/info.txt19
-rw-r--r--src/lib/entropy/p9_darn/p9_darn.cpp28
-rw-r--r--src/lib/entropy/p9_darn/p9_darn.h23
-rw-r--r--src/lib/utils/cpuid/cpuid.cpp1
-rw-r--r--src/lib/utils/cpuid/cpuid.h7
-rw-r--r--src/lib/utils/cpuid/cpuid_ppc.cpp3
10 files changed, 95 insertions, 1 deletions
diff --git a/src/build-data/arch/ppc64.txt b/src/build-data/arch/ppc64.txt
index 23d3bb2a1..470bee2db 100644
--- a/src/build-data/arch/ppc64.txt
+++ b/src/build-data/arch/ppc64.txt
@@ -13,4 +13,5 @@ ppc64el
<isa_extensions>
altivec
ppccrypto
+power9
</isa_extensions>
diff --git a/src/build-data/buildh.in b/src/build-data/buildh.in
index caa160eb0..425d06498 100644
--- a/src/build-data/buildh.in
+++ b/src/build-data/buildh.in
@@ -181,7 +181,7 @@
* broken system RNG.
*/
#define BOTAN_ENTROPY_DEFAULT_SOURCES \
- { "rdseed", "rdrand", "getentropy", "dev_random", \
+ { "rdseed", "rdrand", "p9_darn", "getentropy", "dev_random", \
"system_rng", "proc_walk", "system_stats" }
/* Multiplier on a block cipher's native parallelism */
diff --git a/src/build-data/cc/gcc.txt b/src/build-data/cc/gcc.txt
index f495af4e6..cc3ce99e1 100644
--- a/src/build-data/cc/gcc.txt
+++ b/src/build-data/cc/gcc.txt
@@ -63,6 +63,7 @@ sha -> "-msha"
altivec -> "-maltivec"
ppccrypto -> "-mcrypto"
+power9 -> "-mcpu=power9"
arm64:armv8crypto -> ""
arm64:armv8sm3 -> "-march=armv8.2-a+sm4"
diff --git a/src/lib/entropy/entropy_srcs.cpp b/src/lib/entropy/entropy_srcs.cpp
index 85e0b6dc5..ba60ed62d 100644
--- a/src/lib/entropy/entropy_srcs.cpp
+++ b/src/lib/entropy/entropy_srcs.cpp
@@ -20,6 +20,10 @@
#include <botan/internal/rdseed.h>
#endif
+#if defined(BOTAN_HAS_ENTROPY_SRC_DARN)
+ #include <botan/internal/p9_darn.h>
+#endif
+
#if defined(BOTAN_HAS_ENTROPY_SRC_DEV_RANDOM)
#include <botan/internal/dev_random.h>
#endif
@@ -83,6 +87,13 @@ std::unique_ptr<Entropy_Source> Entropy_Source::create(const std::string& name)
}
#endif
+#if defined(BOTAN_HAS_ENTROPY_SRC_DARN)
+ if(name == "p9_darn")
+ {
+ return std::unique_ptr<Entropy_Source>(new POWER9_DARN);
+ }
+#endif
+
#if defined(BOTAN_HAS_ENTROPY_SRC_GETENTROPY)
if(name == "getentropy")
{
diff --git a/src/lib/entropy/p9_darn/info.txt b/src/lib/entropy/p9_darn/info.txt
new file mode 100644
index 000000000..30f76603b
--- /dev/null
+++ b/src/lib/entropy/p9_darn/info.txt
@@ -0,0 +1,19 @@
+<defines>
+ENTROPY_SRC_DARN -> 20180610
+</defines>
+
+<header:internal>
+p9_darn.h
+</header:internal>
+
+<cc>
+gcc:7.0
+</cc>
+
+<isa>
+power9
+</isa>
+
+<arch>
+ppc64
+</arch>
diff --git a/src/lib/entropy/p9_darn/p9_darn.cpp b/src/lib/entropy/p9_darn/p9_darn.cpp
new file mode 100644
index 000000000..aa88b8301
--- /dev/null
+++ b/src/lib/entropy/p9_darn/p9_darn.cpp
@@ -0,0 +1,28 @@
+/*
+* (C) 2019 Jack Lloyd
+*
+* Botan is released under the Simplified BSD License (see license.txt)
+*/
+
+#include <botan/internal/p9_darn.h>
+#include <botan/cpuid.h>
+
+namespace Botan {
+
+size_t POWER9_DARN::poll(RandomNumberGenerator& rng)
+ {
+ if(CPUID::has_darn_rng())
+ {
+ secure_vector<uint64_t> seed(64);
+
+ for(size_t i = 0; i != seed.size(); ++i)
+ seed[i] = __builtin_darn_raw();
+
+ rng.add_entropy(reinterpret_cast<const uint8_t*>(seed.data()),
+ seed.size() * sizeof(uint64_t));
+ }
+
+ return 0;
+ }
+
+}
diff --git a/src/lib/entropy/p9_darn/p9_darn.h b/src/lib/entropy/p9_darn/p9_darn.h
new file mode 100644
index 000000000..9d8c508a1
--- /dev/null
+++ b/src/lib/entropy/p9_darn/p9_darn.h
@@ -0,0 +1,23 @@
+/*
+* (C) 2019 Jack Lloyd
+*
+* Botan is released under the Simplified BSD License (see license.txt)
+*/
+
+#ifndef BOTAN_ENTROPY_SRC_DARN_H_
+#define BOTAN_ENTROPY_SRC_DARN_H_
+
+#include <botan/entropy_src.h>
+
+namespace Botan {
+
+class POWER9_DARN final : public Entropy_Source
+ {
+ public:
+ std::string name() const override { return "p9_darn"; }
+ size_t poll(RandomNumberGenerator& rng) override;
+ };
+
+}
+
+#endif
diff --git a/src/lib/utils/cpuid/cpuid.cpp b/src/lib/utils/cpuid/cpuid.cpp
index e890af061..18ccff419 100644
--- a/src/lib/utils/cpuid/cpuid.cpp
+++ b/src/lib/utils/cpuid/cpuid.cpp
@@ -63,6 +63,7 @@ std::string CPUID::to_string()
#if defined(BOTAN_TARGET_CPU_IS_PPC_FAMILY)
CPUID_PRINT(altivec);
CPUID_PRINT(ppc_crypto);
+ CPUID_PRINT(darn_rng);
#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 d278a8fcc..256c6cc57 100644
--- a/src/lib/utils/cpuid/cpuid.h
+++ b/src/lib/utils/cpuid/cpuid.h
@@ -107,6 +107,7 @@ class BOTAN_PUBLIC_API(2,1) CPUID final
#if defined(BOTAN_TARGET_CPU_IS_PPC_FAMILY)
CPUID_ALTIVEC_BIT = (1ULL << 0),
CPUID_PPC_CRYPTO_BIT = (1ULL << 1),
+ CPUID_DARN_BIT = (1ULL << 2),
#endif
#if defined(BOTAN_TARGET_CPU_IS_ARM_FAMILY)
@@ -138,6 +139,12 @@ class BOTAN_PUBLIC_API(2,1) CPUID final
static bool has_ppc_crypto()
{ return has_cpuid_bit(CPUID_PPC_CRYPTO_BIT); }
+ /**
+ * Check if the processor supports POWER9 DARN RNG
+ */
+ static bool has_darn_rng()
+ { return has_cpuid_bit(CPUID_DARN_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 08a04cafd..ff528d88e 100644
--- a/src/lib/utils/cpuid/cpuid_ppc.cpp
+++ b/src/lib/utils/cpuid/cpuid_ppc.cpp
@@ -58,6 +58,7 @@ uint64_t CPUID::CPUID_Data::detect_cpu_features(size_t* cache_line_size)
enum PPC_hwcap_bit {
ALTIVEC_bit = (1 << 28),
CRYPTO_bit = (1 << 25),
+ DARN_bit = (1 << 21),
ARCH_hwcap_altivec = 16, // AT_HWCAP
ARCH_hwcap_crypto = 26, // AT_HWCAP2
@@ -72,6 +73,8 @@ uint64_t CPUID::CPUID_Data::detect_cpu_features(size_t* cache_line_size)
const unsigned long hwcap_crypto = OS::get_auxval(PPC_hwcap_bit::ARCH_hwcap_crypto);
if(hwcap_crypto & PPC_hwcap_bit::CRYPTO_bit)
detected_features |= CPUID::CPUID_PPC_CRYPTO_BIT;
+ if(hwcap_crypto & PPC_hwcap_bit::DARN_bit)
+ detected_features |= CPUID::CPUID_DARN_BIT;
return detected_features;