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

randombit / botan / 11331525401

14 Oct 2024 04:29PM UTC coverage: 91.093% (-0.03%) from 91.12%
11331525401

Pull #4291

github

web-flow
Merge f5ffe99f5 into ed74c9542
Pull Request #4291: PQC: SLH-DSA

90346 of 99180 relevant lines covered (91.09%)

9678761.99 hits per line

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

94.29
/src/tests/test_sphincsplus_fors.cpp
1
/*
2
* (C) 2023 Jack Lloyd
3
*     2023 Fabian Albert, René Meusel - 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/hash.h>
13
   #include <botan/hex.h>
14

15
   #include <botan/assert.h>
16
   #include <botan/sp_parameters.h>
17
   #include <botan/internal/loadstor.h>
18
   #include <botan/internal/sp_address.h>
19
   #include <botan/internal/sp_fors.h>
20
   #include <botan/internal/sp_hash.h>
21

22
namespace Botan_Tests {
23

24
class SPHINCS_Plus_FORS_Test final : public Text_Based_Test {
×
25
   private:
26
      static Botan::Sphincs_Address read_address(std::span<const uint8_t> address_buffer) {
12✔
27
         BOTAN_ASSERT_NOMSG(address_buffer.size() == 32);
12✔
28

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

34
         return Botan::Sphincs_Address(adrs);
12✔
35
      }
36

37
   public:
38
      SPHINCS_Plus_FORS_Test() :
1✔
39
            Text_Based_Test("pubkey/sphincsplus_fors.vec",
40
                            "SphincsParameterSet,Address,SecretSeed,PublicSeed,PublicKey,Msg,HashSig") {}
2✔
41

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

47
      Test::Result run_one_test(const std::string&, const VarMap& vars) final {
12✔
48
         Test::Result result("SLH-DSA's FORS");
12✔
49

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

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

55
         const auto hashed_message = Botan::SphincsHashedMessage(vars.get_req_bin("Msg"));
12✔
56

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

69
         auto hashes = Botan::Sphincs_Hash_Functions::create(params, public_seed);
12✔
70
         Botan::Sphincs_Address address = read_address(vars.get_req_bin("Address"));
24✔
71

72
         Botan::ForsSignature sig(params.fors_signature_bytes());
12✔
73

74
         auto pk = Botan::fors_sign_and_pkgen(sig, hashed_message, secret_seed, address, params, *hashes);
12✔
75

76
         const auto pk_ref = Botan::SphincsTreeNode(vars.get_req_bin("PublicKey"));
12✔
77
         result.test_is_eq("Derived public key", pk, pk_ref);
12✔
78

79
         const auto hashed_sig_ref = Botan::ForsSignature(vars.get_req_bin("HashSig"));
12✔
80
         result.test_is_eq("Signature result", unlock(hash->process(sig)), hashed_sig_ref.get());
48✔
81

82
         auto pk_from_sig = Botan::fors_public_key_from_signature(hashed_message, sig, address, params, *hashes);
12✔
83
         result.test_is_eq("Public key from signature", pk_from_sig, pk);
12✔
84

85
         return result;
12✔
86
      }
120✔
87
};
88

89
BOTAN_REGISTER_TEST("pubkey", "sphincsplus_fors", SPHINCS_Plus_FORS_Test);
90

91
}  // namespace Botan_Tests
92

93
#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

© 2025 Coveralls, Inc