aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJ08nY2017-09-30 16:34:50 +0200
committerJ08nY2017-09-30 16:34:50 +0200
commit64ccc59f390cb3a3a2f0347c8807fe4091bb5cd8 (patch)
tree6dfe8da7776c9ef549fc64824cf7a767c048eb3c
parent381ccc4beaf3879606ca33fb385526c8fd8d8fcf (diff)
downloadecgen-64ccc59f390cb3a3a2f0347c8807fe4091bb5cd8.tar.gz
ecgen-64ccc59f390cb3a3a2f0347c8807fe4091bb5cd8.tar.zst
ecgen-64ccc59f390cb3a3a2f0347c8807fe4091bb5cd8.zip
-rw-r--r--src/exhaustive/exhaustive.c34
-rw-r--r--src/exhaustive/exhaustive.h29
-rw-r--r--src/invalid/invalid.c39
-rw-r--r--src/invalid/invalid_thread.c2
4 files changed, 86 insertions, 18 deletions
diff --git a/src/exhaustive/exhaustive.c b/src/exhaustive/exhaustive.c
index 6c8c83d..623396e 100644
--- a/src/exhaustive/exhaustive.c
+++ b/src/exhaustive/exhaustive.c
@@ -3,7 +3,6 @@
* Copyright (C) 2017 J08nY
*/
#include "exhaustive.h"
-#include <misc/types.h>
#include "anomalous.h"
#include "ansi.h"
#include "check.h"
@@ -17,6 +16,39 @@
#include "io/output.h"
#include "util/memory.h"
+exhaustive_t *exhaustive_new(void) { return try_calloc(sizeof(exhaustive_t)); }
+
+exhaustive_t *exhaustive_create(gen_f *generators, check_t **validators,
+ arg_t **argss, unroll_f *unrolls) {
+ exhaustive_t *result = exhaustive_new();
+ result->generators = generators;
+ result->validators = validators;
+ result->argss = argss;
+ result->unrolls = unrolls;
+ return result;
+}
+
+void exhaustive_clear(exhaustive_t *setup) {
+ if (setup->validators) {
+ for (size_t i = 0; i < OFFSET_END; ++i) {
+ check_free(&setup->validators[i]);
+ }
+ }
+ if (setup->argss) {
+ for (size_t i = 0; i < OFFSET_END; ++i) {
+ arg_free(&setup->argss[i]);
+ }
+ }
+}
+
+void exhaustive_free(exhaustive_t **setup) {
+ if (*setup) {
+ exhaustive_clear(*setup);
+ try_free(*setup);
+ *setup = NULL;
+ }
+}
+
static void exhaustive_ginit(gen_f *generators, const config_t *cfg) {
if (cfg->seed_algo) {
switch (cfg->seed_algo) {
diff --git a/src/exhaustive/exhaustive.h b/src/exhaustive/exhaustive.h
index 8d3c34f..ddc1ef6 100644
--- a/src/exhaustive/exhaustive.h
+++ b/src/exhaustive/exhaustive.h
@@ -21,6 +21,35 @@ typedef struct {
} exhaustive_t;
/**
+ * @brief
+ * @return
+ */
+exhaustive_t *exhaustive_new(void);
+
+/**
+ * @brief
+ * @param generators
+ * @param validators
+ * @param argss
+ * @param unrolls
+ * @return
+ */
+exhaustive_t *exhaustive_create(gen_f *generators, check_t **validators,
+ arg_t **argss, unroll_f *unrolls);
+
+/**
+ * @brief
+ * @param setup
+ */
+void exhaustive_clear(exhaustive_t *setup);
+
+/**
+ * @brief
+ * @param setup
+ */
+void exhaustive_free(exhaustive_t **setup);
+
+/**
*
* @param unrolls
* @param cfg
diff --git a/src/invalid/invalid.c b/src/invalid/invalid.c
index c3abbc7..fb56321 100644
--- a/src/invalid/invalid.c
+++ b/src/invalid/invalid.c
@@ -3,6 +3,9 @@
* Copyright (C) 2017 J08nY
*/
#include "invalid.h"
+#include <exhaustive/exhaustive.h>
+#include <misc/types.h>
+#include "exhaustive/arg.h"
#include "exhaustive/check.h"
#include "exhaustive/exhaustive.h"
#include "gen/curve.h"
@@ -88,8 +91,11 @@ static size_t invalid_primes(GEN order, pari_ulong **primes) {
static size_t invalid_curves(const curve_t *curve, const config_t *cfg,
pari_ulong *primes, size_t nprimes,
curve_t **curves, exhaustive_t *setup) {
- arg_t *invalid_argss[OFFSET_END];
- setup->argss = invalid_argss;
+ arg_t *invalid_argss[OFFSET_END] = {NULL};
+ exhaustive_t invalid_setup = {.generators = setup->generators,
+ .validators = setup->validators,
+ .argss = invalid_argss,
+ .unrolls = setup->unrolls};
// Alloc a curve, and only alloc a new one when this pointer is saved into
// **curves
@@ -149,7 +155,8 @@ static size_t invalid_curves(const curve_t *curve, const config_t *cfg,
// generate prime order points, this is expensive (order needs to be
// factorised, so only do it if we want the curve)
- exhaustive_gen(invalid, cfg, setup, OFFSET_POINTS, OFFSET_END);
+ exhaustive_gen(invalid, cfg, &invalid_setup, OFFSET_POINTS,
+ OFFSET_END);
size_t count = 0;
for (size_t i = nprimes; i-- > 0;) {
@@ -284,20 +291,20 @@ int invalid_do(config_t *cfg) {
gen_f original_gens[OFFSET_END] = {NULL};
check_t *common_validators[OFFSET_END] = {NULL};
- arg_t *original_argss[OFFSET_END] = {NULL};
+ arg_t *common_argss[OFFSET_END] = {NULL};
unroll_f common_unrolls[OFFSET_END] = {NULL};
invalid_original_ginit(original_gens, cfg);
invalid_cinit(common_validators, cfg);
exhaustive_uinit(common_unrolls, cfg);
- exhaustive_t original_setup = {.generators = original_gens,
- .validators = common_validators,
- .argss = original_argss,
- .unrolls = common_unrolls};
+
+ exhaustive_t *original_setup = exhaustive_create(
+ original_gens, common_validators, common_argss, common_unrolls);
debug_log_start("Starting to create curve to invalidate");
curve_t *curve = curve_new();
- if (!exhaustive_gen(curve, cfg, &original_setup, OFFSET_FIELD,
+ if (!exhaustive_gen(curve, cfg, original_setup, OFFSET_FIELD,
OFFSET_POINTS)) {
+ exhaustive_free(&original_setup);
curve_free(&curve);
return EXIT_FAILURE;
}
@@ -317,21 +324,19 @@ int invalid_do(config_t *cfg) {
curve_t **curves = try_calloc(nprimes * sizeof(curve_t *));
// init the invalid curve gen_f
- gen_f invalid_gens[OFFSET_END];
+ gen_f invalid_gens[OFFSET_END] = {NULL};
invalid_invalid_ginit(invalid_gens, cfg);
- exhaustive_t invalid_setup = {.generators = invalid_gens,
- .validators = common_validators,
- .argss = NULL,
- .unrolls = common_unrolls};
+ exhaustive_t *invalid_setup = exhaustive_create(
+ invalid_gens, common_validators, common_argss, common_unrolls);
debug_log_start("Starting to generate invalid curves");
size_t ncurves;
if (cfg->threads == 1) {
ncurves =
- invalid_curves(curve, cfg, primes, nprimes, curves, &invalid_setup);
+ invalid_curves(curve, cfg, primes, nprimes, curves, invalid_setup);
} else {
ncurves = invalid_curves_threaded(curve, cfg, primes, nprimes, curves,
- &invalid_setup);
+ invalid_setup);
}
debug_log_end("Finished generating invalid curves");
output_o_end(cfg);
@@ -342,6 +347,8 @@ int invalid_do(config_t *cfg) {
try_free(curves);
try_free(primes);
curve_free(&curve);
+ exhaustive_free(&original_setup);
+ exhaustive_free(&invalid_setup);
debug_log_end("Finished Invalid curve method");
return EXIT_SUCCESS;
diff --git a/src/invalid/invalid_thread.c b/src/invalid/invalid_thread.c
index be2c4aa..a68b0e5 100644
--- a/src/invalid/invalid_thread.c
+++ b/src/invalid/invalid_thread.c
@@ -13,7 +13,7 @@ void *invalid_thread(void *arg) {
thread_t *thread = (thread_t *)arg;
pari_thread_start(thread->pari_thread);
random_init();
- arg_t *invalid_argss[OFFSET_END];
+ arg_t *invalid_argss[OFFSET_END] = {NULL};
exhaustive_t invalid_setup = {.generators = thread->setup->generators,
.validators = thread->setup->validators,
.argss = invalid_argss,