From 731f26e10a71d9749c61c71a2d997698bb55ac37 Mon Sep 17 00:00:00 2001 From: Jack Lloyd Date: Thu, 28 Feb 2019 19:25:31 -0500 Subject: Split CLI utils.cpp into more parts Add base58 encoding/decoding CLI Use decrypt_or_random in pk_decrypt --- src/cli/cli_rng.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'src/cli/cli_rng.cpp') 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 #include #include +#include #if defined(BOTAN_HAS_AUTO_SEEDING_RNG) #include @@ -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 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); + } -- cgit v1.2.3