aboutsummaryrefslogtreecommitdiffstats
path: root/src/cli/cli_rng.cpp
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2019-02-28 19:25:31 -0500
committerJack Lloyd <[email protected]>2019-02-28 19:25:31 -0500
commit731f26e10a71d9749c61c71a2d997698bb55ac37 (patch)
treec8ce8f21b0f1c23df73ada12125752a9c17461d4 /src/cli/cli_rng.cpp
parenta9d2cceb52ea93291f37c2a8da4a91bb13a4fbf6 (diff)
Split CLI utils.cpp into more parts
Add base58 encoding/decoding CLI Use decrypt_or_random in pk_decrypt
Diffstat (limited to 'src/cli/cli_rng.cpp')
-rw-r--r--src/cli/cli_rng.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/cli/cli_rng.cpp b/src/cli/cli_rng.cpp
index 78af51314..90b30a820 100644
--- a/src/cli/cli_rng.cpp
+++ b/src/cli/cli_rng.cpp
@@ -9,6 +9,7 @@
#include <botan/entropy_src.h>
#include <botan/cpuid.h>
#include <botan/hex.h>
+#include <botan/parsing.h>
#if defined(BOTAN_HAS_AUTO_SEEDING_RNG)
#include <botan/auto_rng.h>
@@ -86,4 +87,47 @@ cli_make_rng(const std::string& rng_type, const std::string& hex_drbg_seed)
throw CLI_Error_Unsupported("RNG", rng_type);
}
+class RNG final : public Command
+ {
+ public:
+ RNG() : Command("rng --system --rdrand --auto --entropy --drbg --drbg-seed= *bytes") {}
+
+ std::string group() const override
+ {
+ return "misc";
+ }
+
+ std::string description() const override
+ {
+ return "Sample random bytes from the specified rng";
+ }
+
+ void go() override
+ {
+ std::string type = get_arg("rng-type");
+
+ if(type.empty())
+ {
+ for(std::string flag : { "system", "rdrand", "auto", "entropy", "drbg" })
+ {
+ if(flag_set(flag))
+ {
+ type = flag;
+ break;
+ }
+ }
+ }
+
+ const std::string drbg_seed = get_arg("drbg-seed");
+ std::unique_ptr<Botan::RandomNumberGenerator> rng = cli_make_rng(type, drbg_seed);
+
+ for(const std::string& req : get_arg_list("bytes"))
+ {
+ output() << Botan::hex_encode(rng->random_vec(Botan::to_u32bit(req))) << "\n";
+ }
+ }
+ };
+
+BOTAN_REGISTER_COMMAND("rng", RNG);
+
}