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>
32 if(raw_key.size() < 4) {
33 throw Decoding_Error(
"XMSS signature OID missing.");
38 for(
size_t i = 0; i < 4; i++) {
39 raw_id = ((raw_id << 8) | raw_key[i]);
46std::vector<uint8_t> extract_raw_public_key(std::span<const uint8_t> key_bits) {
47 std::vector<uint8_t> raw_key;
49 DataSource_Memory src(key_bits);
55 XMSS_Parameters params(deserialize_xmss_oid(raw_key));
56 if(raw_key.size() != params.raw_public_key_size() && raw_key.size() != params.raw_private_key_size() &&
57 raw_key.size() != params.raw_legacy_private_key_size()) {
58 throw Decoding_Error(
"unpacked XMSS key does not have the correct length");
60 }
catch(Decoding_Error&) {
61 raw_key.assign(key_bits.begin(), key_bits.end());
62 }
catch(Not_Implemented&) {
63 raw_key.assign(key_bits.begin(), key_bits.end());
72 m_xmss_params(xmss_oid),
73 m_wots_params(m_xmss_params.ots_oid()),
74 m_root(m_xmss_params.element_size()),
75 m_public_seed(rng.random_vec(m_xmss_params.element_size())) {}
78 m_raw_key(extract_raw_public_key(key_bits)),
79 m_xmss_params(deserialize_xmss_oid(m_raw_key)),
80 m_wots_params(m_xmss_params.ots_oid()) {
82 throw Decoding_Error(
"Invalid XMSS public key size detected");
95 m_xmss_params(xmss_oid),
96 m_wots_params(m_xmss_params.ots_oid()),
97 m_root(std::move(
root)),
98 m_public_seed(std::move(public_seed)) {
104 std::string_view provider)
const {
105 if(provider ==
"base" || provider.empty()) {
106 return std::make_unique<XMSS_Verification_Operation>(*
this);
112 std::string_view provider)
const {
113 if(provider ==
"base" || provider.empty()) {
115 throw Decoding_Error(
"Unexpected AlgorithmIdentifier for XMSS X509 signature");
117 return std::make_unique<XMSS_Verification_Operation>(*
this);
127 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)