aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2017-09-19 12:38:53 -0400
committerJack Lloyd <[email protected]>2017-09-19 12:38:53 -0400
commit1d57a5fe543aee78acd1e21a7639e94010079306 (patch)
treed2eb2f907f96c7dde76a655669aba807770f83c6 /src/tests
parent0c77c98feda95c109ed780b767aca6aad1c14dc7 (diff)
Add basic tests for const time utils
Remove CT::min and CT::max which were unused and it turns out, broken.
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/test_utils.cpp35
-rw-r--r--src/tests/tests.cpp5
-rw-r--r--src/tests/tests.h1
3 files changed, 41 insertions, 0 deletions
diff --git a/src/tests/test_utils.cpp b/src/tests/test_utils.cpp
index 0ca79b6e9..d4035de65 100644
--- a/src/tests/test_utils.cpp
+++ b/src/tests/test_utils.cpp
@@ -13,6 +13,7 @@
#include <botan/calendar.h>
#include <botan/internal/rounding.h>
#include <botan/internal/poly_dbl.h>
+#include <botan/internal/ct_utils.h>
#include <botan/charset.h>
#include <botan/parsing.h>
@@ -64,10 +65,44 @@ class Utility_Function_Tests : public Text_Based_Test
std::vector<Test::Result> results;
results.push_back(test_loadstore());
+ results.push_back(test_ct_utils());
return results;
}
+ Test::Result test_ct_utils()
+ {
+ Test::Result result("CT utils");
+
+ result.test_eq_sz("CT::is_zero8", Botan::CT::is_zero<uint8_t>(0), 0xFF);
+ result.test_eq_sz("CT::is_zero8", Botan::CT::is_zero<uint8_t>(1), 0x00);
+ result.test_eq_sz("CT::is_zero8", Botan::CT::is_zero<uint8_t>(0xFF), 0x00);
+
+ result.test_eq_sz("CT::is_zero16", Botan::CT::is_zero<uint16_t>(0), 0xFFFF);
+ result.test_eq_sz("CT::is_zero16", Botan::CT::is_zero<uint16_t>(1), 0x0000);
+ result.test_eq_sz("CT::is_zero16", Botan::CT::is_zero<uint16_t>(0xFF), 0x0000);
+
+ result.test_eq_sz("CT::is_zero32", Botan::CT::is_zero<uint32_t>(0), 0xFFFFFFFF);
+ result.test_eq_sz("CT::is_zero32", Botan::CT::is_zero<uint32_t>(1), 0x00000000);
+ result.test_eq_sz("CT::is_zero32", Botan::CT::is_zero<uint32_t>(0xFF), 0x00000000);
+
+ result.test_eq_sz("CT::is_less8", Botan::CT::is_less<uint8_t>(0, 1), 0xFF);
+ result.test_eq_sz("CT::is_less8", Botan::CT::is_less<uint8_t>(1, 0), 0x00);
+ result.test_eq_sz("CT::is_less8", Botan::CT::is_less<uint8_t>(0xFF, 5), 0x00);
+
+ result.test_eq_sz("CT::is_less16", Botan::CT::is_less<uint16_t>(0, 1), 0xFFFF);
+ result.test_eq_sz("CT::is_less16", Botan::CT::is_less<uint16_t>(1, 0), 0x0000);
+ result.test_eq_sz("CT::is_less16", Botan::CT::is_less<uint16_t>(0xFFFF, 5), 0x0000);
+
+ result.test_eq_sz("CT::is_less32", Botan::CT::is_less<uint32_t>(0, 1), 0xFFFFFFFF);
+ result.test_eq_sz("CT::is_less32", Botan::CT::is_less<uint32_t>(1, 0), 0x00000000);
+ result.test_eq_sz("CT::is_less32", Botan::CT::is_less<uint32_t>(0xFFFF5, 5), 0x00000000);
+ result.test_eq_sz("CT::is_less32", Botan::CT::is_less<uint32_t>(0xFFFFFFFF, 5), 0x00000000);
+ result.test_eq_sz("CT::is_less32", Botan::CT::is_less<uint32_t>(5, 0xFFFFFFFF), 0xFFFFFFFF);
+
+ return result;
+ }
+
Test::Result test_loadstore()
{
Test::Result result("Util load/store");
diff --git a/src/tests/tests.cpp b/src/tests/tests.cpp
index 930d7c623..af2cd5909 100644
--- a/src/tests/tests.cpp
+++ b/src/tests/tests.cpp
@@ -233,6 +233,11 @@ bool Test::Result::test_eq(const std::string& what, size_t produced, size_t expe
return test_is_eq(what, produced, expected);
}
+bool Test::Result::test_eq_sz(const std::string& what, size_t produced, size_t expected)
+ {
+ return test_is_eq(what, produced, expected);
+ }
+
bool Test::Result::test_eq(const std::string& what, OctetString produced, OctetString expected)
{
std::ostringstream out;
diff --git a/src/tests/tests.h b/src/tests/tests.h
index 0673705d9..16b968bd4 100644
--- a/src/tests/tests.h
+++ b/src/tests/tests.h
@@ -203,6 +203,7 @@ class Test
bool test_eq(const std::string& what, bool produced, bool expected);
bool test_eq(const std::string& what, size_t produced, size_t expected);
+ bool test_eq_sz(const std::string& what, size_t produced, size_t expected);
bool test_eq(const std::string& what, OctetString produced, OctetString expected);