17#include <botan/xmss.h>
19#include <botan/ber_dec.h>
20#include <botan/der_enc.h>
21#include <botan/internal/loadstor.h>
22#include <botan/internal/stl_util.h>
23#include <botan/internal/xmss_verification_operation.h>
30 if(raw_key.size() < 4) {
31 throw Decoding_Error(
"XMSS signature OID missing.");
36 for(
size_t i = 0; i < 4; i++) {
37 raw_id = ((raw_id << 8) | raw_key[i]);
44std::vector<uint8_t> extract_raw_public_key(std::span<const uint8_t> key_bits) {
45 std::vector<uint8_t> raw_key;
47 DataSource_Memory src(key_bits);
53 XMSS_Parameters params(deserialize_xmss_oid(raw_key));
54 if(raw_key.size() != params.raw_public_key_size() && raw_key.size() != params.raw_private_key_size() &&
55 raw_key.size() != params.raw_legacy_private_key_size()) {
56 throw Decoding_Error(
"unpacked XMSS key does not have the correct length");
58 }
catch(Decoding_Error&) {
59 raw_key.assign(key_bits.begin(), key_bits.end());
60 }
catch(Not_Implemented&) {
61 raw_key.assign(key_bits.begin(), key_bits.end());
70 m_xmss_params(xmss_oid),
71 m_wots_params(m_xmss_params.ots_oid()),
72 m_root(m_xmss_params.element_size()),
73 m_public_seed(rng.random_vec(m_xmss_params.element_size())) {}
76 m_raw_key(extract_raw_public_key(key_bits)),
77 m_xmss_params(deserialize_xmss_oid(m_raw_key)),
78 m_wots_params(m_xmss_params.ots_oid()) {
80 throw Decoding_Error(
"Invalid XMSS public key size detected");
93 m_xmss_params(xmss_oid),
94 m_wots_params(m_xmss_params.ots_oid()),
95 m_root(std::move(
root)),
96 m_public_seed(std::move(public_seed)) {
102 std::string_view provider)
const {
103 if(provider ==
"base" || provider.empty()) {
104 return std::make_unique<XMSS_Verification_Operation>(*
this);
110 std::string_view provider)
const {
111 if(provider ==
"base" || provider.empty()) {
113 throw Decoding_Error(
"Unexpected AlgorithmIdentifier for XMSS X509 signature");
115 return std::make_unique<XMSS_Verification_Operation>(*
this);
125 std::vector<uint8_t> output;
#define BOTAN_ARG_CHECK(expr, msg)
void skip(const size_t count)
DER_Encoder & encode(bool b)
size_t raw_public_key_size() const
xmss_algorithm_t oid() const
size_t element_size() const
std::unique_ptr< PK_Ops::Verification > create_x509_verification_op(const AlgorithmIdentifier &alg_id, std::string_view provider) const override
secure_vector< uint8_t > m_root
std::vector< uint8_t > public_key_bits() const override
std::vector< uint8_t > raw_public_key_bits() const override
secure_vector< uint8_t > m_public_seed
XMSS_Parameters m_xmss_params
std::vector< uint8_t > m_raw_key
std::vector< uint8_t > raw_public_key() const
std::unique_ptr< Private_Key > generate_another(RandomNumberGenerator &rng) const final
std::string algo_name() const override
AlgorithmIdentifier algorithm_identifier() const override
XMSS_PublicKey(XMSS_Parameters::xmss_algorithm_t xmss_oid, RandomNumberGenerator &rng)
std::unique_ptr< PK_Ops::Verification > create_verification_op(std::string_view params, std::string_view provider) const override
Gf448Elem root(const Gf448Elem &elem)
Compute the root of elem in the field.
constexpr auto concat(Rs &&... ranges)
std::vector< T, secure_allocator< T > > secure_vector
constexpr auto store_be(ParamTs &&... params)