15#include <botan/internal/xmss_wots.h>
17#include <botan/exceptn.h>
18#include <botan/internal/fmt.h>
19#include <botan/internal/xmss_tools.h>
25 if(param_set ==
"WOTSP-SHA2_256") {
28 if(param_set ==
"WOTSP-SHA2_512") {
31 if(param_set ==
"WOTSP-SHAKE_256") {
34 if(param_set ==
"WOTSP-SHAKE_512") {
37 if(param_set ==
"WOTSP-SHA2_192") {
40 if(param_set ==
"WOTSP-SHAKE_256_256") {
43 if(param_set ==
"WOTSP-SHAKE_256_192") {
47 throw Lookup_Error(
fmt(
"Unknown XMSS-WOTS algorithm param '{}'", param_set));
59 m_name =
"WOTSP-SHA2_256";
60 m_hash_name =
"SHA-256";
67 m_name =
"WOTSP-SHA2_512";
68 m_hash_name =
"SHA-512";
75 m_name =
"WOTSP-SHAKE_256";
76 m_hash_name =
"SHAKE-128(256)";
83 m_name =
"WOTSP-SHAKE_512";
84 m_hash_name =
"SHAKE-256(512)";
91 m_name =
"WOTSP-SHA2_192";
92 m_hash_name =
"Truncated(SHA-256,192)";
99 m_name =
"WOTSP-SHAKE_256_256";
100 m_hash_name =
"SHAKE-256(256)";
107 m_name =
"WOTSP-SHAKE_256_192";
108 m_hash_name =
"SHAKE-256(192)";
112 throw Not_Implemented(
"Algorithm id does not match any known XMSS WOTS algorithm id.");
115 m_lg_w = (m_w == 16) ? 4 : 2;
116 m_len_1 =
static_cast<size_t>(std::ceil((8 *
element_size()) / m_lg_w));
117 m_len_2 =
static_cast<size_t>(floor(log2(m_len_1 * (
wots_parameter() - 1)) / m_lg_w) + 1);
119 "Invalid XMSS WOTS parameter "
120 "\"len\" detected.");
125 result.reserve(out_size);
131 for(
size_t i = 0; i < out_size; i++) {
138 result.push_back(
static_cast<uint8_t
>((total >> bits) & (m_w - 1)));
144 value <<= (8 - ((m_len_2 * m_lg_w) % 8));
145 size_t len_2_bytes =
static_cast<size_t>(std::ceil(
static_cast<float>(m_len_2 * m_lg_w) / 8.0));
148 return base_w(result, m_len_2);
154 for(
size_t i = 0; i < data.size(); i++) {
159 std::move(csum_bytes.begin(), csum_bytes.end(), std::back_inserter(data));
#define BOTAN_ASSERT(expr, assertion_made)
size_t wots_parameter() const
size_t element_size() const
XMSS_WOTS_Parameters(std::string_view algo_name)
static ots_algorithm_t xmss_wots_id_from_string(std::string_view param_set)
ots_algorithm_t oid() const
secure_vector< uint8_t > base_w(const secure_vector< uint8_t > &msg, size_t out_size) const
void append_checksum(secure_vector< uint8_t > &data) const
std::string fmt(std::string_view format, const T &... args)
std::vector< T, secure_allocator< T > > secure_vector