aboutsummaryrefslogtreecommitdiffstats
path: root/src/cli
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2016-09-28 03:23:12 -0400
committerJack Lloyd <[email protected]>2016-10-20 22:45:47 -0400
commit6ceeab949aae9d53914838c542e7b156c80b4b57 (patch)
tree01d56f8570686eff1064b14c8e44c6654e626b11 /src/cli
parent36e5b56eb4298e81e8413ac1ef0eada096df8abc (diff)
Add create_private_key, expose key loading functions in pk_algs.h
Diffstat (limited to 'src/cli')
-rw-r--r--src/cli/pubkey.cpp89
-rw-r--r--src/cli/speed.cpp6
2 files changed, 11 insertions, 84 deletions
diff --git a/src/cli/pubkey.cpp b/src/cli/pubkey.cpp
index 1c3f948d1..cb23ddb66 100644
--- a/src/cli/pubkey.cpp
+++ b/src/cli/pubkey.cpp
@@ -12,6 +12,7 @@
#include <botan/base64.h>
#include <botan/pk_keys.h>
+#include <botan/pk_algs.h>
#include <botan/pkcs8.h>
#include <botan/pubkey.h>
@@ -19,26 +20,6 @@
#include <botan/dl_group.h>
#endif
-#if defined(BOTAN_HAS_RSA)
- #include <botan/rsa.h>
-#endif
-
-#if defined(BOTAN_HAS_DSA)
- #include <botan/dsa.h>
-#endif
-
-#if defined(BOTAN_HAS_ECDSA)
- #include <botan/ecdsa.h>
-#endif
-
-#if defined(BOTAN_HAS_CURVE_25519)
- #include <botan/curve25519.h>
-#endif
-
-#if defined(BOTAN_HAS_MCELIECE)
- #include <botan/mceliece.h>
-#endif
-
namespace Botan_CLI {
class PK_Keygen final : public Command
@@ -46,75 +27,19 @@ class PK_Keygen final : public Command
public:
PK_Keygen() : Command("keygen --algo=RSA --params= --passphrase= --pbe= --pbe-millis=300 --der-out") {}
- static std::unique_ptr<Botan::Private_Key> do_keygen(const std::string& algo,
- const std::string& params,
- Botan::RandomNumberGenerator& rng)
+ void go() override
{
- typedef std::function<std::unique_ptr<Botan::Private_Key> (std::string)> gen_fn;
- std::map<std::string, gen_fn> generators;
-
-#if defined(BOTAN_HAS_RSA)
- generators["RSA"] = [&rng](std::string param) -> std::unique_ptr<Botan::Private_Key> {
- if(param.empty())
- param = "2048";
- return std::unique_ptr<Botan::Private_Key>(
- new Botan::RSA_PrivateKey(rng, Botan::to_u32bit(param)));
- };
-#endif
+ const std::string algo = get_arg("algo");
+ const std::string params = get_arg("params");
-#if defined(BOTAN_HAS_DSA)
- generators["DSA"] = [&rng](std::string param) -> std::unique_ptr<Botan::Private_Key> {
- if(param.empty())
- param = "dsa/botan/2048";
- return std::unique_ptr<Botan::Private_Key>(
- new Botan::DSA_PrivateKey(rng, Botan::DL_Group(param)));
- };
-#endif
+ std::unique_ptr<Botan::Private_Key>
+ key(Botan::create_private_key(algo, rng(), params));
-#if defined(BOTAN_HAS_ECDSA)
- generators["ECDSA"] = [&rng](std::string param) {
- if(param.empty())
- param = "secp256r1";
- Botan::EC_Group grp(param);
- return std::unique_ptr<Botan::Private_Key>(
- new Botan::ECDSA_PrivateKey(rng, grp));
- };
-#endif
-
-#if defined(BOTAN_HAS_CURVE_25519)
- generators["Curve25519"] = [&rng](std::string /*ignored*/) {
- return std::unique_ptr<Botan::Private_Key>(
- new Botan::Curve25519_PrivateKey(rng));
- };
-#endif
-
-#if defined(BOTAN_HAS_MCELIECE)
- generators["McEliece"] = [&rng](std::string param) {
- if(param.empty())
- param = "2280,45";
- std::vector<std::string> param_parts = Botan::split_on(param, ',');
- if(param_parts.size() != 2)
- throw CLI_Usage_Error("Bad McEliece parameters " + param);
- return std::unique_ptr<Botan::Private_Key>(
- new Botan::McEliece_PrivateKey(rng,
- Botan::to_u32bit(param_parts[0]),
- Botan::to_u32bit(param_parts[1])));
- };
-#endif
-
- auto gen = generators.find(algo);
- if(gen == generators.end())
+ if(!key)
{
throw CLI_Error_Unsupported("keygen", algo);
}
- return gen->second(params);
- }
-
- void go() override
- {
- std::unique_ptr<Botan::Private_Key> key(do_keygen(get_arg("algo"), get_arg("params"), rng()));
-
const std::string pass = get_arg("passphrase");
const bool der_out = flag_set("der-out");
diff --git a/src/cli/speed.cpp b/src/cli/speed.cpp
index b44c6df99..e6d4a6b7f 100644
--- a/src/cli/speed.cpp
+++ b/src/cli/speed.cpp
@@ -596,16 +596,18 @@ class Speed final : public Command
ks_timer.run([&] { enc.set_key(key); });
ks_timer.run([&] { dec.set_key(key); });
+ Botan::secure_vector<uint8_t> iv = rng().random_vec(enc.default_nonce_length());
+
while(encrypt_timer.under(runtime) && decrypt_timer.under(runtime))
{
- const Botan::secure_vector<uint8_t> iv = rng().random_vec(enc.default_nonce_length());
-
// Must run in this order, or AEADs will reject the ciphertext
iv_timer.run([&] { enc.start(iv); });
encrypt_timer.run([&] { enc.finish(buffer); });
iv_timer.run([&] { dec.start(iv); });
decrypt_timer.run([&] { dec.finish(buffer); });
+
+ iv[0] += 1;
}
output() << Timer::result_string_ops(ks_timer);