Skip to content

Commit

Permalink
Improve parsing of HSS-LMS parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
randombit committed Nov 21, 2024
1 parent f91f829 commit e33eb4a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/lib/pubkey/hss_lms/hss.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,15 @@ HSS_LMS_Params::HSS_LMS_Params(std::vector<LMS_LMOTS_Params_Pair> lm_lmots_param
}

HSS_LMS_Params::HSS_LMS_Params(std::string_view algo_params) {
SCAN_Name scan(fmt("HSS-LMS({})", algo_params));

const auto wrap_in_hss_lms = [&]() {
if(algo_params.starts_with("HSS-LMS(")) {
return std::string(algo_params);
} else {
return fmt("HSS-LMS({})", algo_params);
}
}();
SCAN_Name scan(wrap_in_hss_lms);

BOTAN_ARG_CHECK(scan.arg_count() >= 2 && scan.arg_count() <= HSS_MAX_LEVELS + 1, "Invalid number of arguments");
std::string hash = scan.arg(0);
Expand Down
9 changes: 8 additions & 1 deletion src/lib/pubkey/pk_algs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,14 @@ std::unique_ptr<Private_Key> create_private_key(std::string_view alg_name,

#if defined(BOTAN_HAS_HSS_LMS)
if(alg_name == "HSS-LMS") {
return std::make_unique<HSS_LMS_PrivateKey>(rng, params);
const auto hss_params = [&]() -> std::string {
if(params.empty()) {
return "SHA-256,HW(10,1)";
} else {
return std::string(params);
}
}();
return std::make_unique<HSS_LMS_PrivateKey>(rng, hss_params);
}
#endif

Expand Down

0 comments on commit e33eb4a

Please sign in to comment.