From 007314c530eb12d414ced07515f8cbc25a0f64f5 Mon Sep 17 00:00:00 2001 From: Jack Lloyd Date: Wed, 28 Nov 2018 10:35:17 -0500 Subject: Add CT::Mask type --- src/tests/test_utils.cpp | 73 ++++++++++++++++++++++++++---------------------- 1 file changed, 39 insertions(+), 34 deletions(-) (limited to 'src/tests/test_utils.cpp') diff --git a/src/tests/test_utils.cpp b/src/tests/test_utils.cpp index 7bbe3745c..f1c6bef43 100644 --- a/src/tests/test_utils.cpp +++ b/src/tests/test_utils.cpp @@ -79,44 +79,10 @@ class Utility_Function_Tests final : 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"); @@ -227,6 +193,45 @@ class Utility_Function_Tests final : public Text_Based_Test BOTAN_REGISTER_TEST("util", Utility_Function_Tests); +class CT_Mask_Tests final : public Test + { + public: + std::vector run() override + { + Test::Result result("CT utils"); + + result.test_eq_sz("CT::is_zero8", Botan::CT::Mask::is_zero(0).value(), 0xFF); + result.test_eq_sz("CT::is_zero8", Botan::CT::Mask::is_zero(1).value(), 0x00); + result.test_eq_sz("CT::is_zero8", Botan::CT::Mask::is_zero(0xFF).value(), 0x00); + + result.test_eq_sz("CT::is_zero16", Botan::CT::Mask::is_zero(0).value(), 0xFFFF); + result.test_eq_sz("CT::is_zero16", Botan::CT::Mask::is_zero(1).value(), 0x0000); + result.test_eq_sz("CT::is_zero16", Botan::CT::Mask::is_zero(0xFF).value(), 0x0000); + + result.test_eq_sz("CT::is_zero32", Botan::CT::Mask::is_zero(0).value(), 0xFFFFFFFF); + result.test_eq_sz("CT::is_zero32", Botan::CT::Mask::is_zero(1).value(), 0x00000000); + result.test_eq_sz("CT::is_zero32", Botan::CT::Mask::is_zero(0xFF).value(), 0x00000000); + + result.test_eq_sz("CT::is_less8", Botan::CT::Mask::is_lt(0, 1).value(), 0xFF); + result.test_eq_sz("CT::is_less8", Botan::CT::Mask::is_lt(1, 0).value(), 0x00); + result.test_eq_sz("CT::is_less8", Botan::CT::Mask::is_lt(0xFF, 5).value(), 0x00); + + result.test_eq_sz("CT::is_less16", Botan::CT::Mask::is_lt(0, 1).value(), 0xFFFF); + result.test_eq_sz("CT::is_less16", Botan::CT::Mask::is_lt(1, 0).value(), 0x0000); + result.test_eq_sz("CT::is_less16", Botan::CT::Mask::is_lt(0xFFFF, 5).value(), 0x0000); + + result.test_eq_sz("CT::is_less32", Botan::CT::Mask::is_lt(0, 1).value(), 0xFFFFFFFF); + result.test_eq_sz("CT::is_less32", Botan::CT::Mask::is_lt(1, 0).value(), 0x00000000); + result.test_eq_sz("CT::is_less32", Botan::CT::Mask::is_lt(0xFFFF5, 5).value(), 0x00000000); + result.test_eq_sz("CT::is_less32", Botan::CT::Mask::is_lt(0xFFFFFFFF, 5).value(), 0x00000000); + result.test_eq_sz("CT::is_less32", Botan::CT::Mask::is_lt(5, 0xFFFFFFFF).value(), 0xFFFFFFFF); + + return {result}; + } + }; + +BOTAN_REGISTER_TEST("ct_utils", CT_Mask_Tests); + #if defined(BOTAN_HAS_POLY_DBL) class Poly_Double_Tests final : public Text_Based_Test -- cgit v1.2.3