aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/rng/rdrand_rng/rdrand_rng.h
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2016-07-19 14:57:12 -0400
committerJack Lloyd <[email protected]>2016-07-19 14:57:12 -0400
commit4e78e6ea5608edddda8929f3b43a978e89f927ba (patch)
treeb2da95ad40377650878f1b1218ec6e8bea3e6c5b /src/lib/rng/rdrand_rng/rdrand_rng.h
parent308c7d5eda678566edd26e9ab20edbe772f46363 (diff)
Add RDRAND_RNG
For those that are willing to trust uninspectible hardware. :) Changes RDRAND entropy source to call RDRAND_RNG Add --rdrand flag to rng cmdlet
Diffstat (limited to 'src/lib/rng/rdrand_rng/rdrand_rng.h')
-rw-r--r--src/lib/rng/rdrand_rng/rdrand_rng.h61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/lib/rng/rdrand_rng/rdrand_rng.h b/src/lib/rng/rdrand_rng/rdrand_rng.h
new file mode 100644
index 000000000..b9445f28e
--- /dev/null
+++ b/src/lib/rng/rdrand_rng/rdrand_rng.h
@@ -0,0 +1,61 @@
+/**
+* RDRAND RNG
+* (C) 2016 Jack Lloyd
+*
+* Botan is released under the Simplified BSD License (see license.txt)
+*/
+
+#ifndef BOTAN_RNG_RDRAND_H_
+#define BOTAN_RNG_RDRAND_H_
+
+#include <botan/rng.h>
+
+namespace Botan {
+
+class BOTAN_DLL RDRAND_RNG : public Hardware_RNG
+ {
+ public:
+ /**
+ * On correctly working hardware, RDRAND is always supposed to
+ * succeed within a set number of retries. If after that many
+ * retries RDRAND has still not suceeded, sets ok = false and
+ * returns 0.
+ */
+ static uint32_t rdrand_status(bool& ok);
+
+ /*
+ * Calls RDRAND until it succeeds, this could hypothetically
+ * loop forever on broken hardware.
+ */
+ static uint32_t rdrand();
+
+ /**
+ * Constructor will throw if CPU does not have RDRAND bit set
+ */
+ RDRAND_RNG();
+
+ /**
+ * Uses RDRAND to produce output
+ */
+ void randomize(uint8_t out[], size_t out_len) override;
+
+ /*
+ * No way to provide entropy to RDRAND generator, so add_entropy is ignored
+ */
+ void add_entropy(const uint8_t[], size_t) override
+ { /* no op */ }
+
+ size_t reseed_with_sources(Entropy_Sources&, size_t,
+ std::chrono::milliseconds) override
+ { return 0; /* no op */ }
+
+ std::string name() const override { return "RDRAND"; }
+
+ bool is_seeded() const override { return true; }
+
+ void clear() override {}
+ };
+
+}
+
+#endif