8#ifndef BOTAN_XMSS_WOTS_H_
9#define BOTAN_XMSS_WOTS_H_
11#include <botan/asn1_obj.h>
12#include <botan/exceptn.h>
13#include <botan/pk_keys.h>
15#include <botan/secmem.h>
16#include <botan/xmss_hash.h>
37 WOTSP_SHA2_256 = 0x00000001,
38 WOTSP_SHA2_512 = 0x00000002,
39 WOTSP_SHAKE_256 = 0x00000003,
40 WOTSP_SHAKE_512 = 0x00000004
46 static ots_algorithm_t xmss_wots_id_from_string(
const std::string& param_set);
65 const std::string&
name()
const
95 size_t len()
const {
return m_len; }
97 size_t len_1()
const {
return m_len_1; }
99 size_t len_2()
const {
return m_len_2; }
101 size_t lg_w()
const {
return m_lg_w; }
109 return m_oid == p.m_oid;
113 static const std::map<std::string, ots_algorithm_t> m_oid_name_lut;
114 ots_algorithm_t m_oid;
116 std::string m_hash_name;
117 size_t m_element_size;
144 : m_ots_sig(
std::move(ots_sig)),
145 m_auth_path(
std::move(auth_path))
182 : m_wots_params(oid),
183 m_hash(m_wots_params.hash_function_name()) {}
196 : m_wots_params(oid),
197 m_hash(m_wots_params.hash_function_name()),
198 m_public_seed(rng.random_vec(m_wots_params.element_size())) {}
209 : m_wots_params(oid),
210 m_hash(m_wots_params.hash_function_name()),
211 m_public_seed(
std::move(public_seed)) {}
226 : m_wots_params(oid),
227 m_hash(m_wots_params.hash_function_name()),
228 m_key(
std::move(key)),
229 m_public_seed(
std::move(public_seed))
248 : m_wots_params(oid),
249 m_hash(m_wots_params.hash_function_name()),
250 m_key(pub_key_from_signature(msg,
254 m_public_seed(public_seed)
285 m_public_seed = std::move(public_seed);
294 m_key = std::move(key_data);
299 return m_wots_params;
304 return m_wots_params.name();
309 throw Not_Implemented(
"No AlgorithmIdentifier available for XMSS-WOTS.");
319 return m_wots_params.estimated_strength();
324 return m_wots_params.estimated_strength();
334 return m_key == key.
m_key;
339 return !(*
this == key);
390 chain(x, start_idx, steps, adrs, public_seed, m_hash);
444 m_private_seed(rng.random_vec(m_wots_params.element_size()))
446 set_key_data(generate(m_private_seed));
465 m_private_seed(rng.random_vec(m_wots_params.element_size()))
467 set_key_data(generate(m_private_seed));
500 m_private_seed(
std::move(private_seed))
502 set_key_data(generate(private_seed));
507 throw Not_Implemented(
"Not possible to derive WOTS public key from private key");
536 return this->at(i, m_hash);
557 return this->at(adrs, m_hash);
612 generate_public_key(pub_key, std::move(in_key_data), adrs, m_hash);
628 return sign(msg, adrs, m_hash);
659 return m_private_seed;
670 m_private_seed = std::move(private_seed);
676 throw Not_Implemented(
"No AlgorithmIdentifier available for XMSS-WOTS.");
704 return generate(private_seed, m_hash);
707 secure_vector<uint8_t> m_private_seed;
size_t wots_parameter() const
const std::string & hash_function_name() const
size_t element_size() const
ots_algorithm_t oid() const
size_t estimated_strength() const
const std::string & name() const
bool operator==(const XMSS_WOTS_Parameters &p) const
const secure_vector< uint8_t > & private_seed() const
wots_keysig_t generate_private_key(const secure_vector< uint8_t > &priv_seed)
XMSS_WOTS_PrivateKey(XMSS_WOTS_Parameters::ots_algorithm_t oid)
secure_vector< uint8_t > private_key_bits() const override
void generate_public_key(XMSS_WOTS_PublicKey &pub_key, wots_keysig_t in_key_data, XMSS_Address &adrs)
wots_keysig_t operator[](const XMSS_Address &adrs)
wots_keysig_t sign(const secure_vector< uint8_t > &msg, XMSS_Address &adrs)
XMSS_WOTS_PrivateKey(XMSS_WOTS_Parameters::ots_algorithm_t oid, secure_vector< uint8_t > public_seed, RandomNumberGenerator &rng)
AlgorithmIdentifier pkcs8_algorithm_identifier() const override
XMSS_WOTS_PrivateKey(XMSS_WOTS_Parameters::ots_algorithm_t oid, RandomNumberGenerator &rng)
wots_keysig_t operator[](size_t i)
std::unique_ptr< Public_Key > public_key() const override
XMSS_WOTS_PrivateKey(XMSS_WOTS_Parameters::ots_algorithm_t oid, secure_vector< uint8_t > public_seed, secure_vector< uint8_t > private_seed)
XMSS_WOTS_PrivateKey(XMSS_WOTS_Parameters::ots_algorithm_t oid, secure_vector< uint8_t > public_seed)
void set_private_seed(secure_vector< uint8_t > private_seed)
wots_keysig_t & ots_signature()
const wots_keysig_t & ots_signature() const
const wots_keysig_t & authentication_path() const
TreeSignature(wots_keysig_t ots_sig, wots_keysig_t auth_path)
wots_keysig_t & authentication_path()
XMSS_WOTS_PublicKey(XMSS_WOTS_Parameters::ots_algorithm_t oid, secure_vector< uint8_t > public_seed, wots_keysig_t key)
XMSS_WOTS_Parameters m_wots_params
const secure_vector< uint8_t > & public_seed() const
const wots_keysig_t & key_data() const
const XMSS_WOTS_Parameters & wots_parameters() const
const secure_vector< uint8_t > & operator[](size_t i) const
XMSS_WOTS_PublicKey(XMSS_WOTS_Parameters::ots_algorithm_t oid, RandomNumberGenerator &rng)
secure_vector< uint8_t > m_public_seed
void set_public_seed(secure_vector< uint8_t > public_seed)
size_t key_length() const override
void chain(secure_vector< uint8_t > &x, size_t start_idx, size_t steps, XMSS_Address &adrs, const secure_vector< uint8_t > &public_seed)
XMSS_WOTS_PublicKey(XMSS_WOTS_Parameters::ots_algorithm_t oid, const secure_vector< uint8_t > &msg, const wots_keysig_t &sig, XMSS_Address &adrs, const secure_vector< uint8_t > &public_seed)
size_t estimated_strength() const override
wots_keysig_t & key_data()
XMSS_WOTS_PublicKey(XMSS_WOTS_Parameters::ots_algorithm_t oid)
bool operator==(const XMSS_WOTS_PublicKey &key)
void set_key_data(wots_keysig_t key_data)
std::vector< uint8_t > public_key_bits() const override
XMSS_WOTS_PublicKey(XMSS_WOTS_Parameters::ots_algorithm_t oid, secure_vector< uint8_t > public_seed)
AlgorithmIdentifier algorithm_identifier() const override
bool check_key(RandomNumberGenerator &, bool) const override
std::string algo_name() const override
bool operator!=(const XMSS_WOTS_PublicKey &key)
secure_vector< uint8_t > & public_seed()
secure_vector< uint8_t > & operator[](size_t i)
int(* final)(unsigned char *, CTX *)
#define BOTAN_PUBLIC_API(maj, min)
std::vector< secure_vector< uint8_t > > wots_keysig_t
std::vector< T, secure_allocator< T > > secure_vector