aboutsummaryrefslogtreecommitdiff
path: root/src/io
diff options
context:
space:
mode:
authorJ08nY2017-09-19 12:40:37 +0200
committerJ08nY2017-09-19 12:40:37 +0200
commit3fad579c3cbcbce457f36af6c1ceff37ec04ee54 (patch)
treeee86b1e858754afaadd5f7e55b87021485e78b64 /src/io
parent0a3aea134eea8aaa819548c4ad8c7c653830f5b4 (diff)
downloadecgen-3fad579c3cbcbce457f36af6c1ceff37ec04ee54.tar.gz
ecgen-3fad579c3cbcbce457f36af6c1ceff37ec04ee54.tar.zst
ecgen-3fad579c3cbcbce457f36af6c1ceff37ec04ee54.zip
Diffstat (limited to 'src/io')
-rw-r--r--src/io/cli.c14
-rw-r--r--src/io/config.h2
-rw-r--r--src/io/output.c11
3 files changed, 19 insertions, 8 deletions
diff --git a/src/io/cli.c b/src/io/cli.c
index 960c827..4c6dae2 100644
--- a/src/io/cli.c
+++ b/src/io/cli.c
@@ -19,7 +19,7 @@ enum opt_keys {
OPT_PRIME = 'p',
OPT_COFACTOR = 'k',
OPT_RANDOM = 'r',
- OPT_SEED = 's',
+ OPT_ANSI = 's',
OPT_INVALID = 'i',
OPT_ORDER = 'n',
OPT_KOBLITZ = 'K',
@@ -52,7 +52,7 @@ struct argp_option cli_options[] = {
{"unique", OPT_UNIQUE, 0, 0, "Generate a curve with only one generator.", 2},
{"anomalous", OPT_ANOMALOUS, 0, 0, "Generate an anomalous curve (of trace one, with field order equal to curve order).", 2},
{"points", OPT_POINTS, "TYPE", 0, "Generate points of given type (random/prime/all/nonprime/none).", 2},
- {"seed", OPT_SEED, "SEED", OPTION_ARG_OPTIONAL, "Generate a curve from SEED (ANSI X9.62 verifiable procedure). **NOT IMPLEMENTED**", 2},
+ {"ansi", OPT_ANSI, "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). **NOT IMPLEMENTED**", 2},
{"count", OPT_COUNT, "COUNT", 0, "Generate multiple curves.", 2},
@@ -198,8 +198,8 @@ error_t cli_parse(int key, char *arg, struct argp_state *state) {
}
break;
}
- case OPT_SEED:
- cfg->from_seed = true;
+ case OPT_ANSI:
+ cfg->ansi = true;
if (arg) {
if (!ansi_seed_valid(arg)) {
argp_failure(
@@ -236,13 +236,13 @@ error_t cli_parse(int key, char *arg, struct argp_state *state) {
}
// Invalid is not prime or seed by definition.
if (cfg->invalid &&
- (cfg->prime || cfg->from_seed || cfg->cofactor)) {
+ (cfg->prime || cfg->ansi || cfg->cofactor)) {
// not seed, not prime
argp_failure(state, 1, 0,
"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->ansi || cfg->invalid ||
cfg->cofactor || cfg->anomalous)) {
argp_failure(state, 1, 0,
"Fixed order curve generation can not generate "
@@ -251,7 +251,7 @@ error_t cli_parse(int key, char *arg, struct argp_state *state) {
"prime.");
}
if (cfg->anomalous &&
- (cfg->binary_field || cfg->cofactor || cfg->from_seed ||
+ (cfg->binary_field || cfg->cofactor || cfg->ansi ||
cfg->cm || cfg->invalid || cfg->koblitz)) {
argp_failure(
state, 1, 0,
diff --git a/src/io/config.h b/src/io/config.h
index 0894b5e..7b9a9dc 100644
--- a/src/io/config.h
+++ b/src/io/config.h
@@ -41,7 +41,7 @@ typedef struct {
long koblitz_value;
bool cofactor;
long cofactor_bound;
- bool from_seed;
+ bool ansi;
char *seed;
bool unique;
struct points_s points;
diff --git a/src/io/output.c b/src/io/output.c
index 4cabafd..4e951a2 100644
--- a/src/io/output.c
+++ b/src/io/output.c
@@ -5,6 +5,7 @@
#include "output.h"
#include <parson/parson.h>
+#include "util/bits.h"
#include "gen/field.h"
#include "util/memory.h"
@@ -154,6 +155,16 @@ static JSON_Value *output_jjson(curve_t *curve, const config_t *cfg) {
fprintf(err, "Error, field has unknown amount of elements.\n");
exit(1);
}
+ if (curve->seed) {
+ char *hex_str = bits_to_hex(curve->seed->seed);
+ char *hex = try_calloc(strlen(hex_str) + 3);
+ hex[0] = '0';
+ hex[1] = 'x';
+ strcat(hex, hex_str);
+ json_object_set_string(root_object, "seed", hex);
+ try_free(hex_str);
+ try_free(hex);
+ }
char *a = pari_sprintf("%P0#*x", cfg->hex_digits, field_elementi(curve->a));
json_object_set_string(root_object, "a", a);