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 | |
| parent | 72f2a5d4fb0aaa054fb73e30944c10a41c830727 (diff) | |
| download | ecgen-97149b9104569f70dc0eec47e2e0df4d8d05022d.tar.gz ecgen-97149b9104569f70dc0eec47e2e0df4d8d05022d.tar.zst ecgen-97149b9104569f70dc0eec47e2e0df4d8d05022d.zip | |
Diffstat (limited to 'src')
| -rw-r--r-- | src/exhaustive/brainpool.c | 3 | ||||
| -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 | ||||
| -rw-r--r-- | src/math/subgroup.c | 2 | ||||
| -rw-r--r-- | src/obj/point.c | 90 | ||||
| -rw-r--r-- | src/obj/point.h | 103 |
8 files changed, 197 insertions, 186 deletions
diff --git a/src/exhaustive/brainpool.c b/src/exhaustive/brainpool.c index 68d7966..085e961 100644 --- a/src/exhaustive/brainpool.c +++ b/src/exhaustive/brainpool.c @@ -4,12 +4,11 @@ */ #include "brainpool.h" -#include <misc/types.h> #include "gen/gens.h" -#include "gen/point.h" #include "gen/seed.h" #include "io/output.h" #include "math/subgroup.h" +#include "obj/point.h" #include "util/bits.h" #include "util/str.h" 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 diff --git a/src/math/subgroup.c b/src/math/subgroup.c index 90b795a..f0f2e19 100644 --- a/src/math/subgroup.c +++ b/src/math/subgroup.c @@ -3,7 +3,7 @@ * Copyright (C) 2017-2018 J08nY */ #include "subgroup.h" -#include "gen/point.h" +#include "obj/point.h" #include "util/memory.h" subgroup_t *subgroup_new(void) { return try_calloc(sizeof(subgroup_t)); } diff --git a/src/obj/point.c b/src/obj/point.c new file mode 100644 index 0000000..9c9b37d --- /dev/null +++ b/src/obj/point.c @@ -0,0 +1,90 @@ + +#include "point.h" +#include "misc/types.h" +#include "util/memory.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(unsigned long num) { + return try_calloc(num * sizeof(point_t *)); +} + +point_t **points_copy(point_t **const src, point_t **dest, unsigned long num) { + for (unsigned long i = 0; i < num; ++i) { + dest[i] = point_new_copy(src[i]); + } + return dest; +} + +point_t **points_new_copy(point_t **const src, unsigned long num) { + point_t **result = points_new(num); + return points_copy(src, result, num); +} + +point_t **points_clone(point_t **const src, point_t **dest, unsigned long num) { + for (unsigned long i = 0; i < num; ++i) { + dest[i] = point_new_clone(src[i]); + } + return dest; +} + +point_t **points_new_clone(point_t **const src, unsigned long 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, unsigned long npoints) { + if (*points) { + for (unsigned long i = 0; i < npoints; ++i) { + point_free(&(*points)[i]); + } + points_free(points); + } +}
\ No newline at end of file diff --git a/src/obj/point.h b/src/obj/point.h new file mode 100644 index 0000000..d6aa55e --- /dev/null +++ b/src/obj/point.h @@ -0,0 +1,103 @@ + +#ifndef ECGEN_OBJ_POINT_H +#define ECGEN_OBJ_POINT_H + +#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(unsigned long num); + +/** + * + * @param src + * @param dest + * @param num + * @return + */ +point_t **points_copy(point_t **src, point_t **dest, unsigned long num); + +/** + * + * @param src + * @param num + * @return + */ +point_t **points_new_copy(point_t **src, unsigned long num); + +/** + * + * @param src + * @param dest + * @param num + * @return + */ +point_t **points_clone(point_t **src, point_t **dest, unsigned long num); + +/** + * + * @param src + * @param num + * @return + */ +point_t **points_new_clone(point_t **src, unsigned long num); + +/** + * + * @param point + */ +void points_free(point_t ***point); + +/** + * + * @param points + * @param npoints + */ +void points_free_deep(point_t ***points, unsigned long npoints); + +#endif // ECGEN_OBJ_POINT_H |
