Botan 3.14.1
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_common_ops.h>
16#include <botan/internal/xmss_wots.h>
17
18namespace Botan {
19
20/**
21 * Helper class for marshalling an XMSS signature
22 */
23class XMSS_Signature final {
24 public:
26
27 public:
28 /**
29 * Creates a signature from an XMSS signature method and a uint8_t sequence
30 * representing a raw signature.
31 *
32 * @param oid XMSS signature method
33 * @param raw_sig An XMSS signature serialized using
34 * XMSS_Signature::bytes().
35 **/
36 XMSS_Signature(XMSS_Parameters::xmss_algorithm_t oid, std::span<const uint8_t> raw_sig);
37
38 /**
39 * Creates an XMSS Signature from a leaf index used for signature
40 * generation, a random value and a tree signature.
41 *
42 * @param leaf_idx Leaf index used to generate the signature.
43 * @param randomness A random value.
44 * @param tree_sig A tree signature.
45 **/
47 m_leaf_idx(leaf_idx), m_randomness(std::move(randomness)), m_tree_sig(std::move(tree_sig)) {}
48
49 size_t unused_leaf_index() const { return m_leaf_idx; }
50
51 const secure_vector<uint8_t>& randomness() const { return m_randomness; }
52
53 const XMSS_Signature::TreeSignature& tree() const { return m_tree_sig; }
54
55 // These mutating operations should be removed:
56 void set_unused_leaf_idx(size_t idx) { m_leaf_idx = idx; }
57
58 secure_vector<uint8_t>& randomness() { return m_randomness; }
59
60 void set_randomness(secure_vector<uint8_t> randomness) { m_randomness = std::move(randomness); }
61
62 XMSS_Signature::TreeSignature& tree() { return m_tree_sig; }
63
64 void set_tree(XMSS_Signature::TreeSignature tree_sig) { m_tree_sig = std::move(tree_sig); }
65
66 /**
67 * Generates a serialized representation of XMSS Signature by
68 * concatenating the following elements in order:
69 * 4-byte leaf index, n-bytes randomness, ots_signature,
70 * authentication path.
71 *
72 * n is the element_size(), len equal to len(), h the tree height
73 * defined by the chosen XMSS signature method.
74 *
75 * @return serialized signature, a sequence of
76 * 4+(len + h + 1)n bytes.
77 **/
78 std::vector<uint8_t> bytes() const;
79
80 private:
81 size_t m_leaf_idx;
82 secure_vector<uint8_t> m_randomness;
84};
85
86} // namespace Botan
87
88#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
XMSS_TreeSignature TreeSignature
size_t unused_leaf_index() const
XMSS_Signature::TreeSignature & tree()
void set_randomness(secure_vector< uint8_t > randomness)
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:128