From 1d57a5fe543aee78acd1e21a7639e94010079306 Mon Sep 17 00:00:00 2001 From: Jack Lloyd Date: Tue, 19 Sep 2017 12:38:53 -0400 Subject: Add basic tests for const time utils Remove CT::min and CT::max which were unused and it turns out, broken. --- src/tests/test_utils.cpp | 35 +++++++++++++++++++++++++++++++++++ src/tests/tests.cpp | 5 +++++ src/tests/tests.h | 1 + 3 files changed, 41 insertions(+) (limited to 'src/tests') 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 #include #include +#include #include #include @@ -64,10 +65,44 @@ class Utility_Function_Tests : public Text_Based_Test std::vector 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(0), 0xFF); + result.test_eq_sz("CT::is_zero8", Botan::CT::is_zero(1), 0x00); + result.test_eq_sz("CT::is_zero8", Botan::CT::is_zero(0xFF), 0x00); + + result.test_eq_sz("CT::is_zero16", Botan::CT::is_zero(0), 0xFFFF); + result.test_eq_sz("CT::is_zero16", Botan::CT::is_zero(1), 0x0000); + result.test_eq_sz("CT::is_zero16", Botan::CT::is_zero(0xFF), 0x0000); + + result.test_eq_sz("CT::is_zero32", Botan::CT::is_zero(0), 0xFFFFFFFF); + result.test_eq_sz("CT::is_zero32", Botan::CT::is_zero(1), 0x00000000); + result.test_eq_sz("CT::is_zero32", Botan::CT::is_zero(0xFF), 0x00000000); + + result.test_eq_sz("CT::is_less8", Botan::CT::is_less(0, 1), 0xFF); + result.test_eq_sz("CT::is_less8", Botan::CT::is_less(1, 0), 0x00); + result.test_eq_sz("CT::is_less8", Botan::CT::is_less(0xFF, 5), 0x00); + + result.test_eq_sz("CT::is_less16", Botan::CT::is_less(0, 1), 0xFFFF); + result.test_eq_sz("CT::is_less16", Botan::CT::is_less(1, 0), 0x0000); + result.test_eq_sz("CT::is_less16", Botan::CT::is_less(0xFFFF, 5), 0x0000); + + result.test_eq_sz("CT::is_less32", Botan::CT::is_less(0, 1), 0xFFFFFFFF); + result.test_eq_sz("CT::is_less32", Botan::CT::is_less(1, 0), 0x00000000); + result.test_eq_sz("CT::is_less32", Botan::CT::is_less(0xFFFF5, 5), 0x00000000); + result.test_eq_sz("CT::is_less32", Botan::CT::is_less(0xFFFFFFFF, 5), 0x00000000); + result.test_eq_sz("CT::is_less32", Botan::CT::is_less(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); -- cgit v1.2.3