Botan 3.11.0
Crypto and TLS for C&
xmss_signature.h
Go to the documentation of this file.
1/*
2 * XMSS Signature
3 * (C) 2016 Matthias Gierlings
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 **/
7
8#ifndef BOTAN_XMSS_SIGNATURE_H_
9#define BOTAN_XMSS_SIGNATURE_H_
10
11#include <botan/exceptn.h>
12#include <botan/secmem.h>
13#include <botan/types.h>
14#include <botan/xmss_parameters.h>
15#include <botan/internal/xmss_wots.h>
16
17namespace Botan {
18
19/**
20 * Helper class for marshalling an XMSS signature
21 */
22class XMSS_Signature final {
23 public:
29
30 public:
31 /**
32 * Creates a signature from an XMSS signature method and a uint8_t sequence
33 * representing a raw signature.
34 *
35 * @param oid XMSS signature method
36 * @param raw_sig An XMSS signature serialized using
37 * XMSS_Signature::bytes().
38 **/
39 XMSS_Signature(XMSS_Parameters::xmss_algorithm_t oid, std::span<const uint8_t> raw_sig);
40
41 /**
42 * Creates an XMSS Signature from a leaf index used for signature
43 * generation, a random value and a tree signature.
44 *
45 * @param leaf_idx Leaf index used to generate the signature.
46 * @param randomness A random value.
47 * @param tree_sig A tree signature.
48 **/
50 m_leaf_idx(leaf_idx), m_randomness(std::move(randomness)), m_tree_sig(std::move(tree_sig)) {}
51
52 size_t unused_leaf_index() const { return m_leaf_idx; }
53
54 const secure_vector<uint8_t>& randomness() const { return m_randomness; }
55
56 const XMSS_Signature::TreeSignature& tree() const { return m_tree_sig; }
57
58 // These mutating operations should be removed:
59 void set_unused_leaf_idx(size_t idx) { m_leaf_idx = idx; }
60
61 secure_vector<uint8_t>& randomness() { return m_randomness; }
62
63 void set_randomness(secure_vector<uint8_t> randomness) { m_randomness = std::move(randomness); }
64
65 XMSS_Signature::TreeSignature& tree() { return m_tree_sig; }
66
67 void set_tree(XMSS_Signature::TreeSignature tree_sig) { m_tree_sig = std::move(tree_sig); }
68
69 /**
70 * Generates a serialized representation of XMSS Signature by
71 * concatenating the following elements in order:
72 * 4-byte leaf index, n-bytes randomness, ots_signature,
73 * authentication path.
74 *
75 * n is the element_size(), len equal to len(), h the tree height
76 * defined by the chosen XMSS signature method.
77 *
78 * @return serialized signature, a sequence of
79 * 4+(len + h + 1)n bytes.
80 **/
81 std::vector<uint8_t> bytes() const;
82
83 private:
84 size_t m_leaf_idx;
85 secure_vector<uint8_t> m_randomness;
87};
88
89} // namespace Botan
90
91#endif
void set_unused_leaf_idx(size_t idx)
void set_tree(XMSS_Signature::TreeSignature tree_sig)
const XMSS_Signature::TreeSignature & tree() const
XMSS_Signature(size_t leaf_idx, secure_vector< uint8_t > randomness, XMSS_Signature::TreeSignature tree_sig)
secure_vector< uint8_t > & randomness()
XMSS_Signature(XMSS_Parameters::xmss_algorithm_t oid, std::span< const uint8_t > raw_sig)
const secure_vector< uint8_t > & randomness() const
std::vector< uint8_t > bytes() const
size_t unused_leaf_index() const
XMSS_Signature::TreeSignature & tree()
void set_randomness(secure_vector< uint8_t > randomness)
std::vector< secure_vector< uint8_t > > wots_keysig_t
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:68