Botan 3.9.0
Crypto and TLS for C&
hss_lms.h
Go to the documentation of this file.
1/*
2 * Hierarchical Signature System (HSS) / Leighton-Micali Signature (LMS)
3 * hash-based signature algorithm (RFC 8554).
4 *
5 * (C) 2023 Jack Lloyd
6 * 2023 Philippe Lieser, Fabian Albert - Rohde & Schwarz Cybersecurity GmbH
7 *
8 * Botan is released under the Simplified BSD License (see license.txt)
9 **/
10
11#ifndef BOTAN_HSS_LMS_H_
12#define BOTAN_HSS_LMS_H_
13
14#include <botan/pk_keys.h>
15
16#include <memory>
17#include <vector>
18
19namespace Botan {
20
23
24/**
25 * @brief An HSS/LMS public key.
26 *
27 * Implementation of the Hierarchical Signature System (HSS) of
28 * Leighton-Micali Hash-Based Signatures (LMS) defined in RFC 8554
29 * (https://www.rfc-editor.org/rfc/rfc8554.html).
30 *
31 * To derive seeds for single LMS trees in the HSS-multitree, the method (SECRET_METHOD 2)
32 * of the reference implementation (https://github.com/cisco/hash-sigs) is used.
33 */
34class BOTAN_PUBLIC_API(3, 5) HSS_LMS_PublicKey : public virtual Public_Key {
35 public:
36 /**
37 * @brief Load an existing public key using its bytes.
38 */
39 BOTAN_FUTURE_EXPLICIT HSS_LMS_PublicKey(std::span<const uint8_t> pub_key_bytes);
40
42 HSS_LMS_PublicKey(const HSS_LMS_PublicKey& other) = default;
46
47 size_t key_length() const override;
48
49 std::string algo_name() const override;
50
51 size_t estimated_strength() const override;
53 OID object_identifier() const override;
54 bool check_key(RandomNumberGenerator& rng, bool strong) const override;
55 std::vector<uint8_t> raw_public_key_bits() const override;
56 std::vector<uint8_t> public_key_bits() const override;
57
58 std::unique_ptr<PK_Ops::Verification> create_verification_op(std::string_view params,
59 std::string_view provider) const override;
60
61 std::unique_ptr<PK_Ops::Verification> create_x509_verification_op(const AlgorithmIdentifier& signature_algorithm,
62 std::string_view provider) const override;
63
64 bool supports_operation(PublicKeyOperation op) const override;
65
66 /**
67 * @throws Not_Implemented for LMS public keys.
68 */
69 std::unique_ptr<Private_Key> generate_another(RandomNumberGenerator& rng) const override;
70
71 protected:
72 HSS_LMS_PublicKey() = default;
73
74 std::shared_ptr<HSS_LMS_PublicKeyInternal> m_public; // NOLINT(*non-private-member-variable*)
75};
76
79
80/**
81 * @brief An HSS/LMS private key.
82 *
83 * HSS/LMS is a statefule hash-based signature scheme. This means the private key must
84 * be (securely) updated after using it for signing. Also, there is a maximal number
85 * of signatures that can be created using one HSS/LMS key pair, which depends on
86 * the number and size of LMS layers of the chosen HSS/LMS instance. For the selection
87 * of a sensible parameter set, refer to RFC 8554 6.4.
88 *
89 * The format of the HSS/LMS private key is not defined in
90 * RFC 8554. We use the following format (big endian):
91 *
92 * PrivateKey = u32str(L) || u64str(idx) ||
93 * u32str(LMS algorithm id (root layer)) || u32str(LMOTS algorithm id (root layer)) ||
94 * ... ||
95 * u32str(LMS algorithm id (bottom layer)) || u32str(LMOTS algorithm id (bottom layer)) ||
96 * HSS_SEED || HSS_Identifier
97 *
98 * L: Number of LMS layers
99 * Idx: Number of signatures already created using this private key
100 * HSS_SEED: Seed to derive LMS Seeds (see RFC 8554 Appendix A) like in SECRET_METHOD 2 of
101 * https://github.com/cisco/hash-sigs. As long as the hash functions output length.
102 * HSS_Identifier: 16 bytes long.
103 *
104 * The HSS/LMS instance to use for creating new keys is defined using an algorithm parameter sting,
105 * i.e. to define which hash function (hash), LMS tree height (h)
106 * and OTS Winternitz coefficient widths (w) to use. The syntax is the following:
107 *
108 * HSS-LMS(<hash>,HW(<h>,<w>),HW(<h>,<w>),...)
109 *
110 * e.g. 'HSS-LMS(SHA-256,HW(5,1),HW(5,1))' to use SHA-256 in a two-layer HSS instance
111 * with a LMS tree hights 5 and w=1. The following parameters are allowed (which are
112 * specified in RFC 8554 and draft-fluhrer-lms-more-parm-sets-11):
113 *
114 * hash: 'SHA-256', 'Truncated(SHA-256,192)', 'SHAKE-256(256)', SHAKE-256(192)
115 * h: '5', '10', '15', '20', '25'
116 * w: '1', '2', '4', '8'
117 *
118 * Note: The selected hash function is also used for seed derivation.
119 */
120class BOTAN_PUBLIC_API(3, 5) HSS_LMS_PrivateKey final : public virtual HSS_LMS_PublicKey,
121 public virtual Private_Key {
122 public:
123 /**
124 * @brief Load an existing LMS private key using its bytes
125 */
126 BOTAN_FUTURE_EXPLICIT HSS_LMS_PrivateKey(std::span<const uint8_t> private_key_bytes);
127
128 /**
129 * @brief Construct a new hss lms privatekey object.
130 *
131 * @param rng random number generator
132 * @param algo_params string is format 'HSS-LMS(<hash>,HW(<h>,<w>),HW(<h>,<w>),...)'
133 */
134 HSS_LMS_PrivateKey(RandomNumberGenerator& rng, std::string_view algo_params);
135
141
144 std::unique_ptr<Public_Key> public_key() const override;
145
147
148 bool stateful_operation() const override { return true; }
149
150 /**
151 * Retrieves the number of remaining signatures for this private key.
152 */
153 std::optional<uint64_t> remaining_operations() const override;
154
155 std::unique_ptr<Private_Key> generate_another(RandomNumberGenerator& rng) const override;
156
157 std::unique_ptr<PK_Ops::Signature> create_signature_op(RandomNumberGenerator& rng,
158 std::string_view params,
159 std::string_view provider) const override;
160
161 private:
162 explicit HSS_LMS_PrivateKey(std::shared_ptr<HSS_LMS_PrivateKeyInternal> sk);
163
164 std::shared_ptr<HSS_LMS_PrivateKeyInternal> m_private;
165};
166
168
169} // namespace Botan
170
171#endif
#define BOTAN_DIAGNOSTIC_POP
Definition api.h:122
#define BOTAN_DIAGNOSTIC_PUSH
Definition api.h:119
#define BOTAN_DIAGNOSTIC_IGNORE_INHERITED_VIA_DOMINANCE
Definition api.h:121
#define BOTAN_PUBLIC_API(maj, min)
Definition api.h:21
#define BOTAN_FUTURE_EXPLICIT
Definition api.h:52
The internal HSS-LMS private key.
Definition hss.h:126
An HSS/LMS private key.
Definition hss_lms.h:121
std::unique_ptr< Public_Key > public_key() const override
Definition hss_lms.cpp:149
AlgorithmIdentifier pkcs8_algorithm_identifier() const override
Definition hss_lms.cpp:156
bool stateful_operation() const override
Definition hss_lms.h:148
HSS_LMS_PrivateKey(const HSS_LMS_PrivateKey &other)=delete
secure_vector< uint8_t > raw_private_key_bits() const override
Definition hss_lms.cpp:145
HSS_LMS_PrivateKey & operator=(HSS_LMS_PrivateKey &&other)=delete
BOTAN_FUTURE_EXPLICIT HSS_LMS_PrivateKey(std::span< const uint8_t > private_key_bytes)
Load an existing LMS private key using its bytes.
Definition hss_lms.cpp:117
secure_vector< uint8_t > private_key_bits() const override
Definition hss_lms.cpp:140
HSS_LMS_PrivateKey & operator=(const HSS_LMS_PrivateKey &other)=delete
HSS_LMS_PrivateKey(HSS_LMS_PrivateKey &&other)=default
The internal HSS-LMS public key.
Definition hss.h:245
std::unique_ptr< PK_Ops::Verification > create_verification_op(std::string_view params, std::string_view provider) const override
Definition hss_lms.cpp:88
HSS_LMS_PublicKey & operator=(HSS_LMS_PublicKey &&other)=delete
std::unique_ptr< Private_Key > generate_another(RandomNumberGenerator &rng) const override
Definition hss_lms.cpp:111
size_t key_length() const override
Definition hss_lms.cpp:22
bool supports_operation(PublicKeyOperation op) const override
Definition hss_lms.cpp:107
HSS_LMS_PublicKey(const HSS_LMS_PublicKey &other)=default
std::vector< uint8_t > raw_public_key_bits() const override
Definition hss_lms.cpp:51
HSS_LMS_PublicKey(HSS_LMS_PublicKey &&other)=default
BOTAN_FUTURE_EXPLICIT HSS_LMS_PublicKey(std::span< const uint8_t > pub_key_bytes)
Load an existing public key using its bytes.
Definition hss_lms.cpp:17
std::string algo_name() const override
Definition hss_lms.cpp:34
HSS_LMS_PublicKey & operator=(const HSS_LMS_PublicKey &other)=delete
OID object_identifier() const override
Definition hss_lms.cpp:42
size_t estimated_strength() const override
Definition hss_lms.cpp:26
std::unique_ptr< PK_Ops::Verification > create_x509_verification_op(const AlgorithmIdentifier &signature_algorithm, std::string_view provider) const override
Definition hss_lms.cpp:96
bool check_key(RandomNumberGenerator &rng, bool strong) const override
Definition hss_lms.cpp:46
std::vector< uint8_t > public_key_bits() const override
Definition hss_lms.cpp:55
std::shared_ptr< HSS_LMS_PublicKeyInternal > m_public
Definition hss_lms.h:74
AlgorithmIdentifier algorithm_identifier() const override
Definition hss_lms.cpp:38
PublicKeyOperation
Definition pk_keys.h:46
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:69