diff options
author | Jack Lloyd <[email protected]> | 2016-11-25 16:42:53 -0500 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2016-11-25 16:42:53 -0500 |
commit | cdee866369b274151b745cb9b31b65c8207f638d (patch) | |
tree | bb2e7ad837c98e0ad95e8a30f69633879f7685d9 /src/lib/pubkey | |
parent | 36f260c4b97ba4b2253a3215e6c9afe35022ac04 (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')
-rw-r--r-- | src/lib/pubkey/pk_algs.cpp | 2 | ||||
-rw-r--r-- | src/lib/pubkey/xmss/xmss_parameters.cpp | 53 | ||||
-rw-r--r-- | src/lib/pubkey/xmss/xmss_parameters.h | 4 | ||||
-rw-r--r-- | src/lib/pubkey/xmss/xmss_wots_parameters.cpp | 24 | ||||
-rw-r--r-- | src/lib/pubkey/xmss/xmss_wots_parameters.h | 2 |
5 files changed, 54 insertions, 31 deletions
diff --git a/src/lib/pubkey/pk_algs.cpp b/src/lib/pubkey/pk_algs.cpp index 7cccd0168..178001316 100644 --- a/src/lib/pubkey/pk_algs.cpp +++ b/src/lib/pubkey/pk_algs.cpp @@ -242,7 +242,7 @@ create_private_key(const std::string& alg_name, if(alg_name == "XMSS") { return std::unique_ptr<Private_Key>( - new XMSS_PrivateKey(XMSS_Parameters(params).oid(), rng)); + new XMSS_PrivateKey(XMSS_Parameters(params.empty() ? "XMSS_SHA2-512_W16_H10" : params).oid(), rng)); } #endif 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. * |