diff --git a/src/lib/pubkey/hss_lms/hss_lms_utils.cpp b/src/lib/pubkey/hss_lms/hss_lms_utils.cpp index 8ec0167a3bd..bc05b3e4dd5 100644 --- a/src/lib/pubkey/hss_lms/hss_lms_utils.cpp +++ b/src/lib/pubkey/hss_lms/hss_lms_utils.cpp @@ -11,14 +11,16 @@ #include namespace Botan { -PseudorandomKeyGeneration::PseudorandomKeyGeneration(std::span identifier) : - m_input_buffer(identifier.size() + sizeof(uint32_t) + sizeof(uint16_t) + sizeof(uint8_t)), - m_q(m_input_buffer.data() + identifier.size(), sizeof(uint32_t)), - m_i(m_input_buffer.data() + identifier.size() + sizeof(uint32_t), sizeof(uint16_t)), - m_j(m_input_buffer.data() + identifier.size() + sizeof(uint32_t) + sizeof(uint16_t), sizeof(uint8_t)) -{ - copy_mem(m_input_buffer.data(), identifier.data(), identifier.size()); +// The magic numbers in the initializer list below reflect the structure of the +// m_input_buffer member and must be updated if any of the pre-defined +// std::span<>s are changed. +PseudorandomKeyGeneration::PseudorandomKeyGeneration(std::span identifier) : + m_input_buffer(identifier.size() + 7), + m_q(std::span(m_input_buffer).last<7>().first<4>()), + m_i(std::span(m_input_buffer).last<3>().first<2>()), + m_j(std::span(m_input_buffer).last<1>()) { + copy_into(std::span(m_input_buffer).first(identifier.size()), identifier); } void PseudorandomKeyGeneration::gen(std::span out, HashFunction& hash, std::span seed) const { diff --git a/src/lib/pubkey/hss_lms/hss_lms_utils.h b/src/lib/pubkey/hss_lms/hss_lms_utils.h index 3c6e1783cda..e55adebd5a7 100644 --- a/src/lib/pubkey/hss_lms/hss_lms_utils.h +++ b/src/lib/pubkey/hss_lms/hss_lms_utils.h @@ -35,25 +35,24 @@ class PseudorandomKeyGeneration { /** * @brief Specify the value for the u32str(q) hash input field */ - void set_q(uint32_t q) { store_be(q, m_q.data()); } + void set_q(uint32_t q) { store_be(m_q, q); } /** * @brief Specify the value for the u16str(i) hash input field */ - void set_i(uint16_t i) { store_be(i, m_i.data()); } + void set_i(uint16_t i) { store_be(m_i, i); } /** * @brief Specify the value for the u8str(j) hash input field */ - void set_j(uint8_t j) { m_j[0] = j; } + void set_j(uint8_t j) { store_be(m_j, j); } /** * @brief Create a hash value using the preconfigured prefix and a @p seed */ template > T gen(HashFunction& hash, std::span seed) const { - T output; - output.resize(hash.output_length()); + T output(hash.output_length()); gen(output, hash, seed); return output; }