summaryrefslogtreecommitdiff
path: root/src/seed.hpp
diff options
context:
space:
mode:
authorManoj Srivastava <srivasta@debian.org>2020-05-23 00:33:19 -0700
committerManoj Srivastava <srivasta@debian.org>2020-05-23 00:33:19 -0700
commitd6b913d3ca2e84b75f3675fd6e9f5246c100cf27 (patch)
tree5fc28b7efc737bf2c79dc7d799e0a6013957fe11 /src/seed.hpp
parentc42f029316c0c004a795ca170bdb50644a800534 (diff)
parent73a0259be1d44fdb2ab34266ae0ff63f0d8f0b60 (diff)
Merge branch 'master' into dgit/siddebian/2.4.0-ah-1archive/debian/2.4.0-ah-1
Diffstat (limited to 'src/seed.hpp')
-rw-r--r--src/seed.hpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/seed.hpp b/src/seed.hpp
new file mode 100644
index 00000000..91ec7eba
--- /dev/null
+++ b/src/seed.hpp
@@ -0,0 +1,51 @@
+#pragma once
+
+#include <array>
+#include <cstdint>
+
+class seed_t {
+
+public:
+ // Number of seed bytes.
+ static constexpr std::size_t n_bytes = 64;
+
+ // Sanity check; we're relying on converting to uint32_t elsewhere,
+ // so let's just keep it as easy as possible.
+ static_assert(n_bytes % 4 == 0, "n_bytes must be multiple of 4");
+
+ // Number of uint32_t's required to store the seed.
+ static constexpr std::size_t n_uint32 = n_bytes / 4;
+
+private:
+ std::array<std::uint8_t, n_bytes> m_data;
+
+ // Default constructor is private. Use the static
+ // factory functions instead.
+ seed_t()
+ {
+ // Factory functions do explicit initialization.
+ };
+
+public:
+
+ /**
+ * Create a seed from system entropy.
+ */
+ static seed_t system();
+
+ /**
+ * Create a seed from the given bytes.
+ */
+ static seed_t from_bytes(std::uint8_t bytes[n_bytes]);
+
+ /**
+ * Convert seed to bytes.
+ */
+ void to_bytes(std::uint8_t bytes[n_bytes]) const;
+
+ /**
+ * Convert seed to uint32_t's suitable for seed_seq.
+ */
+ void to_uint32(std::uint32_t seed_seq_data[n_uint32]) const;
+
+};