• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

randombit / botan / 19012754211

02 Nov 2025 01:10PM UTC coverage: 90.677% (+0.006%) from 90.671%
19012754211

push

github

web-flow
Merge pull request #5137 from randombit/jack/clang-tidy-includes

Remove various unused includes flagged by clang-tidy misc-include-cleaner

100457 of 110786 relevant lines covered (90.68%)

12189873.8 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.0
/src/tests/test_sphincsplus_wots.cpp
1
/*
2
* (C) 2023 Jack Lloyd
3
*     2023 Fabian Albert, René Meusel, Amos Treiber - Rohde & Schwarz Cybersecurity
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7

8
#include "tests.h"
9

10
#if defined(BOTAN_HAS_SPHINCS_PLUS_COMMON)
11

12
   #include <botan/assert.h>
13
   #include <botan/hash.h>
14
   #include <botan/sp_parameters.h>
15
   #include <botan/internal/loadstor.h>
16
   #include <botan/internal/sp_address.h>
17
   #include <botan/internal/sp_hash.h>
18
   #include <botan/internal/sp_wots.h>
19

20
namespace Botan_Tests {
21

22
class SPHINCS_Plus_WOTS_Test final : public Text_Based_Test {
×
23
   private:
24
      static std::pair<Botan::Sphincs_Address, Botan::TreeNodeIndex> read_address_and_leaf_idx(
12✔
25
         std::span<const uint8_t> address_buffer) {
26
         BOTAN_ASSERT_NOMSG(address_buffer.size() == 32);
12✔
27

28
         std::array<uint32_t, 8> adrs{};
12✔
29
         for(size_t i = 0; i < 8; ++i) {
108✔
30
            adrs[i] = Botan::load_be<uint32_t>(address_buffer.data(), i);
96✔
31
         }
32

33
         return std::make_pair(Botan::Sphincs_Address(adrs), Botan::TreeNodeIndex(adrs[5]));
12✔
34
      }
35

36
   public:
37
      SPHINCS_Plus_WOTS_Test() :
1✔
38
            Text_Based_Test("pubkey/sphincsplus_wots.vec",
39
                            "SphincsParameterSet,Address,SecretSeed,PublicSeed,HashedWotsPk,Msg,HashedWotsSig") {}
2✔
40

41
      bool skip_this_test(const std::string& /*header*/, const VarMap& vars) override {
12✔
42
         [[maybe_unused]] auto params = Botan::Sphincs_Parameters::create(vars.get_req_str("SphincsParameterSet"));
24✔
43
         return !params.is_available();
12✔
44
      }
45

46
      Test::Result run_one_test(const std::string& /*header*/, const VarMap& vars) final {
12✔
47
         Test::Result result("SLH-DSA's WOTS+");
12✔
48

49
         auto params = Botan::Sphincs_Parameters::create(vars.get_req_str("SphincsParameterSet"));
24✔
50

51
         auto [address, leaf_idx] = read_address_and_leaf_idx(vars.get_req_bin("Address"));
24✔
52
         const auto secret_seed = Botan::SphincsSecretSeed(vars.get_req_bin("SecretSeed"));
24✔
53
         const auto public_seed = Botan::SphincsPublicSeed(vars.get_req_bin("PublicSeed"));
12✔
54
         auto hashed_pk_ref = Botan::SphincsTreeNode(vars.get_req_bin("HashedWotsPk"));
12✔
55
         const auto root_to_sign = Botan::SphincsTreeNode(vars.get_req_bin("Msg"));
12✔
56
         const auto hashed_wots_sig_ref = Botan::WotsSignature(vars.get_req_bin("HashedWotsSig"));
24✔
57

58
         auto hashes = Botan::Sphincs_Hash_Functions::create(params, public_seed);
12✔
59

60
         // Depending on the SLH-DSA's configuration the resulting WOTS+ signature is
61
         // hashed either with SHA-3 or SHA-256 to reduce the inner dependencies
62
         // on other hash function modules.
63
         auto hash_algo_spec = [&]() -> std::string {
×
64
            if(params.hash_type() == Botan::Sphincs_Hash_Type::Shake256) {
12✔
65
               return "SHA-3(256)";
6✔
66
            } else {
67
               return "SHA-256";
6✔
68
            }
69
         }();
12✔
70
         auto hash = Botan::HashFunction::create(hash_algo_spec);
12✔
71

72
         if(!hash) {
12✔
73
            result.test_note("Skipping due to missing hash function");
×
74
            return result;
×
75
         }
76

77
         // Addresses used for signing
78
         auto leaf_addr = Botan::Sphincs_Address::as_subtree_from(address);
12✔
79
         auto pk_addr_sign_and_pkgen = Botan::Sphincs_Address::as_subtree_from(address).set_type(
12✔
80
            Botan::Sphincs_Address_Type::WotsPublicKeyCompression);
12✔
81

82
         // Address used for hashing the WOTS+ public key
83
         auto pk_addr_pk_from_sig = Botan::Sphincs_Address::as_subtree_from(address).set_type(
12✔
84
            Botan::Sphincs_Address_Type::WotsPublicKeyCompression);
12✔
85
         pk_addr_pk_from_sig.set_keypair_address(leaf_idx);
12✔
86

87
         // Prepare the message
88
         auto wots_steps = Botan::chain_lengths(root_to_sign, params);
12✔
89

90
         // Test: WOTS+ Signature and Public Key Generation
91
         Botan::WotsSignature sig_out(params.n() * params.wots_len());
12✔
92
         Botan::SphincsTreeNode hashed_pk_out(params.n());
12✔
93
         wots_sign_and_pkgen(Botan::StrongSpan<Botan::WotsSignature>(sig_out),
12✔
94
                             Botan::StrongSpan<Botan::SphincsTreeNode>(hashed_pk_out),
95
                             secret_seed,
96
                             leaf_idx,
97
                             leaf_idx,
98
                             wots_steps,
99
                             leaf_addr,
100
                             pk_addr_sign_and_pkgen,
101
                             params,
102
                             *hashes);
12✔
103

104
         result.test_is_eq("WOTS+ signature generation", hash->process(sig_out), hashed_wots_sig_ref.get());
24✔
105
         result.test_is_eq("WOTS+ public key generation", hashed_pk_out, hashed_pk_ref);
12✔
106

107
         // Test: Create PK from signature (Verification)
108
         Botan::WotsPublicKey wots_pk_from_sig =
12✔
109
            Botan::wots_public_key_from_signature(root_to_sign, sig_out, address, params, *hashes);
12✔
110

111
         // The WOTS+ PK is hashed like for creating a leaf.
112
         result.test_is_eq("WOTS+ public key from signature",
24✔
113
                           hashes->T<Botan::SphincsTreeNode>(pk_addr_pk_from_sig, wots_pk_from_sig),
12✔
114
                           hashed_pk_ref);
115

116
         return result;
12✔
117
      }
132✔
118
};
119

120
BOTAN_REGISTER_TEST("pubkey", "sphincsplus_wots", SPHINCS_Plus_WOTS_Test);
121

122
}  // namespace Botan_Tests
123

124
#endif  // BOTAN_HAS_SPHINCS_PLUS_COMMON
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc