Botan 3.6.1
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 PseudorandomKeyGeneration(std::span<const uint8_t> identifier);
34
35 /**
36 * @brief Specify the value for the u32str(q) hash input field
37 */
38 void set_q(uint32_t q) { store_be(m_q, q); }
39
40 /**
41 * @brief Specify the value for the u16str(i) hash input field
42 */
43 void set_i(uint16_t i) { store_be(m_i, i); }
44
45 /**
46 * @brief Specify the value for the u8str(j) hash input field
47 */
48 void set_j(uint8_t j) { store_be(m_j, j); }
49
50 /**
51 * @brief Create a hash value using the preconfigured prefix and a @p seed
52 */
53 template <concepts::resizable_byte_buffer T = secure_vector<uint8_t>>
54 T gen(HashFunction& hash, std::span<const uint8_t> seed) const {
55 T output(hash.output_length());
56 gen(output, hash, seed);
57 return output;
58 }
59
60 /**
61 * @brief Create a hash value using the preconfigured prefix and a @p seed
62 */
63 void gen(std::span<uint8_t> out, HashFunction& hash, std::span<const uint8_t> seed) const;
64
65 private:
66 /// Input buffer containing the prefix: 'identifier || u32str(q) || u16str(i) || u8str(j)'
67 std::vector<uint8_t> m_input_buffer;
68
69 std::span<uint8_t, sizeof(uint32_t)> m_q;
70 std::span<uint8_t, sizeof(uint16_t)> m_i;
71 std::span<uint8_t, sizeof(uint8_t)> m_j;
72};
73
74} // namespace Botan
75
76#endif
virtual size_t output_length() const =0
Helper class used to derive secret values based in the pseudorandom key generation described in RFC 8...
void set_i(uint16_t i)
Specify the value for the u16str(i) hash input field.
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.
T gen(HashFunction &hash, std::span< const uint8_t > seed) const
Create a hash value using the preconfigured prefix and a seed.
void set_q(uint32_t q)
Specify the value for the u32str(q) hash input field.
FE_25519 T
Definition ge.cpp:34
constexpr auto store_be(ParamTs &&... params)
Definition loadstor.h:773