diff options
| author | J08nY | 2018-03-03 01:35:04 +0100 |
|---|---|---|
| committer | J08nY | 2018-03-28 17:25:02 +0200 |
| commit | 97149b9104569f70dc0eec47e2e0df4d8d05022d (patch) | |
| tree | ac144c92971491bec46c471fa8f68f09ad5bb64e /src/gen | |
| parent | 72f2a5d4fb0aaa054fb73e30944c10a41c830727 (diff) | |
| download | ecgen-97149b9104569f70dc0eec47e2e0df4d8d05022d.tar.gz ecgen-97149b9104569f70dc0eec47e2e0df4d8d05022d.tar.zst ecgen-97149b9104569f70dc0eec47e2e0df4d8d05022d.zip | |
Separate point object functions into obj.
Diffstat (limited to 'src/gen')
| -rw-r--r-- | src/gen/gens.c | 2 | ||||
| -rw-r--r-- | src/gen/hex.c | 1 | ||||
| -rw-r--r-- | src/gen/point.c | 86 | ||||
| -rw-r--r-- | src/gen/point.h | 96 |
4 files changed, 2 insertions, 183 deletions
diff --git a/src/gen/gens.c b/src/gen/gens.c index 7947ccb..edbe98a 100644 --- a/src/gen/gens.c +++ b/src/gen/gens.c @@ -5,7 +5,7 @@ #include "gens.h" #include "exhaustive/arg.h" #include "math/subgroup.h" -#include "point.h" +#include "obj/point.h" static subgroup_t *gens_point(GEN point, const curve_t *curve) { subgroup_t *sub = subgroup_new(); diff --git a/src/gen/hex.c b/src/gen/hex.c index 4752b7e..c91f522 100644 --- a/src/gen/hex.c +++ b/src/gen/hex.c @@ -3,7 +3,6 @@ * Copyright (C) 2017-2018 J08nY */ #include "hex.h" -#include <misc/types.h> #include "exhaustive/arg.h" #include "field.h" #include "util/bits.h" diff --git a/src/gen/point.c b/src/gen/point.c index 2d307f3..00e7c3c 100644 --- a/src/gen/point.c +++ b/src/gen/point.c @@ -5,93 +5,9 @@ #include "point.h" #include "exhaustive/arg.h" #include "math/subgroup.h" -#include "util/memory.h" +#include "obj/point.h" #include "util/random.h" -point_t *point_new(void) { return try_calloc(sizeof(point_t)); } - -point_t *point_copy(const point_t *src, point_t *dest) { - if (src->point) dest->point = gcopy(src->point); - if (src->order) dest->order = gcopy(src->order); - if (src->cofactor) dest->cofactor = gcopy(src->cofactor); - return dest; -} - -point_t *point_new_copy(const point_t *src) { - point_t *result = point_new(); - return point_copy(src, result); -} - -point_t *point_clone(const point_t *src, point_t *dest) { - if (src->point) dest->point = gclone(src->point); - if (src->order) dest->order = gclone(src->order); - if (src->cofactor) dest->cofactor = gclone(src->cofactor); - return dest; -} - -point_t *point_new_clone(const point_t *src) { - point_t *result = point_new(); - return point_clone(src, result); -} - -void point_free(point_t **point) { - if (*point) { - if ((*point)->point && isclone((*point)->point)) { - gunclone((*point)->point); - } - if ((*point)->order && isclone((*point)->order)) { - gunclone((*point)->order); - } - if ((*point)->cofactor && isclone((*point)->cofactor)) { - gunclone((*point)->cofactor); - } - try_free(*point); - *point = NULL; - } -} - -point_t **points_new(size_t num) { return try_calloc(num * sizeof(point_t *)); } - -point_t **points_copy(point_t **const src, point_t **dest, size_t num) { - for (size_t i = 0; i < num; ++i) { - dest[i] = point_new_copy(src[i]); - } - return dest; -} - -point_t **points_new_copy(point_t **const src, size_t num) { - point_t **result = points_new(num); - return points_copy(src, result, num); -} - -point_t **points_clone(point_t **const src, point_t **dest, size_t num) { - for (size_t i = 0; i < num; ++i) { - dest[i] = point_new_clone(src[i]); - } - return dest; -} - -point_t **points_new_clone(point_t **const src, size_t num) { - point_t **result = points_new(num); - return points_clone(src, result, num); -} - -void points_free(point_t ***points) { - if (*points) { - try_free(*points); - *points = NULL; - } -} - -void points_free_deep(point_t ***points, size_t npoints) { - if (*points) { - for (size_t i = 0; i < npoints; ++i) { - point_free(&(*points)[i]); - } - points_free(points); - } -} - GENERATOR(point_gen_random) { long which_gen = itos(random_range(gen_0, stoi(curve->ngens))); diff --git a/src/gen/point.h b/src/gen/point.h index cc03326..c10b742 100644 --- a/src/gen/point.h +++ b/src/gen/point.h @@ -11,102 +11,6 @@ #include "misc/types.h" /** - * - * @return - */ -point_t *point_new(void); - -/** - * - * @param src - * @param dest - * @return - */ -point_t *point_copy(const point_t *src, point_t *dest); - -/** - * - * @param src - * @return - */ -point_t *point_new_copy(const point_t *src); - -/** - * - * @param src - * @param dest - * @return - */ -point_t *point_clone(const point_t *src, point_t *dest); - -/** - * - * @param src - * @return - */ -point_t *point_new_clone(const point_t *src); - -/** - * - * @param point - */ -void point_free(point_t **point); - -/** - * - * @param num - * @return - */ -point_t **points_new(size_t num); - -/** - * - * @param src - * @param dest - * @param num - * @return - */ -point_t **points_copy(point_t **src, point_t **dest, size_t num); - -/** - * - * @param src - * @param num - * @return - */ -point_t **points_new_copy(point_t **src, size_t num); - -/** - * - * @param src - * @param dest - * @param num - * @return - */ -point_t **points_clone(point_t **src, point_t **dest, size_t num); - -/** - * - * @param src - * @param num - * @return - */ -point_t **points_new_clone(point_t **src, size_t num); - -/** - * - * @param point - */ -void points_free(point_t ***point); - -/** - * - * @param points - * @param npoints - */ -void points_free_deep(point_t ***points, size_t npoints); - -/** * GENERATOR(gen_f) * * @param curve A curve_t being generated |
