diff options
author | lloyd <[email protected]> | 2014-03-22 19:53:37 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2014-03-22 19:53:37 +0000 |
commit | eb0e85280e1feb4eaa66847fe60f9f6c713a8d4e (patch) | |
tree | 211325354ac4e8eabdc803c27d6fab7de0bf4193 /src/cmd | |
parent | 8ce4a125a6eaf012821852ce629ead2466a2fde8 (diff) |
Add rng command which can dump RNG outputs or raw entropy samples
Diffstat (limited to 'src/cmd')
-rw-r--r-- | src/cmd/apps.h | 1 | ||||
-rw-r--r-- | src/cmd/main.cpp | 1 | ||||
-rw-r--r-- | src/cmd/rng.cpp | 51 |
3 files changed, 53 insertions, 0 deletions
diff --git a/src/cmd/apps.h b/src/cmd/apps.h index 280ee46a0..d72220322 100644 --- a/src/cmd/apps.h +++ b/src/cmd/apps.h @@ -29,6 +29,7 @@ DEFINE_APP(cert_verify); DEFINE_APP(ocsp_check); DEFINE_APP(pkcs10); DEFINE_APP(read_ssh); +DEFINE_APP(rng); DEFINE_APP(self_sig); DEFINE_APP(tls_client); DEFINE_APP(tls_server); diff --git a/src/cmd/main.cpp b/src/cmd/main.cpp index cd42658b9..92ecc051e 100644 --- a/src/cmd/main.cpp +++ b/src/cmd/main.cpp @@ -161,6 +161,7 @@ int main(int argc, char* argv[]) CALL_APP(fpe); CALL_APP(hash); CALL_APP(keygen); + CALL_APP(rng); CALL_APP(read_ssh); CALL_APP(speed); diff --git a/src/cmd/rng.cpp b/src/cmd/rng.cpp new file mode 100644 index 000000000..e2a7a8270 --- /dev/null +++ b/src/cmd/rng.cpp @@ -0,0 +1,51 @@ +/* +* (C) 2014 Jack Lloyd +* +* Distributed under the terms in doc/license.rst +*/ + +#include "apps.h" +#include <botan/libstate.h> + +int rng_main(int argc, char* argv[]) + { + if(argc == 1) + { + std::cout << "Usage: " << argv[0] << " [--raw-entropy] [n]\n"; + return 1; + } + + try + { + const size_t amt = to_u32bit(argv[argc-1]); + const bool raw = (argc == 3 && std::string(argv[1]) == "--raw-entropy"); + + if(!raw) + { + AutoSeeded_RNG rng; + std::cout << hex_encode(rng.random_vec(amt)) << "\n"; + } + else + { + double total_collected = 0; + + Entropy_Accumulator accum( + [amt,&total_collected](const byte in[], size_t in_len, double entropy_estimate) + { + std::cout << "Collected estimated "<< entropy_estimate << " bits in " + << hex_encode(in, in_len) << "\n"; + total_collected += entropy_estimate; + return total_collected >= amt; + }); + + global_state().poll_available_sources(accum); + } + } + catch(std::exception& e) + { + std::cout << "Error: " << e.what() << "\n"; + return 1; + } + + return 0; + } |