aboutsummaryrefslogtreecommitdiff
path: root/src/io
diff options
context:
space:
mode:
Diffstat (limited to 'src/io')
-rw-r--r--src/io/cli.c36
-rw-r--r--src/io/cli.h2
-rw-r--r--src/io/input.c2
-rw-r--r--src/io/input.h2
-rw-r--r--src/io/output.c3
-rw-r--r--src/io/output.h3
6 files changed, 30 insertions, 18 deletions
diff --git a/src/io/cli.c b/src/io/cli.c
index d00a0c5..6aaadc8 100644
--- a/src/io/cli.c
+++ b/src/io/cli.c
@@ -21,6 +21,7 @@ enum opt_keys {
OPT_OUTPUT = 'o',
OPT_INPUT = 'f',
OPT_APPEND = 'a',
+ OPT_VERBOSE = 'v',
OPT_FP = 1,
OPT_F2M = 2,
};
@@ -28,20 +29,21 @@ enum opt_keys {
// clang-format off
struct argp_option options[] = {
// Field specification
- {"fp", OPT_FP, 0, 0, "Prime field."},
- {"f2m", OPT_F2M, 0, 0, "Binary field."},
+ {"fp", OPT_FP, 0, 0, "Prime field."},
+ {"f2m", OPT_F2M, 0, 0, "Binary field."},
// Curve specification
- {"random", OPT_RANDOM, 0, 0, "Generate a random curve."},
- {"prime", OPT_PRIME, 0, 0, "Generate a curve with prime order."},
- {"seed", OPT_SEED, "SEED", OPTION_ARG_OPTIONAL, "Generate a curve from SEED (ANSI X9.62 verifiable procedure)."},
- {"invalid", OPT_INVALID, 0, 0, "Generate a set of invalid curves (for a given curve)."},
- {"order", OPT_ORDER, "ORDER", 0, "Generate a curve with given order (using Complex Multiplication)."},
- {"koblitz", OPT_KOBLITZ, 0, 0, "Generate a Koblitz curve."},
+ {"random", OPT_RANDOM, 0, 0, "Generate a random curve."},
+ {"prime", OPT_PRIME, 0, 0, "Generate a curve with prime order."},
+ {"seed", OPT_SEED, "SEED", OPTION_ARG_OPTIONAL, "Generate a curve from SEED (ANSI X9.62 verifiable procedure)."},
+ {"invalid", OPT_INVALID, 0, 0, "Generate a set of invalid curves (for a given curve)."},
+ {"order", OPT_ORDER, "ORDER", 0, "Generate a curve with given order (using Complex Multiplication)."},
+ {"koblitz", OPT_KOBLITZ, 0, 0, "Generate a Koblitz curve."},
// Other
- {"data-dir", OPT_DATADIR, "DIR", 0, "PARI/GP data directory (containing seadata package)."},
- {"input", OPT_INPUT, "FILE", 0, "Input from file."},
- {"output", OPT_OUTPUT, "FILE", 0, "Output into file. Overwrites any existing file!"},
- {"append", OPT_APPEND, 0, 0, "Append to output file (don't overwrite)."},
+ {"data-dir", OPT_DATADIR, "DIR", 0, "PARI/GP data directory (containing seadata package)."},
+ {"input", OPT_INPUT, "FILE", 0, "Input from file."},
+ {"output", OPT_OUTPUT, "FILE", 0, "Output into file. Overwrites any existing file!"},
+ {"append", OPT_APPEND, 0, 0, "Append to output file (don't overwrite)."},
+ {"verbose", OPT_VERBOSE, "FILE", OPTION_ARG_OPTIONAL, "Verbose logging to stdout"},
{0}};
// clang-format on
@@ -61,6 +63,12 @@ error_t parse_opt(int key, char *arg, struct argp_state *state) {
case OPT_APPEND:
cfg->append = true;
break;
+ case OPT_VERBOSE:
+ cfg->verbose++;
+ if (arg) {
+ cfg->debug = arg;
+ }
+ break;
case OPT_RANDOM:
cfg->random = true;
break;
@@ -86,7 +94,7 @@ error_t parse_opt(int key, char *arg, struct argp_state *state) {
if (strlen(arg) < 20) {
argp_failure(
state, 1, 0,
- "SEED must be at least 160 bits(20 characters).");
+ "SEED must be at least 160 bits (20 characters).");
}
cfg->seed = arg;
}
@@ -112,7 +120,7 @@ error_t parse_opt(int key, char *arg, struct argp_state *state) {
if (!cfg->prime_field && !cfg->binary_field) {
argp_failure(state, 1, 0,
"Specify field type, prime or binary, with --fp / "
- "--f2m(but not both).");
+ "--f2m (but not both).");
}
// Invalid is not prime or seed by definition.
if (cfg->invalid && (cfg->prime || cfg->from_seed)) {
diff --git a/src/io/cli.h b/src/io/cli.h
index 0826419..52b39ec 100644
--- a/src/io/cli.h
+++ b/src/io/cli.h
@@ -31,6 +31,8 @@ typedef struct config_t {
char *output;
char *input;
bool append;
+ long verbose;
+ char *debug;
long bits;
} config_t;
diff --git a/src/io/input.c b/src/io/input.c
index 184924f..263364d 100644
--- a/src/io/input.c
+++ b/src/io/input.c
@@ -111,7 +111,7 @@ void input_init(const char *input) {
}
}
-void input_quit() {
+void input_quit(void) {
if (in != NULL && in != stdout) {
fclose(in);
}
diff --git a/src/io/input.h b/src/io/input.h
index 9cdd008..1a3de5b 100644
--- a/src/io/input.h
+++ b/src/io/input.h
@@ -50,6 +50,6 @@ extern FILE *in;
void input_init(const char *input);
-void input_quit();
+void input_quit(void);
#endif // ECGEN_INPUT_H
diff --git a/src/io/output.c b/src/io/output.c
index 31e9f4c..27cdcf4 100644
--- a/src/io/output.c
+++ b/src/io/output.c
@@ -7,6 +7,7 @@
#include <parson/parson.h>
FILE *out;
+FILE *debug;
char *output_scsv(const char *format, char delim, GEN vector) {
long len = lg(vector) - 1;
@@ -66,7 +67,7 @@ void output_init(const char *output, bool append) {
}
}
-void output_quit() {
+void output_quit(void) {
if (out != NULL && out != stdout) {
fclose(out);
}
diff --git a/src/io/output.h b/src/io/output.h
index 35d2178..0a2f91d 100644
--- a/src/io/output.h
+++ b/src/io/output.h
@@ -41,9 +41,10 @@ char *output_sjson(GEN vector);
void output_json(FILE *out, GEN vector);
extern FILE *out;
+extern FILE *debug;
void output_init(const char *output, bool append);
-void output_quit();
+void output_quit(void);
#endif // ECGEN_OUTPUT_H