Coverage Report

Created: 2025-04-11 06:34

/src/botan/build/include/internal/botan/internal/xmss_signature_operation.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * XMSS Signature Operation
3
 * (C) 2016,2017,2018 Matthias Gierlings
4
 *
5
 * Botan is released under the Simplified BSD License (see license.txt)
6
 **/
7
8
#ifndef BOTAN_XMSS_SIGNATURE_OPERATION_H_
9
#define BOTAN_XMSS_SIGNATURE_OPERATION_H_
10
11
#include <botan/pk_ops.h>
12
#include <botan/xmss.h>
13
#include <botan/internal/xmss_address.h>
14
#include <botan/internal/xmss_signature.h>
15
#include <botan/internal/xmss_wots.h>
16
17
namespace Botan {
18
19
/**
20
 * Signature generation operation for Extended Hash-Based Signatures (XMSS) as
21
 * defined in:
22
 *
23
 * [1] XMSS: Extended Hash-Based Signatures,
24
 *     Request for Comments: 8391
25
 *     Release: May 2018.
26
 *     https://datatracker.ietf.org/doc/rfc8391/
27
 **/
28
class XMSS_Signature_Operation final : public virtual PK_Ops::Signature {
29
   public:
30
      XMSS_Signature_Operation(const XMSS_PrivateKey& private_key);
31
32
      /**
33
       * Creates an XMSS signature for the message provided through call to
34
       * update().
35
       *
36
       * @return serialized XMSS signature.
37
       **/
38
      std::vector<uint8_t> sign(RandomNumberGenerator&) override;
39
40
      void update(std::span<const uint8_t> input) override;
41
42
      size_t signature_length() const override;
43
44
      AlgorithmIdentifier algorithm_identifier() const override;
45
46
0
      std::string hash_function() const override { return m_hash.hash_function(); }
47
48
   private:
49
      /**
50
       * Algorithm 11: "treeSig"
51
       * Generate a WOTS+ signature on a message with corresponding auth path.
52
       *
53
       * @param msg A message.
54
       * @param xmss_priv_key A XMSS private key.
55
       * @param adrs A XMSS Address.
56
       **/
57
      XMSS_Signature::TreeSignature generate_tree_signature(const secure_vector<uint8_t>& msg,
58
                                                            XMSS_PrivateKey& xmss_priv_key,
59
                                                            XMSS_Address& adrs);
60
61
      /**
62
       * Algorithm 12: "XMSS_sign"
63
       * Generate an XMSS signature and update the XMSS secret key
64
       *
65
       * @param msg A message to sign of arbitrary length.
66
       * @param [out] xmss_priv_key A XMSS private key. The private key will be
67
       *              updated during the signing process.
68
       *
69
       * @return The signature of msg signed using xmss_priv_key.
70
       **/
71
      XMSS_Signature sign(const secure_vector<uint8_t>& msg, XMSS_PrivateKey& xmss_priv_key);
72
73
      wots_keysig_t build_auth_path(XMSS_PrivateKey& priv_key, XMSS_Address& adrs);
74
75
      void initialize();
76
77
      XMSS_PrivateKey m_priv_key;
78
      XMSS_Hash m_hash;
79
      secure_vector<uint8_t> m_randomness;
80
      uint32_t m_leaf_idx;
81
      bool m_is_initialized;
82
};
83
84
}  // namespace Botan
85
86
#endif