diff options
| -rw-r--r-- | src/math/koblitz.c | 2 | ||||
| -rw-r--r-- | src/math/koblitz.h | 19 | ||||
| -rw-r--r-- | test/src/gen/test_order.c | 6 | ||||
| -rw-r--r-- | test/src/math/test_koblitz.c | 33 |
4 files changed, 55 insertions, 5 deletions
diff --git a/src/math/koblitz.c b/src/math/koblitz.c index 48eec2a..10467e3 100644 --- a/src/math/koblitz.c +++ b/src/math/koblitz.c @@ -63,7 +63,7 @@ const koblitz_t *koblitz_find(unsigned int m, unsigned int a) { sizeof(koblitz_t), &compare_koblitz); } -GEN koblitz_get_order(unsigned long m, unsigned int a) { +GEN koblitz_get_order(unsigned int m, unsigned int a) { const koblitz_t *found = koblitz_find(m, a); if (found) { return strtoi(found->hex_order); diff --git a/src/math/koblitz.h b/src/math/koblitz.h index 8284c2e..f1b87d2 100644 --- a/src/math/koblitz.h +++ b/src/math/koblitz.h @@ -14,10 +14,27 @@ typedef struct { const char *hex_order; } koblitz_t; +/** + * @brief + * @param curve + * @return + */ bool koblitz_is_curve(const curve_t *curve); +/** + * @brief + * @param m + * @param a + * @return + */ const koblitz_t *koblitz_find(unsigned int m, unsigned int a); -GEN koblitz_get_order(unsigned long m, unsigned int a); +/** + * @brief + * @param m + * @param a + * @return + */ +GEN koblitz_get_order(unsigned int m, unsigned int a); #endif // ECGEN_KOBLITZ_H 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 <criterion/criterion.h> +#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 |
