9#include <botan/hss_lms.h>
12#include <botan/internal/hss.h>
13#include <botan/internal/pk_ops_impl.h>
31 return 8 *
m_public->lms_pub_key().lms_params().m() - 1;
39 return m_public->algorithm_identifier();
43 return m_public->object_identifier();
65 explicit HSS_LMS_Verification_Operation(std::shared_ptr<HSS_LMS_PublicKeyInternal> pub_key) :
66 m_public(std::move(pub_key)) {}
68 void update(std::span<const uint8_t> msg)
override {
69 m_msg_buffer.insert(m_msg_buffer.end(), msg.begin(), msg.end());
72 bool is_valid_signature(std::span<const uint8_t> sig)
override {
73 std::vector<uint8_t> message_to_verify = std::exchange(m_msg_buffer, {});
76 return m_public->verify_signature(message_to_verify, signature);
77 }
catch(
const Decoding_Error&) {
83 std::string hash_function()
const override {
return m_public->lms_pub_key().lms_params().hash_name(); }
86 std::shared_ptr<HSS_LMS_PublicKeyInternal> m_public;
87 std::vector<uint8_t> m_msg_buffer;
93 std::string_view provider)
const {
94 if(provider.empty() || provider ==
"base") {
95 return std::make_unique<HSS_LMS_Verification_Operation>(
m_public);
102 if(provider.empty() || provider ==
"base") {
104 throw Decoding_Error(
"Unexpected AlgorithmIdentifier for HSS-LMS signature");
106 return std::make_unique<HSS_LMS_Verification_Operation>(
m_public);
118 throw Not_Implemented(
"Cannot generate a new HSS/LMS keypair from a public key");
130 m_private = std::make_shared<HSS_LMS_PrivateKeyInternal>(hss_params, rng);
154 return std::make_unique<HSS_LMS_PublicKey>(*
this);
165 return m_private->remaining_operations(m_private->hss_params().max_sig_count()).get();
170 return std::unique_ptr<HSS_LMS_PrivateKey>(
171 new HSS_LMS_PrivateKey(std::make_shared<HSS_LMS_PrivateKeyInternal>(m_private->hss_params(), rng)));
178 HSS_LMS_Signature_Operation(std::shared_ptr<HSS_LMS_PrivateKeyInternal> private_key,
179 std::shared_ptr<HSS_LMS_PublicKeyInternal> public_key) :
180 m_private(std::move(private_key)), m_public(std::move(public_key)) {}
182 void update(std::span<const uint8_t> msg)
override {
183 m_msg_buffer.insert(m_msg_buffer.end(), msg.begin(), msg.end());
186 std::vector<uint8_t> sign(RandomNumberGenerator& )
override {
187 std::vector<uint8_t> message_to_sign = std::exchange(m_msg_buffer, {});
192 size_t signature_length()
const override {
return m_private->signature_size(); }
194 AlgorithmIdentifier algorithm_identifier()
const override {
return m_public->algorithm_identifier(); }
196 std::string hash_function()
const override {
return m_public->lms_pub_key().lms_params().hash_name(); }
199 std::shared_ptr<HSS_LMS_PrivateKeyInternal> m_private;
200 std::shared_ptr<HSS_LMS_PublicKeyInternal> m_public;
201 std::vector<uint8_t> m_msg_buffer;
207 std::string_view params,
208 std::string_view provider)
const {
210 BOTAN_ARG_CHECK(params.empty(),
"Unexpected parameters for signing with HSS-LMS");
212 if(provider.empty() || provider ==
"base") {
213 return std::make_unique<HSS_LMS_Signature_Operation>(m_private,
m_public);
#define BOTAN_ARG_CHECK(expr, msg)
static std::shared_ptr< HSS_LMS_PrivateKeyInternal > from_bytes_or_throw(std::span< const uint8_t > key_bytes)
Parse a private HSS-LMS key.
std::unique_ptr< Public_Key > public_key() const override
AlgorithmIdentifier pkcs8_algorithm_identifier() const override
std::unique_ptr< Private_Key > generate_another(RandomNumberGenerator &rng) const override
secure_vector< uint8_t > raw_private_key_bits() const override
std::optional< uint64_t > remaining_operations() const override
BOTAN_FUTURE_EXPLICIT HSS_LMS_PrivateKey(std::span< const uint8_t > private_key_bytes)
Load an existing LMS private key using its bytes.
~HSS_LMS_PrivateKey() override
secure_vector< uint8_t > private_key_bits() const override
std::unique_ptr< PK_Ops::Signature > create_signature_op(RandomNumberGenerator &rng, std::string_view params, std::string_view provider) const override
The internal HSS-LMS public key.
static HSS_LMS_PublicKeyInternal create(const HSS_LMS_PrivateKeyInternal &hss_sk)
Create the public HSS-LMS key from its private key.
std::unique_ptr< PK_Ops::Verification > create_verification_op(std::string_view params, std::string_view provider) const override
std::unique_ptr< Private_Key > generate_another(RandomNumberGenerator &rng) const override
size_t key_length() const override
~HSS_LMS_PublicKey() override
bool supports_operation(PublicKeyOperation op) const override
std::vector< uint8_t > raw_public_key_bits() const override
HSS_LMS_PublicKey()=default
std::string algo_name() const override
OID object_identifier() const override
size_t estimated_strength() const override
std::unique_ptr< PK_Ops::Verification > create_x509_verification_op(const AlgorithmIdentifier &signature_algorithm, std::string_view provider) const override
bool check_key(RandomNumberGenerator &rng, bool strong) const override
std::vector< uint8_t > public_key_bits() const override
std::shared_ptr< HSS_LMS_PublicKeyInternal > m_public
AlgorithmIdentifier algorithm_identifier() const override
static HSS_Signature from_bytes_or_throw(std::span< const uint8_t > sig_bytes)
Parse a HSS-LMS signature.
static OID from_string(std::string_view str)
decltype(auto) driveby_unpoison(T &&v)
constexpr auto scoped_poison(const Ts &... xs)
constexpr void unpoison(const T *p, size_t n)
std::vector< T, secure_allocator< T > > secure_vector