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 <cstddef> 12 #include <botan/exceptn.h> 13 #include <botan/types.h> 14 #include <botan/secmem.h> 15 #include <botan/xmss_parameters.h> 16 #include <botan/xmss_wots.h> 17 18 namespace Botan { 19 20 class XMSS_Signature final 21 { 22 public: 23 /** 24 * Creates a signature from an XMSS signature method and a uint8_t sequence 25 * representing a raw signature. 26 * 27 * @param oid XMSS signature method 28 * @param raw_sig An XMSS signature serialized using 29 * XMSS_Signature::bytes(). 30 **/ 31 XMSS_Signature(XMSS_Parameters::xmss_algorithm_t oid, 32 const secure_vector<uint8_t>& raw_sig); 33 34 /** 35 * Creates an XMSS Signature from a leaf index used for signature 36 * generation, a random value and a tree signature. 37 * 38 * @param leaf_idx Leaf index used to generate the signature. 39 * @param randomness A random value. 40 * @param tree_sig A tree signature. 41 **/ XMSS_Signature(size_t leaf_idx,const secure_vector<uint8_t> & randomness,const XMSS_WOTS_PublicKey::TreeSignature & tree_sig)42 XMSS_Signature(size_t leaf_idx, 43 const secure_vector<uint8_t>& randomness, 44 const XMSS_WOTS_PublicKey::TreeSignature& tree_sig) 45 : m_leaf_idx(leaf_idx), m_randomness(randomness), 46 m_tree_sig(tree_sig) {} 47 48 /** 49 * Creates an XMSS Signature from a leaf index used for signature 50 * generation, a random value and a tree signature. 51 * 52 * @param leaf_idx Leaf index used to generate the signature. 53 * @param randomness A random value. 54 * @param tree_sig A tree signature. 55 **/ XMSS_Signature(size_t leaf_idx,secure_vector<uint8_t> && randomness,XMSS_WOTS_PublicKey::TreeSignature && tree_sig)56 XMSS_Signature(size_t leaf_idx, 57 secure_vector<uint8_t>&& randomness, 58 XMSS_WOTS_PublicKey::TreeSignature&& tree_sig) 59 : m_leaf_idx(leaf_idx), m_randomness(std::move(randomness)), 60 m_tree_sig(std::move(tree_sig)) {} 61 unused_leaf_index()62 size_t unused_leaf_index() const { return m_leaf_idx; } set_unused_leaf_idx(size_t idx)63 void set_unused_leaf_idx(size_t idx) { m_leaf_idx = idx; } 64 randomness()65 const secure_vector<uint8_t> randomness() const 66 { 67 return m_randomness; 68 } 69 randomness()70 secure_vector<uint8_t>& randomness() 71 { 72 return m_randomness; 73 } 74 set_randomness(const secure_vector<uint8_t> & randomness)75 void set_randomness(const secure_vector<uint8_t>& randomness) 76 { 77 m_randomness = randomness; 78 } 79 set_randomness(secure_vector<uint8_t> && randomness)80 void set_randomness(secure_vector<uint8_t>&& randomness) 81 { 82 m_randomness = std::move(randomness); 83 } 84 tree()85 const XMSS_WOTS_PublicKey::TreeSignature& tree() const 86 { 87 return m_tree_sig; 88 } 89 tree()90 XMSS_WOTS_PublicKey::TreeSignature& tree() 91 { 92 return m_tree_sig; 93 } 94 set_tree(const XMSS_WOTS_PublicKey::TreeSignature & tree_sig)95 void set_tree(const XMSS_WOTS_PublicKey::TreeSignature& tree_sig) 96 { 97 m_tree_sig = tree_sig; 98 } 99 set_tree(XMSS_WOTS_PublicKey::TreeSignature && tree_sig)100 void set_tree(XMSS_WOTS_PublicKey::TreeSignature&& tree_sig) 101 { 102 m_tree_sig = std::move(tree_sig); 103 } 104 105 /** 106 * Generates a serialized representation of XMSS Signature by 107 * concatenating the following elements in order: 108 * 4-byte leaf index, n-bytes randomness, ots_signature, 109 * authentication path. 110 * 111 * n is the element_size(), len equal to len(), h the tree height 112 * defined by the chosen XMSS signature method. 113 * 114 * @return serialized signature, a sequence of 115 * 4+(len + h + 1)n bytes. 116 **/ 117 secure_vector<uint8_t> bytes() const; 118 119 private: 120 size_t m_leaf_idx; 121 secure_vector<uint8_t> m_randomness; 122 XMSS_WOTS_PublicKey::TreeSignature m_tree_sig; 123 }; 124 125 } 126 127 #endif 128