aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests/test_gf2m.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests/test_gf2m.cpp')
-rw-r--r--src/tests/test_gf2m.cpp76
1 files changed, 52 insertions, 24 deletions
diff --git a/src/tests/test_gf2m.cpp b/src/tests/test_gf2m.cpp
index 7557672a6..11a15c3fe 100644
--- a/src/tests/test_gf2m.cpp
+++ b/src/tests/test_gf2m.cpp
@@ -7,40 +7,68 @@
#include "tests.h"
#if defined(BOTAN_HAS_MCELIECE)
+ #include <botan/gf2m_small_m.h>
+#endif
-#include <botan/gf2m_small_m.h>
-
-BOTAN_TEST_CASE(gf2m, "GF(2^m)", {
+namespace Botan_Tests {
- using namespace Botan;
+namespace {
- for(size_t degree = 2; degree <= 16; ++degree)
- {
- GF2m_Field field(degree);
+#if defined(BOTAN_HAS_MCELIECE)
- for(size_t i = 0; i <= field.gf_ord(); ++i)
+class GF2m_Tests : public Test
+ {
+ public:
+ std::vector<Test::Result> run() override
{
- gf2m a = i;
+ std::vector<Test::Result> results;
+
+ results.push_back(test_gf_overflow());
- BOTAN_TEST(field.gf_square(a), field.gf_mul(a, a), "Square and multiply");
+ return results;
+ }
+
+ private:
+ Test::Result test_gf_overflow()
+ {
+ Test::Result result("GF2m");
- /*
- * This sequence is from the start of gf2m_decomp_rootfind_state::calc_Fxj_j_neq_0
- */
+ for(size_t degree = 2; degree <= 16; ++degree)
{
- const gf2m jl_gray = field.gf_l_from_n(a);
- gf2m xl_j_tt_5 = field.gf_square_rr(jl_gray);
- const gf2m xl_gray_tt_3 = field.gf_mul_rrr(xl_j_tt_5, jl_gray);
- xl_j_tt_5 = field.gf_mul_rrr(xl_j_tt_5, xl_gray_tt_3);
- gf2m s = field.gf_mul_nrr(xl_gray_tt_3, field.gf_ord());
- BOTAN_CONFIRM(s <= field.gf_ord(), "Less than order");
+ Botan::GF2m_Field field(degree);
+
+ using Botan::gf2m;
+
+ for(size_t i = 0; i <= field.gf_ord(); ++i)
+ {
+ gf2m a = i;
+
+ result.test_eq("square vs multiply",
+ static_cast<size_t>(field.gf_square(a)),
+ static_cast<size_t>(field.gf_mul(a, a)));
+
+ /*
+ * This sequence is from the start of gf2m_decomp_rootfind_state::calc_Fxj_j_neq_0
+ */
+ {
+ const gf2m jl_gray = field.gf_l_from_n(a);
+ gf2m xl_j_tt_5 = field.gf_square_rr(jl_gray);
+ const gf2m xl_gray_tt_3 = field.gf_mul_rrr(xl_j_tt_5, jl_gray);
+ xl_j_tt_5 = field.gf_mul_rrr(xl_j_tt_5, xl_gray_tt_3);
+ gf2m s = field.gf_mul_nrr(xl_gray_tt_3, field.gf_ord());
+
+ result.test_gte("Value less than order", field.gf_ord(), s);
+ }
+ }
}
+ return result;
}
- }
- });
+ };
-#else
-
-SKIP_TEST(gf2m);
+BOTAN_REGISTER_TEST("gf2m", GF2m_Tests);
#endif
+
+}
+
+}