aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests/test_tss.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests/test_tss.cpp')
-rw-r--r--src/tests/test_tss.cpp67
1 files changed, 30 insertions, 37 deletions
diff --git a/src/tests/test_tss.cpp b/src/tests/test_tss.cpp
index c5440634b..96e3fa9ee 100644
--- a/src/tests/test_tss.cpp
+++ b/src/tests/test_tss.cpp
@@ -7,53 +7,46 @@
#include "tests.h"
#if defined(BOTAN_HAS_THRESHOLD_SECRET_SHARING)
+ #include <botan/tss.h>
+ #include <botan/hex.h>
+#endif
-#include <iostream>
-#include <botan/hex.h>
-#include <botan/tss.h>
+namespace Botan_Tests {
-size_t test_tss()
- {
- using namespace Botan;
-
- auto& rng = test_rng();
-
- size_t fails = 0;
-
- byte id[16];
- for(int i = 0; i != 16; ++i)
- id[i] = i;
-
- const secure_vector<byte> S = hex_decode_locked("7465737400");
+namespace {
- std::vector<RTSS_Share> shares =
- RTSS_Share::split(2, 4, S.data(), S.size(), id, rng);
+#if defined(BOTAN_HAS_THRESHOLD_SECRET_SHARING)
- auto back = RTSS_Share::reconstruct(shares);
+class TSS_Tests : public Test
+ {
+ public:
+ std::vector<Test::Result> run() override
+ {
+ std::vector<Test::Result> results;
- if(S != back)
- {
- std::cout << "TSS-0: " << hex_encode(S) << " != " << hex_encode(back) << std::endl;
- ++fails;
- }
+ Test::Result result("TSS");
+ byte id[16];
+ for(int i = 0; i != 16; ++i)
+ id[i] = i;
- shares.resize(shares.size()-1);
+ const std::vector<byte> S = Botan::hex_decode("7465737400");
- back = RTSS_Share::reconstruct(shares);
+ std::vector<Botan::RTSS_Share> shares =
+ Botan::RTSS_Share::split(2, 4, S.data(), S.size(), id, Test::rng());
- if(S != back)
- {
- std::cout << "TSS-1: " << hex_encode(S) << " != " << hex_encode(back) << std::endl;
- ++fails;
- }
+ result.test_eq("reconstruction", Botan::RTSS_Share::reconstruct(shares), S);
+ shares.resize(shares.size()-1);
+ result.test_eq("reconstruction after removal", Botan::RTSS_Share::reconstruct(shares), S);
- test_report("TSS", 2, fails);
+ results.push_back(result);
+ return results;
+ }
+ };
- return fails;
- }
+BOTAN_REGISTER_TEST("tss", TSS_Tests);
-#else
+#endif // BOTAN_HAS_THRESHOLD_SECRET_SHARING
-SKIP_TEST(tss);
+}
-#endif // BOTAN_HAS_THRESHOLD_SECRET_SHARING
+}