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

randombit / botan / 21780928802

07 Feb 2026 01:36PM UTC coverage: 90.068% (+0.003%) from 90.065%
21780928802

Pull #5295

github

web-flow
Merge cbabeb61a into ebf8f0044
Pull Request #5295: Reduce header dependencies in tests and cli

102234 of 113508 relevant lines covered (90.07%)

11464546.51 hits per line

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

85.14
/src/tests/test_tss.cpp
1
/*
2
* (C) 2009 Jack Lloyd
3
*
4
* Botan is released under the Simplified BSD License (see license.txt)
5
*/
6

7
#include "tests.h"
8

9
#if defined(BOTAN_HAS_THRESHOLD_SECRET_SHARING)
10
   #include "test_rng.h"
11
   #include <botan/exceptn.h>
12
   #include <botan/tss.h>
13
#endif
14

15
namespace Botan_Tests {
16

17
namespace {
18

19
#if defined(BOTAN_HAS_THRESHOLD_SECRET_SHARING)
20

21
class TSS_Recovery_Tests final : public Text_Based_Test {
×
22
   public:
23
      TSS_Recovery_Tests() : Text_Based_Test("tss/recovery.vec", "N,M,Shares,Recovered") {}
2✔
24

25
      Test::Result run_one_test(const std::string& header, const VarMap& vars) override {
4✔
26
         Test::Result result("TSS");
4✔
27

28
         const std::vector<uint8_t> input = vars.get_req_bin("Recovered");
4✔
29
         const size_t N = vars.get_req_sz("N");
4✔
30
         const size_t M = vars.get_req_sz("M");
4✔
31
         const std::vector<std::vector<uint8_t>> expected_shares = vars.get_req_bin_list("Shares");
4✔
32

33
         try {
4✔
34
            std::vector<Botan::RTSS_Share> shares;
4✔
35
            shares.reserve(expected_shares.size());
4✔
36

37
            for(auto&& v : expected_shares) {
17✔
38
               shares.push_back(Botan::RTSS_Share(v.data(), v.size()));
26✔
39
            }
40

41
            auto reconstructed_secret_all = Botan::RTSS_Share::reconstruct(shares);
4✔
42
            result.test_eq("Reconstructed secret correctly from all shares", reconstructed_secret_all, input);
6✔
43

44
            if(header == "Invalid") {
3✔
45
               result.test_failure("Invalid shares should not result in recovery");
×
46
            }
47

48
            if(N != M) {
3✔
49
               while(shares.size() > M) {
6✔
50
                  const size_t to_remove = this->rng().next_byte() % shares.size();
4✔
51
                  shares.erase(shares.begin() + to_remove);
4✔
52
                  try {
4✔
53
                     auto reconstructed_secret = Botan::RTSS_Share::reconstruct(shares);
4✔
54
                     result.test_eq("Reconstructed secret correctly from reduced shares", reconstructed_secret, input);
8✔
55
                  } catch(Botan::Decoding_Error&) {
4✔
56
                     result.test_failure("Reconstruction failed with share count " + std::to_string(shares.size()));
×
57
                  }
×
58
               }
59
            }
60

61
         } catch(std::exception& e) {
5✔
62
            if(header == "Valid") {
1✔
63
               result.test_failure("Valid TSS failed to recover", e.what());
×
64
            } else {
65
               result.test_success("Invalid TSS rejected as expected");
2✔
66
            }
67
         }
1✔
68

69
         return result;
8✔
70
      }
8✔
71
};
72

73
BOTAN_REGISTER_TEST("utils", "tss_recovery", TSS_Recovery_Tests);
74

75
class TSS_Generation_Tests final : public Text_Based_Test {
×
76
   public:
77
      TSS_Generation_Tests() : Text_Based_Test("tss/generation.vec", "Input,RNG,Hash,Id,N,M,Shares") {}
2✔
78

79
      static size_t tss_hash_len(const std::string& hash) {
6✔
80
         if(hash == "None") {
6✔
81
            return 0;
82
         } else if(hash == "SHA-1") {
2✔
83
            return 20;
84
         } else if(hash == "SHA-256") {
1✔
85
            return 32;
86
         } else {
87
            throw Test_Error("Unknown TSS hash algorithm " + hash);
×
88
         }
89
      }
90

91
      Test::Result run_one_test(const std::string& /*header*/, const VarMap& vars) override {
6✔
92
         Test::Result result("TSS");
6✔
93

94
         const std::vector<uint8_t> input = vars.get_req_bin("Input");
6✔
95
         const std::vector<uint8_t> id = vars.get_req_bin("Id");
6✔
96
         const std::vector<uint8_t> rng_data = vars.get_req_bin("RNG");
6✔
97
         const uint8_t N = vars.get_req_u8("N");
6✔
98
         const uint8_t M = vars.get_req_u8("M");
6✔
99
         const std::string hash = vars.get_req_str("Hash");
6✔
100
         const std::vector<std::vector<uint8_t>> expected_shares = vars.get_req_bin_list("Shares");
6✔
101

102
         if(expected_shares.size() != N) {
6✔
103
            throw Test_Error("Invalid test data for TSS share count != N");
×
104
         }
105

106
         if(rng_data.size() != (input.size() + tss_hash_len(hash)) * (M - 1)) {
6✔
107
            throw Test_Error("Invalid test data for TSS share bad RNG input size");
×
108
         }
109

110
         Fixed_Output_RNG fixed_rng(rng_data);
6✔
111

112
         std::vector<Botan::RTSS_Share> shares =
6✔
113
            Botan::RTSS_Share::split(M, N, input.data(), static_cast<uint16_t>(input.size()), id, hash, fixed_rng);
6✔
114

115
         result.test_eq("Expected number of shares", shares.size(), N);
6✔
116

117
         for(size_t i = 0; i != N; ++i) {
40✔
118
            result.test_eq("Expected share", shares[i].data(), expected_shares[i]);
68✔
119
         }
120

121
         auto reconstructed_secret_all = Botan::RTSS_Share::reconstruct(shares);
6✔
122
         result.test_eq("Reconstructed secret correctly from all shares", reconstructed_secret_all, input);
12✔
123

124
         if(N != M) {
6✔
125
            while(shares.size() > M) {
21✔
126
               const size_t to_remove = this->rng().next_byte() % shares.size();
17✔
127
               shares.erase(shares.begin() + to_remove);
17✔
128

129
               try {
17✔
130
                  auto reconstructed_secret = Botan::RTSS_Share::reconstruct(shares);
17✔
131
                  result.test_eq("Reconstructed secret correctly from reduced shares", reconstructed_secret, input);
34✔
132
               } catch(Botan::Decoding_Error&) {
17✔
133
                  result.test_failure("Reconstruction failed with share count " + std::to_string(shares.size()));
×
134
               }
×
135
            }
136
         }
137

138
         return result;
6✔
139
      }
24✔
140
};
141

142
BOTAN_REGISTER_TEST("utils", "tss_generation", TSS_Generation_Tests);
143

144
#endif  // BOTAN_HAS_THRESHOLD_SECRET_SHARING
145

146
}  // namespace
147

148
}  // namespace Botan_Tests
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