diff options
| author | J08nY | 2024-12-01 13:56:04 +0100 |
|---|---|---|
| committer | J08nY | 2024-12-01 13:56:04 +0100 |
| commit | 23c460dff96f57a4fa480ab6426700b0be384f12 (patch) | |
| tree | 81a61274f2279556eb09547190e2baa41d0b89f1 /src/io/cli.c | |
| parent | 2e3b816158447a963af903afe5259f3d82097aa3 (diff) | |
| download | ecgen-23c460dff96f57a4fa480ab6426700b0be384f12.tar.gz ecgen-23c460dff96f57a4fa480ab6426700b0be384f12.tar.zst ecgen-23c460dff96f57a4fa480ab6426700b0be384f12.zip | |
Diffstat (limited to 'src/io/cli.c')
| -rw-r--r-- | src/io/cli.c | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/src/io/cli.c b/src/io/cli.c index 5f29047..0da0770 100644 --- a/src/io/cli.c +++ b/src/io/cli.c @@ -31,6 +31,7 @@ enum opt_keys { OPT_APPEND = 'a', OPT_VERBOSE = 'v', OPT_MEMORY = 'm', + OPT_FAMILY = 'F', OPT_FP = 1, OPT_F2M, OPT_POINTS, @@ -59,9 +60,10 @@ struct argp_option cli_options[] = { {"ansi", OPT_ANSI, "SEED", OPTION_ARG_OPTIONAL, "Generate a curve from SEED (ANSI X9.62 verifiable procedure).", 2}, {"brainpool", OPT_BRAINPOOL, "SEED", OPTION_ARG_OPTIONAL, "Generate a curve from SEED (Brainpool procedure).", 2}, {"brainpool-rfc", OPT_BRAINPOOL_RFC, "SEED", OPTION_ARG_OPTIONAL, "Generate a curve from SEED (Brainpool procedure, as per RFC 5639).", 2}, - {"nums", OPT_NUMS, 0, 0, "Generate a curve using the NUMS procedure.", 2}, + {"nums", OPT_NUMS, 0, 0, "Generate a curve using the NUMS procedure.", 2}, {"invalid", OPT_INVALID, "RANGE", OPTION_ARG_OPTIONAL, "Generate a set of invalid curves, for a given curve (using Invalid curve algorithm).", 2}, - {"twist", OPT_TWIST, 0, 0, "Generate a twist of a given curve.", 2}, + {"twist", OPT_TWIST, 0, 0, "Generate a twist of a given curve.", 2}, + {"family", OPT_FAMILY, "NAME", 0, "Generate a curve from a curve family (e.g. BN, BLS12, BLS24, KSS)."}, {0, 0, 0, 0, "Generation options:", 3}, {"random", OPT_RANDOM, "WHAT", OPTION_ARG_OPTIONAL, "Generate a random curve (using Random approach). " @@ -171,6 +173,7 @@ static void cli_end(struct argp_state *state) { case METHOD_INVALID: case METHOD_TWIST: case METHOD_SUPERSINGULAR: + case METHOD_FAMILY: break; default: argp_failure(state, 1, 0, @@ -200,6 +203,10 @@ static void cli_end(struct argp_state *state) { "Can only generate anomalous curves over prime fields " "currently."); } + if (cfg->method == METHOD_FAMILY && cfg->field == FIELD_BINARY) { + argp_failure(state, 1, 0, + "Can only generate family curves over prime fields."); + } if (cfg->method == METHOD_SUPERSINGULAR && cfg->field == FIELD_BINARY) { argp_failure(state, 1, 0, "Can only generate supersingular curves over prime fields " @@ -213,7 +220,8 @@ static void cli_end(struct argp_state *state) { } if (cfg->method == METHOD_ANOMALOUS && !cfg->random) { argp_failure(state, 1, 0, - "Anomalous curves can only be generated randomly (specify the -r option)."); + "Anomalous curves can only be generated randomly (specify " + "the -r option)."); } // default values if (!cfg->count) { @@ -276,6 +284,31 @@ error_t cli_parse(int key, char *arg, struct argp_state *state) { cfg->method |= METHOD_SUPERSINGULAR; SET(method); break; + case OPT_FAMILY: + cfg->method |= METHOD_FAMILY; + SET(method); + if (strcasecmp(arg, "BN") == 0) { + cfg->family = FAMILY_BN; + } else if (strcasecmp(arg, "BLS12") == 0) { + cfg->family = FAMILY_BLS12; + } else if (strcasecmp(arg, "BLS24") == 0) { + cfg->family = FAMILY_BLS24; + } else if (strcasecmp(arg, "KSS16") == 0) { + argp_failure(state, 1, 0, "Family not yet supported."); + cfg->family = FAMILY_KSS16; + } else if (strcasecmp(arg, "KSS18") == 0) { + argp_failure(state, 1, 0, "Family not yet supported."); + cfg->family = FAMILY_KSS18; + } else if (strcasecmp(arg, "KSS36") == 0) { + argp_failure(state, 1, 0, "Family not yet supported."); + cfg->family = FAMILY_KSS36; + } else if (strcasecmp(arg, "KSS40") == 0) { + argp_failure(state, 1, 0, "Family not yet supported."); + cfg->family = FAMILY_KSS40; + } else { + argp_failure(state, 1, 0, "Unknown curve family = %s", arg); + } + break; case OPT_ANSI: cfg->method |= METHOD_SEED; SET(method); |
