aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/exhaustive/exhaustive.c54
-rw-r--r--src/exhaustive/exhaustive.h2
-rw-r--r--src/exhaustive/seed.c8
-rw-r--r--src/exhaustive/seed.h6
-rw-r--r--src/io/cli.c140
-rw-r--r--src/io/cli.h2
-rw-r--r--src/io/input.c3
-rw-r--r--src/io/output.c26
-rw-r--r--src/io/output.h18
-rw-r--r--src/math/arg.c1
-rw-r--r--src/math/arg.h2
-rw-r--r--src/math/curve.c16
-rw-r--r--src/math/curve.h6
-rw-r--r--src/math/equation.c34
-rw-r--r--src/math/equation.h24
-rw-r--r--src/math/field.c18
-rw-r--r--src/math/field.h4
-rw-r--r--src/math/gens.c4
-rw-r--r--src/math/gens.h4
-rw-r--r--src/math/order.c2
-rw-r--r--src/math/point.c8
-rw-r--r--src/math/point.h8
-rw-r--r--src/math/types.c2
-rw-r--r--src/math/types.h2
24 files changed, 214 insertions, 180 deletions
diff --git a/src/exhaustive/exhaustive.c b/src/exhaustive/exhaustive.c
index d7acb82..ecc9a01 100644
--- a/src/exhaustive/exhaustive.c
+++ b/src/exhaustive/exhaustive.c
@@ -4,21 +4,21 @@
*/
#include "exhaustive.h"
#include "io/output.h"
+#include "math/arg.h"
#include "math/curve.h"
#include "math/equation.h"
#include "math/field.h"
#include "math/gens.h"
#include "math/order.h"
#include "math/point.h"
-#include "math/arg.h"
#include "seed.h"
-void exhaustive_ginit(gen_t *generators, config_t *config) {
- if (config->from_seed) {
- if (config->seed) {
+void exhaustive_ginit(gen_t *generators, config_t *cfg) {
+ if (cfg->from_seed) {
+ if (cfg->seed) {
generators[OFFSET_SEED] = &seed_argument;
} else {
- if (config->random) {
+ if (cfg->random) {
generators[OFFSET_SEED] = &seed_random;
} else {
generators[OFFSET_SEED] = &seed_input;
@@ -30,7 +30,7 @@ void exhaustive_ginit(gen_t *generators, config_t *config) {
} else {
generators[OFFSET_SEED] = &gen_skip;
- if (config->random) {
+ if (cfg->random) {
generators[OFFSET_A] = &a_random;
generators[OFFSET_B] = &b_random;
} else {
@@ -38,57 +38,66 @@ void exhaustive_ginit(gen_t *generators, config_t *config) {
generators[OFFSET_B] = &b_input;
}
- if (config->koblitz) {
+ if (cfg->koblitz) {
generators[OFFSET_A] = &a_zero;
}
generators[OFFSET_CURVE] = &curve_nonzero;
- if (config->prime) {
+ if (cfg->prime) {
generators[OFFSET_ORDER] = &order_prime;
+ } else if (cfg->cofactor) {
+ generators[OFFSET_ORDER] = &order_smallfact;
} else {
generators[OFFSET_ORDER] = &order_any;
}
}
- if (config->unique) {
+ if (cfg->unique) {
generators[OFFSET_GENERATORS] = &gens_one;
} else {
generators[OFFSET_GENERATORS] = &gens_any;
}
- if (config->random) {
+ if (cfg->random) {
generators[OFFSET_FIELD] = &field_random;
} else {
generators[OFFSET_FIELD] = &field_input;
}
- switch (config->points.type) {
+ switch (cfg->points.type) {
case POINTS_RANDOM:
- if (config->points.amount) {
+ if (cfg->points.amount) {
generators[OFFSET_POINTS] = &points_random;
} else {
generators[OFFSET_POINTS] = &point_random;
}
break;
- case POINTS_PRIME: generators[OFFSET_POINTS] = &points_prime;
+ case POINTS_PRIME:
+ generators[OFFSET_POINTS] = &points_prime;
break;
}
}
-void exhaustive_ainit(arg_t **argss, config_t *config) {
+void exhaustive_ainit(arg_t **argss, config_t *cfg) {
for (size_t i = 0; i < OFFSET_END; ++i) {
argss[i] = NULL;
}
- if (config->points.type == POINTS_RANDOM) {
+ if (cfg->points.type == POINTS_RANDOM) {
arg_t *points_arg = arg_new();
- points_arg->args = &config->points.amount;
+ points_arg->args = &cfg->points.amount;
points_arg->nargs = 1;
argss[OFFSET_POINTS] = points_arg;
}
+ if (cfg->cofactor) {
+ arg_t *order_arg = arg_new();
+ order_arg->args = &cfg->cofactor_bound;
+ order_arg->nargs = 1;
+ argss[OFFSET_ORDER] = order_arg;
+ }
}
-int exhaustive_gen(curve_t *curve, config_t *config, gen_t generators[],
- arg_t *argss[], int start_offset, int end_offset) {
+int exhaustive_gen(curve_t *curve, config_t *cfg, gen_t generators[],
+ arg_t *argss[], int start_offset, int end_offset) {
if (start_offset == end_offset) {
return 1;
}
@@ -101,8 +110,7 @@ int exhaustive_gen(curve_t *curve, config_t *config, gen_t generators[],
while (state < end_offset) {
tops[state - start_offset] = avma;
- int diff =
- generators[state](curve, config, argss ? argss[state] : NULL);
+ int diff = generators[state](curve, cfg, argss ? argss[state] : NULL);
state += diff;
if (diff == INT_MIN) {
@@ -114,7 +122,7 @@ int exhaustive_gen(curve_t *curve, config_t *config, gen_t generators[],
avma = tops[state - start_offset];
}
- if (config->verbose) {
+ if (cfg->verbose) {
if (diff > 0) {
fprintf(debug, "+");
} else if (diff < 0) {
@@ -126,7 +134,7 @@ int exhaustive_gen(curve_t *curve, config_t *config, gen_t generators[],
}
}
- if (config->verbose) fprintf(debug, "\n");
+ if (cfg->verbose) fprintf(debug, "\n");
return 1;
}
@@ -149,7 +157,7 @@ int exhaustive_do(config_t *cfg) {
for (long i = 0; i < cfg->count; ++i) {
curve_t *curve = curve_new();
if (!exhaustive_gen(curve, cfg, generators, argss, OFFSET_SEED,
- OFFSET_END)) {
+ OFFSET_END)) {
curve_free(&curve);
return 1;
}
diff --git a/src/exhaustive/exhaustive.h b/src/exhaustive/exhaustive.h
index 22bfe71..ee81874 100644
--- a/src/exhaustive/exhaustive.h
+++ b/src/exhaustive/exhaustive.h
@@ -20,7 +20,7 @@
* @param end_offset
* @return
*/
-int exhaustive_gen(curve_t *curve, config_t *config, gen_t generators[],
+int exhaustive_gen(curve_t *curve, config_t *cfg, gen_t generators[],
arg_t *argss[], int start_offset, int end_offset);
/**
diff --git a/src/exhaustive/seed.c b/src/exhaustive/seed.c
index 8e379bb..e7e0738 100644
--- a/src/exhaustive/seed.c
+++ b/src/exhaustive/seed.c
@@ -43,19 +43,19 @@ GEN seed_stoi(const char *cstr) {
return gerepilecopy(ltop, seed);
}
-int seed_random(curve_t *curve, config_t *config, arg_t *args) {
+int seed_random(curve_t *curve, config_t *cfg, arg_t *args) {
curve->seed = seed_new();
curve->seed->seed = random_int(160);
return 1;
}
-int seed_argument(curve_t *curve, config_t *config, arg_t *args) {
+int seed_argument(curve_t *curve, config_t *cfg, arg_t *args) {
curve->seed = seed_new();
- curve->seed->seed = seed_stoi(config->seed);
+ curve->seed->seed = seed_stoi(cfg->seed);
return 1;
}
-int seed_input(curve_t *curve, config_t *config, arg_t *args) {
+int seed_input(curve_t *curve, config_t *cfg, arg_t *args) {
pari_sp ltop = avma;
GEN str = input_string("seed:");
diff --git a/src/exhaustive/seed.h b/src/exhaustive/seed.h
index 9107a71..067ee9e 100644
--- a/src/exhaustive/seed.h
+++ b/src/exhaustive/seed.h
@@ -38,7 +38,7 @@ void seed_free(seed_t **seed);
* @param args
* @return
*/
-int seed_random(curve_t *curve, config_t *config, arg_t *args);
+int seed_random(curve_t *curve, config_t *cfg, arg_t *args);
/**
*
@@ -47,7 +47,7 @@ int seed_random(curve_t *curve, config_t *config, arg_t *args);
* @param args
* @return
*/
-int seed_argument(curve_t *curve, config_t *config, arg_t *args);
+int seed_argument(curve_t *curve, config_t *cfg, arg_t *args);
/**
*
@@ -56,6 +56,6 @@ int seed_argument(curve_t *curve, config_t *config, arg_t *args);
* @param args
* @return
*/
-int seed_input(curve_t *curve, config_t *config, arg_t *args);
+int seed_input(curve_t *curve, config_t *cfg, arg_t *args);
#endif // ECGEN_SEED_H
diff --git a/src/io/cli.c b/src/io/cli.c
index 374b949..efebfbc 100644
--- a/src/io/cli.c
+++ b/src/io/cli.c
@@ -6,19 +6,20 @@
#include <string.h>
char doc[] =
- "ecgen, tool for generating Elliptic curve domain parameters.\v(C) 2017 "
- "Eastern Seaboard Phishing Authority";
+ "ecgen, tool for generating Elliptic curve domain parameters.\v(C) 2017 "
+ "Eastern Seaboard Phishing Authority";
char args_doc[] = "bits";
enum opt_keys {
OPT_DATADIR = 'd',
OPT_COUNT = 'c',
OPT_PRIME = 'p',
+ OPT_COFACTOR = 'k',
OPT_RANDOM = 'r',
OPT_SEED = 's',
OPT_INVALID = 'i',
OPT_ORDER = 'n',
- OPT_KOBLITZ = 'k',
+ OPT_KOBLITZ = 'K',
OPT_UNIQUE = 'u',
OPT_FORMAT = 't',
OPT_OUTPUT = 'o',
@@ -32,27 +33,28 @@ enum opt_keys {
// clang-format off
struct argp_option options[] = {
- {0, 0, 0, 0, "Field specification:", 1},
- {"fp", OPT_FP, 0, 0, "Prime field.", 1},
- {"f2m", OPT_F2M, 0, 0, "Binary field.", 1},
- {0, 0, 0, 0, "Generation options:", 2},
- {"random", OPT_RANDOM, 0, 0, "Generate a random curve.", 2},
- {"prime", OPT_PRIME, 0, 0, "Generate a curve with prime order.", 2},
- {"seed", OPT_SEED, "SEED", OPTION_ARG_OPTIONAL, "Generate a curve from SEED (ANSI X9.62 verifiable procedure).", 2},
- {"invalid", OPT_INVALID, 0, 0, "Generate a set of invalid curves (for a given curve).", 2},
- {"order", OPT_ORDER, "ORDER", 0, "Generate a curve with given order (using Complex Multiplication).", 2},
- {"koblitz", OPT_KOBLITZ, 0, 0, "Generate a Koblitz curve (a = 0).", 2},
- {"unique", OPT_UNIQUE, 0, 0, "Generate a curve with only one generator.", 2},
- {"points", OPT_POINTS, "TYPE", 0, "Generate points of given type (random/prime).", 2},
- {"count", OPT_COUNT, "COUNT", 0, "Generate multiple curves.", 2},
- {0, 0, 0, 0, "Input/Output options:", 3},
- {"format", OPT_FORMAT, "FORMAT", 0, "Format to output in. One of [csv,json], default is json.", 3},
- {"input", OPT_INPUT, "FILE", 0, "Input from file.", 3},
- {"output", OPT_OUTPUT, "FILE", 0, "Output into file. Overwrites any existing file!", 3},
- {"append", OPT_APPEND, 0, 0, "Append to output file (don't overwrite).", 3},
- {"verbose", OPT_VERBOSE, "FILE", OPTION_ARG_OPTIONAL, "Verbose logging (to stdout or file).", 3},
- {0, 0, 0, 0, "Other:", 4},
- {"data-dir", OPT_DATADIR, "DIR", 0, "PARI/GP data directory (containing seadata package).", 4},
+ {0, 0, 0, 0, "Field specification:", 1},
+ {"fp", OPT_FP, 0, 0, "Prime field.", 1},
+ {"f2m", OPT_F2M, 0, 0, "Binary field.", 1},
+ {0, 0, 0, 0, "Generation options:", 2},
+ {"random", OPT_RANDOM, 0, 0, "Generate a random curve (using Random approach).", 2},
+ {"prime", OPT_PRIME, 0, 0, "Generate a curve with prime order.", 2},
+ {"cofactor", OPT_COFACTOR, "BOUND", 0, "Generate a curve with cofactor up to BOUND.", 2},
+ {"seed", OPT_SEED, "SEED", OPTION_ARG_OPTIONAL, "Generate a curve from SEED (ANSI X9.62 verifiable procedure).", 2},
+ {"invalid", OPT_INVALID, 0, 0, "Generate a set of invalid curves, for a given curve (using Invalid curve algorithm).", 2},
+ {"order", OPT_ORDER, "ORDER", 0, "Generate a curve with given order (using Complex Multiplication).", 2},
+ {"koblitz", OPT_KOBLITZ, 0, 0, "Generate a Koblitz curve (a = 0).", 2},
+ {"unique", OPT_UNIQUE, 0, 0, "Generate a curve with only one generator.", 2},
+ {"points", OPT_POINTS, "TYPE", 0, "Generate points of given type (random/prime).", 2},
+ {"count", OPT_COUNT, "COUNT", 0, "Generate multiple curves.", 2},
+ {0, 0, 0, 0, "Input/Output options:", 3},
+ {"format", OPT_FORMAT, "FORMAT", 0, "Format to output in. One of [csv,json], default is json.", 3},
+ {"input", OPT_INPUT, "FILE", 0, "Input from file.", 3},
+ {"output", OPT_OUTPUT, "FILE", 0, "Output into file. Overwrites any existing file!", 3},
+ {"append", OPT_APPEND, 0, 0, "Append to output file (don't overwrite).", 3},
+ {"verbose", OPT_VERBOSE, "FILE", OPTION_ARG_OPTIONAL, "Verbose logging (to stdout or file).", 3},
+ {0, 0, 0, 0, "Other:", 4},
+ {"data-dir", OPT_DATADIR, "DIR", 0, "PARI/GP data directory (containing seadata package).", 4},
{0}
};
// clang-format on
@@ -61,7 +63,8 @@ error_t cli_parse(int key, char *arg, struct argp_state *state) {
struct config_t *cfg = state->input;
switch (key) {
- case OPT_DATADIR: cfg->datadir = arg;
+ case OPT_DATADIR:
+ cfg->datadir = arg;
break;
case OPT_COUNT:
if (arg) {
@@ -76,40 +79,55 @@ error_t cli_parse(int key, char *arg, struct argp_state *state) {
cfg->format = FORMAT_JSON;
} else {
argp_failure(state, 1, 0,
- "Invalid format specified. One of [csv, json] "
- "is valid.");
+ "Invalid format specified. One of [csv, json] "
+ "is valid.");
}
} else {
argp_failure(
- state, 1, 0,
- "You have to specify a format with the format option.");
+ state, 1, 0,
+ "You have to specify a format with the format option.");
}
break;
- case OPT_INPUT: cfg->input = arg;
+ case OPT_INPUT:
+ cfg->input = arg;
break;
- case OPT_OUTPUT: cfg->output = arg;
+ case OPT_OUTPUT:
+ cfg->output = arg;
break;
- case OPT_APPEND: cfg->append = true;
+ case OPT_APPEND:
+ cfg->append = true;
break;
- case OPT_VERBOSE: cfg->verbose++;
+ case OPT_VERBOSE:
+ cfg->verbose++;
if (arg) {
cfg->debug = arg;
}
break;
- case OPT_RANDOM: cfg->random = true;
+ case OPT_RANDOM:
+ cfg->random = true;
break;
- case OPT_PRIME: cfg->prime = true;
+ case OPT_PRIME:
+ cfg->prime = true;
break;
- case OPT_INVALID: cfg->invalid = true;
+ case OPT_COFACTOR:
+ cfg->cofactor = true;
+ if (arg) {
+ cfg->cofactor_bound = strtol(arg, NULL, 10);
+ }
+ case OPT_INVALID:
+ cfg->invalid = true;
break;
- case OPT_ORDER: cfg->cm = true;
+ case OPT_ORDER:
+ cfg->cm = true;
if (arg) {
cfg->order = arg;
}
break;
- case OPT_KOBLITZ: cfg->koblitz = true;
+ case OPT_KOBLITZ:
+ cfg->koblitz = true;
break;
- case OPT_UNIQUE: cfg->unique = true;
+ case OPT_UNIQUE:
+ cfg->unique = true;
break;
case OPT_POINTS:
if (arg) {
@@ -123,24 +141,28 @@ error_t cli_parse(int key, char *arg, struct argp_state *state) {
argp_failure(state, 1, 0, "Unknow point type");
}
} else {
- argp_failure(state, 1, 0, "You have to specify what points you want.");
+ argp_failure(state, 1, 0,
+ "You have to specify what points you want.");
}
break;
- case OPT_SEED: cfg->from_seed = true;
+ case OPT_SEED:
+ cfg->from_seed = true;
if (arg) {
// ANSI X9.62 specifies seed as at least 160 bits in length.
if (strlen(arg) < 20) {
argp_failure(
- state, 1, 0,
- "SEED must be at least 160 bits (20 characters).");
+ state, 1, 0,
+ "SEED must be at least 160 bits (20 characters).");
}
cfg->seed = arg;
}
break;
- case OPT_FP: cfg->field = FIELD_PRIME;
+ case OPT_FP:
+ cfg->field = FIELD_PRIME;
cfg->prime_field = true;
break;
- case OPT_F2M: cfg->field = FIELD_BINARY;
+ case OPT_F2M:
+ cfg->field = FIELD_BINARY;
cfg->binary_field = true;
break;
case ARGP_KEY_ARG:
@@ -155,31 +177,35 @@ error_t cli_parse(int key, char *arg, struct argp_state *state) {
// Only one field
if (!cfg->prime_field && !cfg->binary_field) {
argp_failure(state, 1, 0,
- "Specify field type, prime or binary, with --fp / "
- "--f2m (but not both).");
+ "Specify field type, prime or binary, with --fp / "
+ "--f2m (but not both).");
}
// Invalid is not prime or seed by definition.
- if (cfg->invalid && (cfg->prime || cfg->from_seed)) {
+ if (cfg->invalid &&
+ (cfg->prime || cfg->from_seed || cfg->cofactor)) {
// not seed, not prime
argp_failure(state, 1, 0,
- "Invalid curve generation can not generate curves "
- "from seed, exhaustive or prime order.");
+ "Invalid curve generation can not generate curves "
+ "from seed, exhaustive or prime order.");
}
- if (cfg->cm && (cfg->prime || cfg->from_seed || cfg->invalid)) {
+ if (cfg->cm && (cfg->prime || cfg->from_seed || cfg->invalid ||
+ cfg->cofactor)) {
argp_failure(state, 1, 0,
- "Fixed order curve generation can not generate "
- "curves from seed, or invalid curves. Prime order "
- "also doesn't make sense if the given one isn't "
- "prime.");
+ "Fixed order curve generation can not generate "
+ "curves from seed, or invalid curves. Prime order "
+ "also doesn't make sense if the given one isn't "
+ "prime.");
}
// default values
if (!cfg->count) {
cfg->count = 1;
}
break;
- case ARGP_KEY_NO_ARGS: argp_usage(state);
+ case ARGP_KEY_NO_ARGS:
+ argp_usage(state);
break;
- default: return ARGP_ERR_UNKNOWN;
+ default:
+ return ARGP_ERR_UNKNOWN;
}
return 0;
}
diff --git a/src/io/cli.h b/src/io/cli.h
index 3facaff..c65f125 100644
--- a/src/io/cli.h
+++ b/src/io/cli.h
@@ -36,6 +36,8 @@ typedef struct config_t {
bool cm;
char *order;
bool koblitz;
+ bool cofactor;
+ long cofactor_bound;
bool from_seed;
char *seed;
bool unique;
diff --git a/src/io/input.c b/src/io/input.c
index 3865d79..34aeb5a 100644
--- a/src/io/input.c
+++ b/src/io/input.c
@@ -22,7 +22,8 @@ GEN input_i(const char *prompt, long bits) {
free(line);
return gen_m1;
}
- for (size_t i = 0, j = 0; (line[j] = line[i]); j += !isspace(line[i++]));
+ for (size_t i = 0, j = 0; (line[j] = line[i]); j += !isspace(line[i++]))
+ ;
pari_sp ltop = avma;
GEN in = strtoi(line);
diff --git a/src/io/output.c b/src/io/output.c
index 88b120e..cb718fa 100644
--- a/src/io/output.c
+++ b/src/io/output.c
@@ -11,7 +11,7 @@
FILE *out;
FILE *debug;
-char *output_scsv(curve_t *curve, config_t *config) {
+char *output_scsv(curve_t *curve, config_t *cfg) {
pari_sp ltop = avma;
GEN vector = curve_params(curve);
@@ -48,23 +48,21 @@ char *output_scsv(curve_t *curve, config_t *config) {
return result;
}
-void output_fcsv(FILE *out, curve_t *curve, config_t *config) {
- char *string = output_scsv(curve, config);
+void output_fcsv(FILE *out, curve_t *curve, config_t *cfg) {
+ char *string = output_scsv(curve, cfg);
fprintf(out, "%s\n", string);
free(string);
}
-void output_csv(curve_t *curve, config_t *config) {
- output_fcsv(out, curve, config);
-}
+void output_csv(curve_t *curve, config_t *cfg) { output_fcsv(out, curve, cfg); }
-JSON_Value *output_jjson(curve_t *curve, config_t *config) {
+JSON_Value *output_jjson(curve_t *curve, config_t *cfg) {
pari_sp ltop = avma;
// root object/value is curve
JSON_Value *root_value = json_value_init_object();
JSON_Object *root_object = json_value_get_object(root_value);
- switch (config->field) {
+ switch (cfg->field) {
case FIELD_PRIME: {
char *prime = pari_sprintf("%P#x", curve->field);
json_object_dotset_string(root_object, "field.p", prime);
@@ -168,22 +166,22 @@ JSON_Value *output_jjson(curve_t *curve, config_t *config) {
return root_value;
}
-char *output_sjson(curve_t *curve, config_t *config) {
- JSON_Value *root_value = output_jjson(curve, config);
+char *output_sjson(curve_t *curve, config_t *cfg) {
+ JSON_Value *root_value = output_jjson(curve, cfg);
char *result = json_serialize_to_string_pretty(root_value);
json_value_free(root_value);
return result;
}
-void output_fjson(FILE *out, curve_t *curve, config_t *config) {
- char *s = output_sjson(curve, config);
+void output_fjson(FILE *out, curve_t *curve, config_t *cfg) {
+ char *s = output_sjson(curve, cfg);
fprintf(out, "%s\n", s);
json_free_serialized_string(s);
}
-void output_json(curve_t *curve, config_t *config) {
- output_fjson(out, curve, config);
+void output_json(curve_t *curve, config_t *cfg) {
+ output_fjson(out, curve, cfg);
}
void output_init(config_t *cfg) {
diff --git a/src/io/output.h b/src/io/output.h
index ea9a97e..283b701 100644
--- a/src/io/output.h
+++ b/src/io/output.h
@@ -18,7 +18,7 @@
* @param config
* @return
*/
-char *output_scsv(curve_t *curve, config_t *config);
+char *output_scsv(curve_t *curve, config_t *cfg);
/**
*
@@ -26,14 +26,14 @@ char *output_scsv(curve_t *curve, config_t *config);
* @param curve
* @param config
*/
-void output_fcsv(FILE *out, curve_t *curve, config_t *config);
+void output_fcsv(FILE *out, curve_t *curve, config_t *cfg);
/**
*
* @param curve
* @param config
*/
-void output_csv(curve_t *curve, config_t *config);
+void output_csv(curve_t *curve, config_t *cfg);
/**
*
@@ -41,7 +41,7 @@ void output_csv(curve_t *curve, config_t *config);
* @param config
* @return
*/
-char *output_sjson(curve_t *curve, config_t *config);
+char *output_sjson(curve_t *curve, config_t *cfg);
/**
*
@@ -49,14 +49,14 @@ char *output_sjson(curve_t *curve, config_t *config);
* @param curve
* @param config
*/
-void output_fjson(FILE *out, curve_t *curve, config_t *config);
+void output_fjson(FILE *out, curve_t *curve, config_t *cfg);
/**
*
* @param curve
* @param config
*/
-void output_json(curve_t *curve, config_t *config);
+void output_json(curve_t *curve, config_t *cfg);
/**
*
@@ -64,7 +64,7 @@ void output_json(curve_t *curve, config_t *config);
* @param config
* @return
*/
-char *(*output_s)(curve_t *curve, config_t *config);
+char *(*output_s)(curve_t *curve, config_t *cfg);
/**
*
@@ -72,14 +72,14 @@ char *(*output_s)(curve_t *curve, config_t *config);
* @param curve
* @param config
*/
-void (*output_f)(FILE *out, curve_t *curve, config_t *config);
+void (*output_f)(FILE *out, curve_t *curve, config_t *cfg);
/**
*
* @param curve
* @param config
*/
-void (*output_o)(curve_t *curve, config_t *config);
+void (*output_o)(curve_t *curve, config_t *cfg);
/**
*
diff --git a/src/math/arg.c b/src/math/arg.c
index be3f92e..991eebb 100644
--- a/src/math/arg.c
+++ b/src/math/arg.c
@@ -4,7 +4,6 @@
*/
#include "arg.h"
-
arg_t *arg_new() {
arg_t *arg = pari_malloc(sizeof(arg_t));
if (!arg) {
diff --git a/src/math/arg.h b/src/math/arg.h
index 55e1b19..a7859dd 100644
--- a/src/math/arg.h
+++ b/src/math/arg.h
@@ -20,6 +20,6 @@ arg_t *arg_new();
* @brief
* @param arg
*/
-void arg_free (arg_t **arg);
+void arg_free(arg_t **arg);
#endif // ECGEN_ARG_H
diff --git a/src/math/curve.c b/src/math/curve.c
index 284cd39..5b609fa 100644
--- a/src/math/curve.c
+++ b/src/math/curve.c
@@ -41,7 +41,7 @@ void curve_free(curve_t **curve) {
}
}
-int curve_any(curve_t *curve, config_t *config, arg_t *args) {
+int curve_any(curve_t *curve, config_t *cfg, arg_t *args) {
pari_sp ltop = avma;
GEN v = gen_0;
switch (typ(curve->field)) {
@@ -64,9 +64,9 @@ int curve_any(curve_t *curve, config_t *config, arg_t *args) {
return 1;
}
-int curve_nonzero(curve_t *curve, config_t *config, arg_t *args) {
+int curve_nonzero(curve_t *curve, config_t *cfg, arg_t *args) {
pari_sp ltop = avma;
- curve_any(curve, config, args);
+ curve_any(curve, cfg, args);
if (gequal0(ell_get_disc(curve->curve))) {
avma = ltop;
return -3;
@@ -75,22 +75,22 @@ int curve_nonzero(curve_t *curve, config_t *config, arg_t *args) {
}
}
-int curve_seed_fp(curve_t *curve, config_t *config, arg_t *args) {
+int curve_seed_fp(curve_t *curve, config_t *cfg, arg_t *args) {
// TODO implement
return INT_MIN;
}
-int curve_seed_f2m(curve_t *curve, config_t *config, arg_t *args) {
+int curve_seed_f2m(curve_t *curve, config_t *cfg, arg_t *args) {
// TODO implement
return INT_MIN;
}
-int curve_seed(curve_t *curve, config_t *config, arg_t *args) {
+int curve_seed(curve_t *curve, config_t *cfg, arg_t *args) {
switch (typ(curve->field)) {
case t_INT:
- return curve_seed_fp(curve, config, args);
+ return curve_seed_fp(curve, cfg, args);
case t_FFELT:
- return curve_seed_f2m(curve, config, args);
+ return curve_seed_f2m(curve, cfg, args);
default:
pari_err_TYPE("curve_seed", curve->field);
return INT_MIN; /* NOT REACHABLE */
diff --git a/src/math/curve.h b/src/math/curve.h
index 3da391b..25e4f51 100644
--- a/src/math/curve.h
+++ b/src/math/curve.h
@@ -22,7 +22,7 @@
* @param args unused
* @return state diff
*/
-int curve_any(curve_t *curve, config_t *config, arg_t *args);
+int curve_any(curve_t *curve, config_t *cfg, arg_t *args);
/**
* GENERATOR(gen_t)
@@ -34,7 +34,7 @@ int curve_any(curve_t *curve, config_t *config, arg_t *args);
* @param args unused
* @return state diff
*/
-int curve_nonzero(curve_t *curve, config_t *config, arg_t *args);
+int curve_nonzero(curve_t *curve, config_t *cfg, arg_t *args);
/**
* GENERATOR(gen_t)
@@ -47,7 +47,7 @@ int curve_nonzero(curve_t *curve, config_t *config, arg_t *args);
* @param args unused
* @return state diff
*/
-int curve_seed(curve_t *curve, config_t *config, arg_t *args);
+int curve_seed(curve_t *curve, config_t *cfg, arg_t *args);
/**
* Serializes curve parameters into a t_VEC:
diff --git a/src/math/equation.c b/src/math/equation.c
index 45b849b..d676350 100644
--- a/src/math/equation.c
+++ b/src/math/equation.c
@@ -5,14 +5,14 @@
#include "equation.h"
#include "io/input.h"
-int a_random(curve_t *curve, config_t *config, arg_t *args) {
+int a_random(curve_t *curve, config_t *cfg, arg_t *args) {
curve->a = genrand(curve->field);
return 1;
}
-int a_input(curve_t *curve, config_t *config, arg_t *args) {
+int a_input(curve_t *curve, config_t *cfg, arg_t *args) {
pari_sp ltop = avma;
- GEN inp = input_int("a:", config->bits);
+ GEN inp = input_int("a:", cfg->bits);
if (gequalm1(inp)) {
avma = ltop;
return 0;
@@ -25,13 +25,13 @@ int a_input(curve_t *curve, config_t *config, arg_t *args) {
static GEN a = NULL;
static curve_t *curve_a = NULL;
-int a_once(curve_t *curve, config_t *config, arg_t *args) {
+int a_once(curve_t *curve, config_t *cfg, arg_t *args) {
if (a && curve_a == curve) {
curve->a = gcopy(a);
return 1;
}
- int inp = a_input(curve, config, args);
+ int inp = a_input(curve, cfg, args);
if (inp > 0) {
a = gclone(curve->a);
curve_a = curve;
@@ -41,29 +41,29 @@ int a_once(curve_t *curve, config_t *config, arg_t *args) {
}
}
-int a_zero(curve_t *curve, config_t *config, arg_t *args) {
+int a_zero(curve_t *curve, config_t *cfg, arg_t *args) {
curve->a = gen_0;
return 1;
}
-int a_one(curve_t *curve, config_t *config, arg_t *args) {
+int a_one(curve_t *curve, config_t *cfg, arg_t *args) {
curve->a = gen_1;
return 1;
}
-int a_seed(curve_t *curve, config_t *config, arg_t *args) {
+int a_seed(curve_t *curve, config_t *cfg, arg_t *args) {
// TODO implement
return INT_MIN;
}
-int b_random(curve_t *curve, config_t *config, arg_t *args) {
+int b_random(curve_t *curve, config_t *cfg, arg_t *args) {
curve->b = genrand(curve->field);
return 1;
}
-int b_input(curve_t *curve, config_t *config, arg_t *args) {
+int b_input(curve_t *curve, config_t *cfg, arg_t *args) {
pari_sp ltop = avma;
- GEN inp = input_int("b:", config->bits);
+ GEN inp = input_int("b:", cfg->bits);
if (gequalm1(inp)) {
avma = ltop;
return 0;
@@ -74,15 +74,15 @@ int b_input(curve_t *curve, config_t *config, arg_t *args) {
}
static GEN b = NULL;
-static curve_t* curve_b = NULL;
+static curve_t *curve_b = NULL;
-int b_once(curve_t *curve, config_t *config, arg_t *args) {
+int b_once(curve_t *curve, config_t *cfg, arg_t *args) {
if (b && curve_b == curve) {
curve->b = gcopy(b);
return 1;
}
- int inp = b_input(curve, config, args);
+ int inp = b_input(curve, cfg, args);
if (inp > 0) {
b = gclone(curve->b);
curve_b = curve;
@@ -92,17 +92,17 @@ int b_once(curve_t *curve, config_t *config, arg_t *args) {
}
}
-int b_zero(curve_t *curve, config_t *config, arg_t *args) {
+int b_zero(curve_t *curve, config_t *cfg, arg_t *args) {
curve->b = gen_0;
return 1;
}
-int b_one(curve_t *curve, config_t *config, arg_t *args) {
+int b_one(curve_t *curve, config_t *cfg, arg_t *args) {
curve->b = gen_1;
return 1;
}
-int b_seed(curve_t *curve, config_t *config, arg_t *args) {
+int b_seed(curve_t *curve, config_t *cfg, arg_t *args) {
// TODO implement
return INT_MIN;
}
diff --git a/src/math/equation.h b/src/math/equation.h
index 28ded06..03d87af 100644
--- a/src/math/equation.h
+++ b/src/math/equation.h
@@ -22,7 +22,7 @@
* @param args
* @return state diff
*/
-int a_random(curve_t *curve, config_t *config, arg_t *args);
+int a_random(curve_t *curve, config_t *cfg, arg_t *args);
/**
* GENERATOR(gen_t)
@@ -33,7 +33,7 @@ int a_random(curve_t *curve, config_t *config, arg_t *args);
* @param args
* @return state diff
*/
-int a_input(curve_t *curve, config_t *config, arg_t *args);
+int a_input(curve_t *curve, config_t *cfg, arg_t *args);
/**
* GENERATOR(gen_t)
@@ -44,7 +44,7 @@ int a_input(curve_t *curve, config_t *config, arg_t *args);
* @param args
* @return
*/
-int a_once(curve_t *curve, config_t *config, arg_t *args);
+int a_once(curve_t *curve, config_t *cfg, arg_t *args);
/**
* GENERATOR(gen_t)
@@ -55,7 +55,7 @@ int a_once(curve_t *curve, config_t *config, arg_t *args);
* @param args
* @return state diff
*/
-int a_zero(curve_t *curve, config_t *config, arg_t *args);
+int a_zero(curve_t *curve, config_t *cfg, arg_t *args);
/**
* GENERATOR(gen_t)
@@ -66,7 +66,7 @@ int a_zero(curve_t *curve, config_t *config, arg_t *args);
* @param args
* @return state diff
*/
-int a_one(curve_t *curve, config_t *config, arg_t *args);
+int a_one(curve_t *curve, config_t *cfg, arg_t *args);
/**
* @brief
@@ -75,7 +75,7 @@ int a_one(curve_t *curve, config_t *config, arg_t *args);
* @param args
* @return
*/
-int a_seed(curve_t *curve, config_t *config, arg_t *args);
+int a_seed(curve_t *curve, config_t *cfg, arg_t *args);
/**
* GENERATOR(gen_t)
@@ -87,7 +87,7 @@ int a_seed(curve_t *curve, config_t *config, arg_t *args);
* @param args
* @return state diff
*/
-int b_random(curve_t *curve, config_t *config, arg_t *args);
+int b_random(curve_t *curve, config_t *cfg, arg_t *args);
/**
* GENERATOR(gen_t)
@@ -98,7 +98,7 @@ int b_random(curve_t *curve, config_t *config, arg_t *args);
* @param args
* @return state diff
*/
-int b_input(curve_t *curve, config_t *config, arg_t *args);
+int b_input(curve_t *curve, config_t *cfg, arg_t *args);
/**
* GENERATOR(gen_t)
@@ -109,7 +109,7 @@ int b_input(curve_t *curve, config_t *config, arg_t *args);
* @param args
* @return
*/
-int b_once(curve_t *curve, config_t *config, arg_t *args);
+int b_once(curve_t *curve, config_t *cfg, arg_t *args);
/**
* GENERATOR(gen_t)
@@ -120,7 +120,7 @@ int b_once(curve_t *curve, config_t *config, arg_t *args);
* @param args
* @return state diff
*/
-int b_zero(curve_t *curve, config_t *config, arg_t *args);
+int b_zero(curve_t *curve, config_t *cfg, arg_t *args);
/**
* GENERATOR(gen_t)
@@ -131,7 +131,7 @@ int b_zero(curve_t *curve, config_t *config, arg_t *args);
* @param args
* @return state diff
*/
-int b_one(curve_t *curve, config_t *config, arg_t *args);
+int b_one(curve_t *curve, config_t *cfg, arg_t *args);
/**
* @brief
@@ -140,7 +140,7 @@ int b_one(curve_t *curve, config_t *config, arg_t *args);
* @param args
* @return
*/
-int b_seed(curve_t *curve, config_t *config, arg_t *args);
+int b_seed(curve_t *curve, config_t *cfg, arg_t *args);
/**
*
diff --git a/src/math/field.c b/src/math/field.c
index 2d6d358..08172bf 100644
--- a/src/math/field.c
+++ b/src/math/field.c
@@ -19,24 +19,24 @@ GEN field_binaryr(long bits) {
}
}
-int field_random(curve_t *curve, config_t *config, arg_t *args) {
- switch (config->field) {
+int field_random(curve_t *curve, config_t *cfg, arg_t *args) {
+ switch (cfg->field) {
case FIELD_PRIME:
- curve->field = field_primer(config->bits);
+ curve->field = field_primer(cfg->bits);
return 1;
case FIELD_BINARY:
- curve->field = field_binaryr(config->bits);
+ curve->field = field_binaryr(cfg->bits);
return 1;
default:
return INT_MIN; /* NOT REACHABLE */
}
}
-int field_input(curve_t *curve, config_t *config, arg_t *args) {
+int field_input(curve_t *curve, config_t *cfg, arg_t *args) {
pari_sp ltop = avma;
- switch (config->field) {
+ switch (cfg->field) {
case FIELD_PRIME: {
- GEN p = input_prime("p:", config->bits);
+ GEN p = input_prime("p:", cfg->bits);
if (equalii(p, gen_m1)) {
avma = ltop;
return 0;
@@ -67,8 +67,8 @@ int field_input(curve_t *curve, config_t *config, arg_t *args) {
return 0;
}
- GEN v = gtovec0(gen_0, config->bits + 1);
- gel(v, config->bits + 1) = gen_1;
+ GEN v = gtovec0(gen_0, cfg->bits + 1);
+ gel(v, cfg->bits + 1) = gen_1;
if (gsigne(e1) == 1) gel(v, itos(e1) + 1) = gen_1;
if (gsigne(e2) == 1) gel(v, itos(e2) + 1) = gen_1;
if (gsigne(e3) == 1) gel(v, itos(e3) + 1) = gen_1;
diff --git a/src/math/field.h b/src/math/field.h
index 0491a83..3ed300c 100644
--- a/src/math/field.h
+++ b/src/math/field.h
@@ -21,7 +21,7 @@
* @param args unused
* @return state diff
*/
-int field_random(curve_t *curve, config_t *config, arg_t *args);
+int field_random(curve_t *curve, config_t *cfg, arg_t *args);
/**
* GENERATOR(gen_t)
@@ -34,7 +34,7 @@ int field_random(curve_t *curve, config_t *config, arg_t *args);
* @param args unused
* @return state diff
*/
-int field_input(curve_t *curve, config_t *config, arg_t *args);
+int field_input(curve_t *curve, config_t *cfg, arg_t *args);
/**
*
diff --git a/src/math/gens.c b/src/math/gens.c
index 93106b7..e535c62 100644
--- a/src/math/gens.c
+++ b/src/math/gens.c
@@ -22,13 +22,13 @@ int gens_put(curve_t *curve, GEN generators, long len) {
return 1;
}
-int gens_any(curve_t *curve, config_t *config, arg_t *args) {
+int gens_any(curve_t *curve, config_t *cfg, arg_t *args) {
GEN generators = ellff_get_gens(curve->curve);
long len = glength(generators);
return gens_put(curve, generators, len);
}
-int gens_one(curve_t *curve, config_t *config, arg_t *args) {
+int gens_one(curve_t *curve, config_t *cfg, arg_t *args) {
pari_sp ltop = avma;
GEN generators = ellff_get_gens(curve->curve);
long len = glength(generators);
diff --git a/src/math/gens.h b/src/math/gens.h
index a1ae34f..ba22358 100644
--- a/src/math/gens.h
+++ b/src/math/gens.h
@@ -18,7 +18,7 @@
* @param args
* @return
*/
-int gens_any(curve_t *curve, config_t *config, arg_t *args);
+int gens_any(curve_t *curve, config_t *cfg, arg_t *args);
/**
* @brief
@@ -27,6 +27,6 @@ int gens_any(curve_t *curve, config_t *config, arg_t *args);
* @param args
* @return
*/
-int gens_one(curve_t *curve, config_t *config, arg_t *args);
+int gens_one(curve_t *curve, config_t *cfg, arg_t *args);
#endif // ECGEN_GENS_H
diff --git a/src/math/order.c b/src/math/order.c
index 83d7e0d..8902524 100644
--- a/src/math/order.c
+++ b/src/math/order.c
@@ -11,7 +11,7 @@ int order_any(curve_t *curve, config_t *cfg, arg_t *args) {
int order_smallfact(curve_t *curve, config_t *cfg, arg_t *args) {
if (!args) {
- fprintf(stderr, "No args to an arged function. points_random");
+ fprintf(stderr, "No args to an arged function. order_smallfact");
return INT_MIN;
}
pari_ulong smallfact = *(pari_ulong *)args->args;
diff --git a/src/math/point.c b/src/math/point.c
index 6368c60..fb2235e 100644
--- a/src/math/point.c
+++ b/src/math/point.c
@@ -61,7 +61,7 @@ void points_free_deep(point_t ***points, size_t npoints) {
}
}
-int point_random(curve_t *curve, config_t *config, arg_t *args) {
+int point_random(curve_t *curve, config_t *cfg, arg_t *args) {
points_free_deep(&curve->points, curve->npoints);
point_t *p = point_new();
@@ -74,7 +74,7 @@ int point_random(curve_t *curve, config_t *config, arg_t *args) {
return 1;
}
-int points_random(curve_t *curve, config_t *config, arg_t *args) {
+int points_random(curve_t *curve, config_t *cfg, arg_t *args) {
if (!args) {
fprintf(stderr, "No args to an arged function. points_random");
return INT_MIN;
@@ -110,7 +110,7 @@ int points_random(curve_t *curve, config_t *config, arg_t *args) {
}
*/
-int points_trial(curve_t *curve, config_t *config, arg_t *args) {
+int points_trial(curve_t *curve, config_t *cfg, arg_t *args) {
// TODO stack code!!!
if (!args) {
fprintf(stderr, "No args to an arged function. points_trial");
@@ -149,7 +149,7 @@ int points_trial(curve_t *curve, config_t *config, arg_t *args) {
return 1;
}
-int points_prime(curve_t *curve, config_t *config, arg_t *args) {
+int points_prime(curve_t *curve, config_t *cfg, arg_t *args) {
// TODO stack code!!!
points_free_deep(&curve->points, curve->npoints);
diff --git a/src/math/point.h b/src/math/point.h
index 76f095a..4ced232 100644
--- a/src/math/point.h
+++ b/src/math/point.h
@@ -68,7 +68,7 @@ void points_free_deep(point_t ***points, size_t npoints);
* @param args unused
* @return state diff
*/
-int point_random(curve_t *curve, config_t *config, arg_t *args);
+int point_random(curve_t *curve, config_t *cfg, arg_t *args);
/**
* GENERATOR(gen_t)
@@ -78,7 +78,7 @@ int point_random(curve_t *curve, config_t *config, arg_t *args);
* @param args size_t number of points to generate
* @return state diff
*/
-int points_random(curve_t *curve, config_t *config, arg_t *args);
+int points_random(curve_t *curve, config_t *cfg, arg_t *args);
/**
* GENERATOR(gen_t)
@@ -96,7 +96,7 @@ int points_random(curve_t *curve, config_t *config, arg_t *args);
* @param args
* @return state diff
*/
-int points_trial(curve_t *curve, config_t *config, arg_t *args);
+int points_trial(curve_t *curve, config_t *cfg, arg_t *args);
/**
* GENERATOR(gen_t)
@@ -110,6 +110,6 @@ int points_trial(curve_t *curve, config_t *config, arg_t *args);
* @param args
* @return state diff
*/
-int points_prime(curve_t *curve, config_t *config, arg_t *args);
+int points_prime(curve_t *curve, config_t *cfg, arg_t *args);
#endif // ECGEN_POINT_H
diff --git a/src/math/types.c b/src/math/types.c
index bf1bb5d..431c9c2 100644
--- a/src/math/types.c
+++ b/src/math/types.c
@@ -4,4 +4,4 @@
*/
#include "types.h"
-int gen_skip(curve_t *curve, config_t *config, arg_t *args) { return 1; }
+int gen_skip(curve_t *curve, config_t *cfg, arg_t *args) { return 1; }
diff --git a/src/math/types.h b/src/math/types.h
index 43ee7cf..38dadbe 100644
--- a/src/math/types.h
+++ b/src/math/types.h
@@ -58,6 +58,6 @@ typedef int (*gen_t)(curve_t *, config_t *, arg_t *);
* @param args
* @return
*/
-int gen_skip(curve_t *curve, config_t *config, arg_t *args);
+int gen_skip(curve_t *curve, config_t *cfg, arg_t *args);
#endif // ECGEN_TYPES_H