From 40cbb213ac910ddcaf22a26a247d2a9eeddca1fc Mon Sep 17 00:00:00 2001 From: J08nY Date: Tue, 27 Feb 2018 20:48:21 +0100 Subject: Add tests for Koblitz order store. --- test/src/gen/test_order.c | 6 +++--- test/src/math/test_koblitz.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 test/src/math/test_koblitz.c (limited to 'test') diff --git a/test/src/gen/test_order.c b/test/src/gen/test_order.c index aa7dc08..ab74f54 100644 --- a/test/src/gen/test_order.c +++ b/test/src/gen/test_order.c @@ -46,17 +46,17 @@ Test(order, test_order_gen_sea) { cr_assert(gequal(curve.order, stoi(26)), ); } -Test(order, test_order_gen_smallfact) { +Test(order, test_order_gen_cofactor) { curve_t curve = {.field = stoi(19), .a = mkintmodu(3, 19), .b = mkintmodu(5, 19), .curve = ellinit(mkvec2(stoi(3), stoi(5)), stoi(19), 0)}; cfg->bits = 16; - pari_ulong smallfact = 5; + pari_ulong smallfact = 2; arg_t arg = {.args = &smallfact, .nargs = 1}; - int ret = order_gen_smallfact(&curve, &arg, OFFSET_ORDER); + int ret = order_gen_cofactor(&curve, &arg, OFFSET_ORDER); cr_assert_eq(ret, 1, ); cr_assert(gequal(curve.order, stoi(26)), ); } diff --git a/test/src/math/test_koblitz.c b/test/src/math/test_koblitz.c new file mode 100644 index 0000000..03e411c --- /dev/null +++ b/test/src/math/test_koblitz.c @@ -0,0 +1,33 @@ +/* + * ecgen, tool for generating Elliptic curve domain parameters + * Copyright (C) 2017 J08nY + */ +#include +#include "gen/point.h" +#include "math/koblitz.h" +#include "test/default.h" + +TestSuite(koblitz, .init = default_setup, .fini = default_teardown); + +Test(koblitz, test_koblitz_is_curve) { + curve_t curve = { + .field = stoi(23), + .a = mkintmodu(3, 23), + .b = mkintmodu(2, 23) + }; + + cr_assert_not(koblitz_is_curve(&curve),); + curve.a = mkintmodu(1, 23); + curve.b = mkintmodu(1, 23); + cr_assert(koblitz_is_curve(&curve),); +} + +Test(koblitz, test_koblitz_find) { + const koblitz_t *koblitz = koblitz_find(107, 0); + cr_assert_not_null(koblitz, ); +} + +Test(koblitz, test_koblitz_get_order) { + GEN order = koblitz_get_order(107, 0); + cr_assert(gequal(order, strtoi("0x7ffffffffffffb57c25324737c4")), ); +} \ No newline at end of file -- cgit v1.3.1