diff options
| author | J08nY | 2017-08-30 01:48:08 +0200 |
|---|---|---|
| committer | J08nY | 2017-08-30 01:48:08 +0200 |
| commit | a324d5db93ea089f1d2e86c2adb4560856307dad (patch) | |
| tree | a3c426786e69613fdea75b12dd69adbb43cff2ea | |
| parent | e8623c98acfda4e839a552d5d23e80287be1ec11 (diff) | |
| download | ecgen-a324d5db93ea089f1d2e86c2adb4560856307dad.tar.gz ecgen-a324d5db93ea089f1d2e86c2adb4560856307dad.tar.zst ecgen-a324d5db93ea089f1d2e86c2adb4560856307dad.zip | |
| -rw-r--r-- | src/math/subgroups.c | 4 | ||||
| -rw-r--r-- | test/src/gen/test_point.c | 41 | ||||
| -rw-r--r-- | test/src/math/test_subgroups.c | 10 | ||||
| -rw-r--r-- | test/src/test/utils.c | 8 |
4 files changed, 42 insertions, 21 deletions
diff --git a/src/math/subgroups.c b/src/math/subgroups.c index 587570b..93526ae 100644 --- a/src/math/subgroups.c +++ b/src/math/subgroups.c @@ -2,7 +2,6 @@ * ecgen, tool for generating Elliptic curve domain parameters * Copyright (C) 2017 J08nY */ -#include <gen/types.h> #include "subgroups.h" /** @@ -47,7 +46,8 @@ static GEN subgroups_divisors(GEN order) { } /** - * @brief All factors consisting of at least <code>min_bits</code> prime <code>factors</code>. + * @brief All factors consisting of at least <code>min_bits</code> prime + * <code>factors</code>. * * @param factors * @param min_bits diff --git a/test/src/gen/test_point.c b/test/src/gen/test_point.c index fd928d6..a0c9e06 100644 --- a/test/src/gen/test_point.c +++ b/test/src/gen/test_point.c @@ -3,12 +3,11 @@ * Copyright (C) 2017 J08nY */ -#include "gen/types.h" +#include <criterion/criterion.h> #include "gen/point.h" #include "test/utils.h" -#include <criterion/criterion.h> -TestSuite(point, .init=default_setup, .fini=default_teardown); +TestSuite(point, .init = default_setup, .fini = default_teardown); Test(point, test_point_random) { GEN e = ellinit(mkvec2s(1, 3), stoi(23), -1); @@ -21,7 +20,8 @@ Test(point, test_point_random) { cr_assert_not_null(curve.points, "Points are null."); cr_assert(ellisoncurve(e, curve.points[0]->point), "Point not on curve."); cr_assert(gequal(ellorder(e, curve.points[0]->point, NULL), - curve.points[0]->order), "Point has wrong order set."); + curve.points[0]->order), + "Point has wrong order set."); points_free_deep(&curve.points, 1); } @@ -39,11 +39,38 @@ Test(point, test_points_random) { cr_assert_not_null(curve.points, "Points are null."); for (size_t i = 0; i < npoints; i++) { point_t *point = curve.points[i]; - cr_assert(ellisoncurve(e, point->point), - "Point not on curve."); + cr_assert(ellisoncurve(e, point->point), "Point not on curve."); cr_assert(gequal(ellorder(e, point->point, NULL), point->order), - "Point has wrong order set."); + "Point has wrong order set."); } points_free_deep(&curve.points, npoints); } + +Test(point, test_points_trial) { + GEN e = ellinit(mkvec2s(1, 3), stoi(23), -1); + point_t **gens = points_new(1); + gens[0] = point_new(); + gens[0]->order = stoi(27); + gens[0]->cofactor = stoi(1); + gens[0]->point = mkvec2(mkintmodu(15, 23), mkintmodu(14, 23)); + curve_t curve = { + .order = stoi(27), .curve = e, .ngens = 1, .generators = gens}; + config_t cfg = {}; + pari_ulong prime = 3; + arg_t arg = {.args = &prime, .nargs = 1}; + int ret = points_gen_trial(&curve, &cfg, &arg); + + cr_assert_eq(ret, 1, "Point wasn't generated."); + cr_assert_eq(curve.npoints, 1, "Incorrect number of points."); + cr_assert_not_null(curve.points, "Points are null."); + cr_assert(ellisoncurve(e, curve.points[0]->point), "Point not on curve."); + cr_assert(gequal(ellorder(e, curve.points[0]->point, NULL), + curve.points[0]->order), + "Point has wrong order set."); + cr_assert(gequal(curve.points[0]->order, stoi(prime)), + "Point has wrong order."); + + points_free_deep(&curve.points, 1); + points_free_deep(&curve.generators, 1); +} diff --git a/test/src/math/test_subgroups.c b/test/src/math/test_subgroups.c index 05bfe57..b9368d0 100644 --- a/test/src/math/test_subgroups.c +++ b/test/src/math/test_subgroups.c @@ -2,13 +2,12 @@ * ecgen, tool for generating Elliptic curve domain parameters * Copyright (C) 2017 J08nY */ -#include "gen/types.h" +#include <criterion/criterion.h> #include "gen/point.h" #include "math/subgroups.h" -#include <criterion/criterion.h> #include "test/utils.h" -TestSuite(subgroups, .init=default_setup, .fini=default_teardown); +TestSuite(subgroups, .init = default_setup, .fini = default_teardown); Test(subgroups, test_prime_factors) { curve_t curve = {.order = stoi(12)}; @@ -40,8 +39,7 @@ Test(subgroups, test_nonprime_factors) { config_t cfg = {.prime = false}; GEN divs = subgroups_nonprime(&curve, &cfg); GEN vec = mkvec2s(9, 27); - cr_assert(gequal(divs, vec), - "Factors not equal!"); + cr_assert(gequal(divs, vec), "Factors not equal!"); } Test(subgroups, test_all_factors) { @@ -69,7 +67,7 @@ Test(subgroups, test_all_factors_two_gens) { config_t cfg = {.prime = false}; GEN divs = subgroups_all(&curve, &cfg); GEN vec = mkvecn(8, stoi(2), stoi(3), stoi(4), stoi(6), stoi(12), stoi(2), - stoi(3), stoi(6)); + stoi(3), stoi(6)); cr_assert(gequal(divs, vec), "Factors not equal!"); points_free_deep(&gens, 2); } diff --git a/test/src/test/utils.c b/test/src/test/utils.c index a8a11db..8589efe 100644 --- a/test/src/test/utils.c +++ b/test/src/test/utils.c @@ -5,10 +5,6 @@ #include "utils.h" #include <pari/pari.h> -void default_setup(void) { - pari_init(1000000, 1000000); -} +void default_setup(void) { pari_init(1000000, 1000000); } -void default_teardown(void) { - pari_close(); -}
\ No newline at end of file +void default_teardown(void) { pari_close(); }
\ No newline at end of file |
