Botan 3.13.0
Crypto and TLS for C&
hss_lms_utils.h
Go to the documentation of this file.
1/**
2 * Utils for HSS/LMS
3 * (C) 2023 Jack Lloyd
4 * 2023 Fabian Albert, Philippe Lieser - Rohde & Schwarz Cybersecurity GmbH
5 *
6 * Botan is released under the Simplified BSD License (see license.txt)
7 */
8
9#ifndef BOTAN_HSS_LMS_UTILS_H_
10#define BOTAN_HSS_LMS_UTILS_H_
11
12#include <botan/hash.h>
13#include <botan/internal/loadstor.h>
14
15namespace Botan {
16
17/**
18 * @brief Helper class used to derive secret values based in the pseudorandom key generation
19 * described in RFC 8554 Appendix A.
20 *
21 * This generation computes the following:
22 *
23 * Result = Hash( identifier || u32str(q) || u16str(i) || u8str(j) || SEED )
24 *
25 * This Key Generation procedure is also used for the seed derivation function of
26 * SECRET_METHOD 2 defined in https://github.com/cisco/hash-sigs,
27 */
29 public:
30 /**
31 * @brief Create a PseudorandomKeyGeneration instance for a fixed @p identifier
32 */
33 explicit PseudorandomKeyGeneration(std::span<const uint8_t> identifier);
34
37
40
42
43 /**
44 * @brief Specify the value for the u32str(q) hash input field
45 */
46 void set_q(uint32_t q) { store_be(m_q, q); }
47
48 /**
49 * @brief Specify the value for the u16str(i) hash input field
50 */
51 void set_i(uint16_t i) { store_be(m_i, i); }
52
53 /**
54 * @brief Specify the value for the u8str(j) hash input field
55 */
56 void set_j(uint8_t j) { store_be(m_j, j); }
57
58 /**
59 * @brief Create a hash value using the preconfigured prefix and a @p seed
60 */
61 template <concepts::resizable_byte_buffer T = secure_vector<uint8_t>>
62 T gen(HashFunction& hash, std::span<const uint8_t> seed) const {
63 T output(hash.output_length());
64 gen(output, hash, seed);
65 return output;
66 }
67
68 /**
69 * @brief Create a hash value using the preconfigured prefix and a @p seed
70 */
71 void gen(std::span<uint8_t> out, HashFunction& hash, std::span<const uint8_t> seed) const;
72
73 private:
74 /// Input buffer containing the prefix: 'identifier || u32str(q) || u16str(i) || u8str(j)'
75 std::vector<uint8_t> m_input_buffer;
76
77 std::span<uint8_t, sizeof(uint32_t)> m_q;
78 std::span<uint8_t, sizeof(uint16_t)> m_i;
79 std::span<uint8_t, sizeof(uint8_t)> m_j;
80};
81
82} // namespace Botan
83
84#endif
virtual size_t output_length() const =0
void set_i(uint16_t i)
Specify the value for the u16str(i) hash input field.
PseudorandomKeyGeneration & operator=(PseudorandomKeyGeneration &&)=delete
PseudorandomKeyGeneration & operator=(const PseudorandomKeyGeneration &)=delete
PseudorandomKeyGeneration(std::span< const uint8_t > identifier)
Create a PseudorandomKeyGeneration instance for a fixed identifier.
void set_j(uint8_t j)
Specify the value for the u8str(j) hash input field.
PseudorandomKeyGeneration(PseudorandomKeyGeneration &&)=delete
T gen(HashFunction &hash, std::span< const uint8_t > seed) const
Create a hash value using the preconfigured prefix and a seed.
PseudorandomKeyGeneration(const PseudorandomKeyGeneration &)=delete
void set_q(uint32_t q)
Specify the value for the u32str(q) hash input field.
constexpr auto store_be(ParamTs &&... params)
Definition loadstor.h:745