aboutsummaryrefslogtreecommitdiff
path: root/src/exhaustive
diff options
context:
space:
mode:
authorJ08nY2017-09-29 17:48:58 +0200
committerJ08nY2017-09-29 17:48:58 +0200
commit49bd1736641a101dde23f2bbe994159ed33ef347 (patch)
tree0c2b9ea76272807c69e8e07c7d3249ab88509e9b /src/exhaustive
parent63aa880e19b49ab83132b0032ddd9e1f43029e50 (diff)
downloadecgen-49bd1736641a101dde23f2bbe994159ed33ef347.tar.gz
ecgen-49bd1736641a101dde23f2bbe994159ed33ef347.tar.zst
ecgen-49bd1736641a101dde23f2bbe994159ed33ef347.zip
Introduce check_t func.
Diffstat (limited to 'src/exhaustive')
-rw-r--r--src/exhaustive/ansi.c11
-rw-r--r--src/exhaustive/exhaustive.c54
-rw-r--r--src/exhaustive/exhaustive.h23
3 files changed, 55 insertions, 33 deletions
diff --git a/src/exhaustive/ansi.c b/src/exhaustive/ansi.c
index bbdf24e..51d20e5 100644
--- a/src/exhaustive/ansi.c
+++ b/src/exhaustive/ansi.c
@@ -48,7 +48,7 @@ static void seed_tsh(seed_t *seed, const config_t *cfg) {
pari_sp ltop = avma;
seed->ansi.t = utoi(cfg->bits);
seed->ansi.s =
- floorr(rdivii(subis(seed->ansi.t, 1), stoi(160), DEFAULTPREC));
+ floorr(rdivii(subis(seed->ansi.t, 1), stoi(160), DEFAULTPREC));
seed->ansi.h = subii(seed->ansi.t, mulis(seed->ansi.s, 160));
gerepileall(ltop, 3, &seed->ansi.t, &seed->ansi.s, &seed->ansi.h);
}
@@ -182,9 +182,12 @@ static GENERATOR(ansi_gen_equation_f2m) {
GENERATOR(ansi_gen_equation) {
switch (cfg->field) {
- case FIELD_PRIME: return ansi_gen_equation_fp(curve, cfg, args);
- case FIELD_BINARY: return ansi_gen_equation_f2m(curve, cfg, args);
- default: pari_err_BUG("Field not prime or binary?");
+ case FIELD_PRIME:
+ return ansi_gen_equation_fp(curve, cfg, args);
+ case FIELD_BINARY:
+ return ansi_gen_equation_f2m(curve, cfg, args);
+ default:
+ pari_err_BUG("Field not prime or binary?");
return INT_MIN; /* NOT REACHABLE */
}
}
diff --git a/src/exhaustive/exhaustive.c b/src/exhaustive/exhaustive.c
index e1044f9..afbacff 100644
--- a/src/exhaustive/exhaustive.c
+++ b/src/exhaustive/exhaustive.c
@@ -32,10 +32,14 @@ static void exhaustive_ginit(gen_t *generators, const config_t *cfg) {
generators[OFFSET_A] = &gen_skip;
generators[OFFSET_B] = &ansi_gen_equation;
}
- case SEED_BRAINPOOL:break;
- case SEED_BRAINPOOL_RFC:break;
- case SEED_FIPS:break;
- default:break;
+ case SEED_BRAINPOOL:
+ break;
+ case SEED_BRAINPOOL_RFC:
+ break;
+ case SEED_FIPS:
+ break;
+ default:
+ break;
}
generators[OFFSET_CURVE] = &curve_gen_nonzero;
generators[OFFSET_ORDER] = &order_gen_any;
@@ -119,6 +123,8 @@ static void exhaustive_ginit(gen_t *generators, const config_t *cfg) {
}
}
+static void exhaustive_cinit(check_t *validators, const config_t *cfg) {}
+
static void exhaustive_ainit(arg_t **argss, const config_t *cfg) {
if (cfg->anomalous) {
arg_t *field_arg = arg_new();
@@ -167,15 +173,18 @@ void exhaustive_uinit(unroll_t *unrolls, const config_t *cfg) {
}
int exhaustive_gen_retry(curve_t *curve, const config_t *cfg,
- gen_t generators[], arg_t *argss[], unroll_t unrolls[],
- offset_e start_offset, offset_e end_offset,
- int retry) {
+ const exhaustive_t *setup, offset_e start_offset,
+ offset_e end_offset, int retry) {
if (start_offset == end_offset) {
return 2;
}
if (start_offset > end_offset) {
return 0;
}
+ gen_t *generators = setup->generators;
+ check_t *validators = setup->validators;
+ arg_t **argss = setup->argss;
+ unroll_t *unrolls = setup->unrolls;
pari_sp stack_tops[OFFSET_END] = {0};
int gen_tries[OFFSET_END] = {0};
@@ -235,14 +244,19 @@ int exhaustive_gen_retry(curve_t *curve, const config_t *cfg,
return 1;
}
-int exhaustive_gen(curve_t *curve, const config_t *cfg, gen_t generators[],
- arg_t *argss[], unroll_t unrolls[], offset_e start_offset,
+int exhaustive_gen(curve_t *curve, const config_t *cfg,
+ const exhaustive_t *setup, offset_e start_offset,
offset_e end_offset) {
- return exhaustive_gen_retry(curve, cfg, generators, argss, unrolls,
- start_offset, end_offset, 0);
+ return exhaustive_gen_retry(curve, cfg, setup, start_offset, end_offset, 0);
}
-static void exhaustive_init() { anomalous_init(); }
+static void exhaustive_init(exhaustive_t *setup, const config_t *cfg) {
+ exhaustive_ginit(setup->generators, cfg);
+ exhaustive_cinit(setup->validators, cfg);
+ exhaustive_ainit(setup->argss, cfg);
+ exhaustive_uinit(setup->unrolls, cfg);
+ anomalous_init();
+}
static void exhaustive_quit(arg_t *argss[]) {
equation_quit();
@@ -258,19 +272,21 @@ int exhaustive_do(config_t *cfg) {
debug_log_start("Starting Exhaustive method");
gen_t generators[OFFSET_END] = {NULL};
+ check_t validators[OFFSET_END] = {NULL};
arg_t *argss[OFFSET_END] = {NULL};
unroll_t unrolls[OFFSET_END] = {NULL};
- exhaustive_ginit(generators, cfg);
- exhaustive_ainit(argss, cfg);
- exhaustive_uinit(unrolls, cfg);
- exhaustive_init();
+
+ exhaustive_t setup = {.generators = generators,
+ .validators = validators,
+ .argss = argss,
+ .unrolls = unrolls};
+ exhaustive_init(&setup, cfg);
output_o_begin(cfg);
for (unsigned long i = 0; i < cfg->count; ++i) {
debug_log_start("Generating new curve");
curve_t *curve = curve_new();
- if (!exhaustive_gen(curve, cfg, generators, argss, unrolls, OFFSET_SEED,
- OFFSET_END)) {
+ if (!exhaustive_gen(curve, cfg, &setup, OFFSET_SEED, OFFSET_END)) {
curve_free(&curve);
return EXIT_FAILURE;
}
@@ -284,7 +300,7 @@ int exhaustive_do(config_t *cfg) {
}
output_o_end(cfg);
- exhaustive_quit(argss);
+ exhaustive_quit(setup.argss);
debug_log_end("Finished Exhaustive method");
return EXIT_SUCCESS;
}
diff --git a/src/exhaustive/exhaustive.h b/src/exhaustive/exhaustive.h
index 446dff2..9419ff4 100644
--- a/src/exhaustive/exhaustive.h
+++ b/src/exhaustive/exhaustive.h
@@ -10,6 +10,13 @@
#include "misc/types.h"
+typedef struct {
+ gen_t *generators;
+ check_t *validators;
+ arg_t **argss;
+ unroll_t *unrolls;
+} exhaustive_t;
+
/**
*
* @param unrolls
@@ -21,31 +28,27 @@ void exhaustive_uinit(unroll_t *unrolls, const config_t *cfg);
*
* @param curve
* @param cfg
- * @param generators
- * @param argss
- * @param unrolls
+ * @param setup
* @param start_offset
* @param end_offset
* @param retry
* @return
*/
int exhaustive_gen_retry(curve_t *curve, const config_t *cfg,
- gen_t generators[], arg_t *argss[], unroll_t unrolls[],
- offset_e start_offset, offset_e end_offset, int retry);
+ const exhaustive_t *setup, offset_e start_offset,
+ offset_e end_offset, int retry);
/**
*
* @param curve
* @param config
- * @param generators
- * @param argss
- * @param unrolls
+ * @param setup
* @param start_offset
* @param end_offset
* @return
*/
-int exhaustive_gen(curve_t *curve, const config_t *cfg, gen_t generators[],
- arg_t *argss[], unroll_t unrolls[], offset_e start_offset,
+int exhaustive_gen(curve_t *curve, const config_t *cfg,
+ const exhaustive_t *setup, offset_e start_offset,
offset_e end_offset);
/**