aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/pubkey/xmss
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2016-11-25 16:42:53 -0500
committerJack Lloyd <[email protected]>2016-11-25 16:42:53 -0500
commitcdee866369b274151b745cb9b31b65c8207f638d (patch)
treebb2e7ad837c98e0ad95e8a30f69633879f7685d9 /src/lib/pubkey/xmss
parent36f260c4b97ba4b2253a3215e6c9afe35022ac04 (diff)
Make XMSS more friendly about invalid params.
Previously just throw an exception from map.at Add an XMSS keygen test, and add default params for create_private_key
Diffstat (limited to 'src/lib/pubkey/xmss')
-rw-r--r--src/lib/pubkey/xmss/xmss_parameters.cpp53
-rw-r--r--src/lib/pubkey/xmss/xmss_parameters.h4
-rw-r--r--src/lib/pubkey/xmss/xmss_wots_parameters.cpp24
-rw-r--r--src/lib/pubkey/xmss/xmss_wots_parameters.h2
4 files changed, 53 insertions, 30 deletions
diff --git a/src/lib/pubkey/xmss/xmss_parameters.cpp b/src/lib/pubkey/xmss/xmss_parameters.cpp
index f1f3281cf..c55b25a27 100644
--- a/src/lib/pubkey/xmss/xmss_parameters.cpp
+++ b/src/lib/pubkey/xmss/xmss_parameters.cpp
@@ -16,26 +16,41 @@
namespace Botan {
-const std::map<std::string, XMSS_Parameters::xmss_algorithm_t>
- XMSS_Parameters::m_oid_name_lut =
- {
- { "XMSS_SHA2-256_W16_H10", XMSS_SHA2_256_W16_H10 },
- { "XMSS_SHA2-256_W16_H16", XMSS_SHA2_256_W16_H16 },
- { "XMSS_SHA2-256_W16_H20", XMSS_SHA2_256_W16_H20 },
- { "XMSS_SHA2-512_W16_H10", XMSS_SHA2_512_W16_H10 },
- { "XMSS_SHA2-512_W16_H16", XMSS_SHA2_512_W16_H16 },
- { "XMSS_SHA2-512_W16_H20", XMSS_SHA2_512_W16_H20 },
- { "XMSS_SHAKE128_W16_H10", XMSS_SHAKE128_W16_H10 },
- { "XMSS_SHAKE128_W16_H16", XMSS_SHAKE128_W16_H16 },
- { "XMSS_SHAKE128_W16_H20", XMSS_SHAKE128_W16_H20 },
- { "XMSS_SHAKE256_W16_H10", XMSS_SHAKE256_W16_H10 },
- { "XMSS_SHAKE256_W16_H16", XMSS_SHAKE256_W16_H16 },
- { "XMSS_SHAKE256_W16_H20", XMSS_SHAKE256_W16_H20 }
- };
+//static
+XMSS_Parameters::xmss_algorithm_t XMSS_Parameters::xmss_id_from_string(const std::string& param_set)
+ {
+ if(param_set == "XMSS_SHA2-256_W16_H10")
+ return XMSS_SHA2_256_W16_H10;
+ if(param_set == "XMSS_SHA2-256_W16_H16")
+ return XMSS_SHA2_256_W16_H16;
+ if(param_set == "XMSS_SHA2-256_W16_H20")
+ return XMSS_SHA2_256_W16_H20;
+ if(param_set == "XMSS_SHA2-512_W16_H10")
+ return XMSS_SHA2_512_W16_H10;
+ if(param_set == "XMSS_SHA2-512_W16_H16")
+ return XMSS_SHA2_512_W16_H16;
+ if(param_set == "XMSS_SHA2-512_W16_H20")
+ return XMSS_SHA2_512_W16_H20;
+ if(param_set == "XMSS_SHAKE128_W16_H10")
+ return XMSS_SHAKE128_W16_H10;
+ if(param_set == "XMSS_SHAKE128_W16_H16")
+ return XMSS_SHAKE128_W16_H16;
+ if(param_set == "XMSS_SHAKE128_W16_H20")
+ return XMSS_SHAKE128_W16_H20;
+ if(param_set == "XMSS_SHAKE256_W16_H10")
+ return XMSS_SHAKE256_W16_H10;
+ if(param_set == "XMSS_SHAKE256_W16_H16")
+ return XMSS_SHAKE256_W16_H16;
+ if(param_set == "XMSS_SHAKE256_W16_H20")
+ return XMSS_SHAKE256_W16_H20;
+ throw Invalid_Argument("Unknown XMSS algorithm param '" + param_set + "'");
+ }
+
+XMSS_Parameters::XMSS_Parameters(const std::string& param_set)
+ : XMSS_Parameters(XMSS_Parameters::xmss_id_from_string(param_set))
+ {
+ }
-XMSS_Parameters::XMSS_Parameters(const std::string& algo_name)
- : XMSS_Parameters(m_oid_name_lut.at(algo_name))
- {}
XMSS_Parameters::XMSS_Parameters(xmss_algorithm_t oid)
: m_oid(oid)
diff --git a/src/lib/pubkey/xmss/xmss_parameters.h b/src/lib/pubkey/xmss/xmss_parameters.h
index 7a83af381..1e8048217 100644
--- a/src/lib/pubkey/xmss/xmss_parameters.h
+++ b/src/lib/pubkey/xmss/xmss_parameters.h
@@ -44,6 +44,8 @@ class BOTAN_DLL XMSS_Parameters
XMSS_SHAKE256_W16_H20 = 0x0c00000c
};
+ static xmss_algorithm_t xmss_id_from_string(const std::string& algo_name);
+
XMSS_Parameters(const std::string& algo_name);
XMSS_Parameters(xmss_algorithm_t oid);
@@ -106,8 +108,6 @@ class BOTAN_DLL XMSS_Parameters
}
private:
- static const std::map<std::string, xmss_algorithm_t>
- m_oid_name_lut;
xmss_algorithm_t m_oid;
XMSS_WOTS_Parameters::ots_algorithm_t m_wots_oid;
std::string m_name;
diff --git a/src/lib/pubkey/xmss/xmss_wots_parameters.cpp b/src/lib/pubkey/xmss/xmss_wots_parameters.cpp
index 274da8d31..3a1c1902d 100644
--- a/src/lib/pubkey/xmss/xmss_wots_parameters.cpp
+++ b/src/lib/pubkey/xmss/xmss_wots_parameters.cpp
@@ -17,17 +17,23 @@
namespace Botan {
-const std::map<std::string, XMSS_WOTS_Parameters::ots_algorithm_t>
- XMSS_WOTS_Parameters::m_oid_name_lut =
+//static
+XMSS_WOTS_Parameters::ots_algorithm_t
+XMSS_WOTS_Parameters::xmss_wots_id_from_string(const std::string& param_set)
{
- { "WOTSP_SHA2-256_W16", WOTSP_SHA2_256_W16 },
- { "WOTSP_SHA2-512_W16", WOTSP_SHA2_512_W16 },
- { "WOTSP_SHAKE128_W16", WOTSP_SHAKE128_W16 },
- { "WOTSP_SHAKE256_W16", WOTSP_SHAKE256_W16 }
- };
+ if(param_set == "WOTSP_SHA2-256_W16")
+ return WOTSP_SHA2_256_W16;
+ if(param_set == "WOTSP_SHA2-512_W16")
+ return WOTSP_SHA2_512_W16;
+ if(param_set == "WOTSP_SHAKE128_W16")
+ return WOTSP_SHAKE128_W16;
+ if(param_set == "WOTSP_SHAKE256_W16")
+ return WOTSP_SHAKE256_W16;
+ throw Invalid_Argument("Unknown XMSS-WOTS algorithm param '" + param_set + "'");
+ }
-XMSS_WOTS_Parameters::XMSS_WOTS_Parameters(const std::string& algo_name)
- : XMSS_WOTS_Parameters(m_oid_name_lut.at(algo_name))
+XMSS_WOTS_Parameters::XMSS_WOTS_Parameters(const std::string& param_set)
+ : XMSS_WOTS_Parameters(xmss_wots_id_from_string(param_set))
{}
XMSS_WOTS_Parameters::XMSS_WOTS_Parameters(ots_algorithm_t oid)
diff --git a/src/lib/pubkey/xmss/xmss_wots_parameters.h b/src/lib/pubkey/xmss/xmss_wots_parameters.h
index 15644a257..cc89c3d4a 100644
--- a/src/lib/pubkey/xmss/xmss_wots_parameters.h
+++ b/src/lib/pubkey/xmss/xmss_wots_parameters.h
@@ -45,6 +45,8 @@ class XMSS_WOTS_Parameters
XMSS_WOTS_Parameters(const std::string& algo_name);
XMSS_WOTS_Parameters(ots_algorithm_t ots_spec);
+ static ots_algorithm_t xmss_wots_id_from_string(const std::string& param_set);
+
/**
* Algorithm 1: convert input string to base.
*