diff options
| -rw-r--r-- | src/exhaustive/check.c | 15 | ||||
| -rw-r--r-- | src/exhaustive/check.h | 25 | ||||
| -rw-r--r-- | src/exhaustive/exhaustive.c | 17 | ||||
| -rw-r--r-- | src/exhaustive/exhaustive.h | 5 | ||||
| -rw-r--r-- | src/misc/types.h | 11 |
5 files changed, 67 insertions, 6 deletions
diff --git a/src/exhaustive/check.c b/src/exhaustive/check.c new file mode 100644 index 0000000..1492b3c --- /dev/null +++ b/src/exhaustive/check.c @@ -0,0 +1,15 @@ +/* + * ecgen, tool for generating Elliptic curve domain parameters + * Copyright (C) 2017 J08nY + */ +#include "check.h" +#include "util/memory.h" + +check_t *check_new(void) { return try_calloc(sizeof(check_t)); } + +void check_free(check_t **check) { + if (*check) { + try_free(*check); + *check = NULL; + } +}
\ No newline at end of file diff --git a/src/exhaustive/check.h b/src/exhaustive/check.h new file mode 100644 index 0000000..d5584da --- /dev/null +++ b/src/exhaustive/check.h @@ -0,0 +1,25 @@ +/* + * ecgen, tool for generating Elliptic curve domain parameters + * Copyright (C) 2017 J08nY + */ +/** + * @file check.h + */ +#ifndef ECGEN_CHECK_H +#define ECGEN_CHECK_H + +#include "misc/types.h" + +/** + * @brief + * @return + */ +check_t *check_new(void); + +/** + * @brief + * @param check + */ +void check_free(check_t **check); + +#endif // ECGEN_CHECK_H diff --git a/src/exhaustive/exhaustive.c b/src/exhaustive/exhaustive.c index 131abbb..2d52626 100644 --- a/src/exhaustive/exhaustive.c +++ b/src/exhaustive/exhaustive.c @@ -123,7 +123,7 @@ static void exhaustive_ginit(gen_f *generators, const config_t *cfg) { } } -static void exhaustive_cinit(check_f *validators, 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) { @@ -182,7 +182,7 @@ int exhaustive_gen_retry(curve_t *curve, const config_t *cfg, return 0; } gen_f *generators = setup->generators; - check_f *validators = setup->validators; + check_t **validators = setup->validators; arg_t **argss = setup->argss; unroll_f *unrolls = setup->unrolls; @@ -197,6 +197,17 @@ int exhaustive_gen_retry(curve_t *curve, const config_t *cfg, int new_state = state + diff; if (new_state < start_offset) new_state = start_offset; + if (diff > 0 && validators && validators[state]) { + check_t *validator = validators[state]; + for (size_t i = 0; i < validator->nchecks; ++i) { + int new_diff = validator->checks[state](curve, cfg); + if (new_diff <= 0) { + diff = new_diff; + break; + } + } + } + if (diff <= 0) { if (diff == INT_MIN || state + diff < 0) { fprintf(err, "Error generating a curve. state = %i\n", state); @@ -272,7 +283,7 @@ int exhaustive_do(config_t *cfg) { debug_log_start("Starting Exhaustive method"); gen_f generators[OFFSET_END] = {NULL}; - check_f validators[OFFSET_END] = {NULL}; + check_t *validators[OFFSET_END] = {NULL}; arg_t *argss[OFFSET_END] = {NULL}; unroll_f unrolls[OFFSET_END] = {NULL}; diff --git a/src/exhaustive/exhaustive.h b/src/exhaustive/exhaustive.h index e7e45ee..8d3c34f 100644 --- a/src/exhaustive/exhaustive.h +++ b/src/exhaustive/exhaustive.h @@ -10,9 +10,12 @@ #include "misc/types.h" +/** + * @brief + */ typedef struct { gen_f *generators; - check_f *validators; + check_t **validators; arg_t **argss; unroll_f *unrolls; } exhaustive_t; diff --git a/src/misc/types.h b/src/misc/types.h index 77ee903..e80789f 100644 --- a/src/misc/types.h +++ b/src/misc/types.h @@ -141,14 +141,21 @@ typedef UNROLL((*unroll_f)); * @brief A check function type. * @param curve A curve_t being checked * @param cfg An application config - * @param args Current optional check argument * @return state diff */ -#define CHECK(check_name) GENERATOR(check_name) +#define CHECK(check_name) int check_name(curve_t *curve, const config_t *cfg) typedef CHECK((*check_f)); /** + * @brief + */ +typedef struct { + check_f *checks; + size_t nchecks; +} check_t; + +/** * GENERATOR(gen_f) * * @param curve A curve_t being generated |
