Skip to content

Commit

Permalink
iterate on LMS's PseudorandomKeyGeneration
Browse files Browse the repository at this point in the history
  • Loading branch information
reneme committed Apr 8, 2024
1 parent fe06610 commit 114c35e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
16 changes: 9 additions & 7 deletions src/lib/pubkey/hss_lms/hss_lms_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@
#include <botan/internal/stl_util.h>

namespace Botan {
PseudorandomKeyGeneration::PseudorandomKeyGeneration(std::span<const uint8_t> 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<const uint8_t> 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<uint8_t> out, HashFunction& hash, std::span<const uint8_t> seed) const {
Expand Down
9 changes: 4 additions & 5 deletions src/lib/pubkey/hss_lms/hss_lms_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <concepts::resizable_byte_buffer T = secure_vector<uint8_t>>
T gen(HashFunction& hash, std::span<const uint8_t> seed) const {
T output;
output.resize(hash.output_length());
T output(hash.output_length());
gen(output, hash, seed);
return output;
}
Expand Down

0 comments on commit 114c35e

Please sign in to comment.