diff options
| author | J08nY | 2017-07-20 01:06:50 +0200 |
|---|---|---|
| committer | J08nY | 2017-07-20 01:06:50 +0200 |
| commit | 84c8a246ffb870bce8bafc5ba03116b82c5ebfb7 (patch) | |
| tree | 4bd5e1a5b966b9b3abeb4ece59085219aa51ea5f | |
| parent | 75c07ec3d7c24b37b6afa0e832a5e1b52927d83b (diff) | |
| download | ecgen-84c8a246ffb870bce8bafc5ba03116b82c5ebfb7.tar.gz ecgen-84c8a246ffb870bce8bafc5ba03116b82c5ebfb7.tar.zst ecgen-84c8a246ffb870bce8bafc5ba03116b82c5ebfb7.zip | |
Add proper support for Koblitz curves generation.
| -rw-r--r-- | src/exhaustive/exhaustive.c | 12 | ||||
| -rw-r--r-- | src/gen/equation.c | 2 | ||||
| -rw-r--r-- | src/gen/equation.h | 2 | ||||
| -rw-r--r-- | src/io/cli.c | 11 | ||||
| -rw-r--r-- | src/io/config.h | 1 | ||||
| -rw-r--r-- | src/math/subgroups.c | 20 | ||||
| -rwxr-xr-x | test/ecgen.sh | 4 |
7 files changed, 37 insertions, 15 deletions
diff --git a/src/exhaustive/exhaustive.c b/src/exhaustive/exhaustive.c index 768d0c4..3f10b53 100644 --- a/src/exhaustive/exhaustive.c +++ b/src/exhaustive/exhaustive.c @@ -2,6 +2,7 @@ * ecgen, tool for generating Elliptic curve domain parameters * Copyright (C) 2017 J08nY */ +#include <io/config.h> #include "exhaustive.h" #include "anomalous.h" #include "gen/curve.h" @@ -45,7 +46,16 @@ static void exhaustive_ginit(gen_t *generators, const config_t *cfg) { } if (cfg->koblitz) { - generators[OFFSET_A] = &a_gen_zero; + switch (cfg->koblitz_value) { + case 0: + generators[OFFSET_A] = &a_gen_zero; + break; + case 1: + generators[OFFSET_A] = &a_gen_one; + break; + default:break; + } + generators[OFFSET_B] = &b_gen_one; } generators[OFFSET_CURVE] = &curve_gen_nonzero; diff --git a/src/gen/equation.c b/src/gen/equation.c index 7c90ab7..9524df7 100644 --- a/src/gen/equation.c +++ b/src/gen/equation.c @@ -106,7 +106,7 @@ GENERATOR(b_gen_zero) { return 1; } -GENERATOR(g_gen_one) { +GENERATOR(b_gen_one) { curve->b = gen_1; return 1; } diff --git a/src/gen/equation.h b/src/gen/equation.h index 741517c..58e2e6e 100644 --- a/src/gen/equation.h +++ b/src/gen/equation.h @@ -131,7 +131,7 @@ GENERATOR(b_gen_zero); * @param args unused * @return state diff */ -GENERATOR(g_gen_one); +GENERATOR(b_gen_one); /** * GENERATOR(gen_t) diff --git a/src/io/cli.c b/src/io/cli.c index db76b5b..54dfb55 100644 --- a/src/io/cli.c +++ b/src/io/cli.c @@ -47,7 +47,7 @@ struct argp_option cli_options[] = { {"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}, - {"koblitz", OPT_KOBLITZ, 0, 0, "Generate a Koblitz curve (a = 0).", 2}, + {"koblitz", OPT_KOBLITZ, "A", OPTION_ARG_OPTIONAL,"Generate a Koblitz curve (a in {0, 1}, b = 1).", 2}, {"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}, @@ -57,7 +57,7 @@ struct argp_option cli_options[] = { {"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}, + {"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}, @@ -164,6 +164,13 @@ error_t cli_parse(int key, char *arg, struct argp_state *state) { break; case OPT_KOBLITZ: cfg->koblitz = true; + if (arg) { + cfg->koblitz_value = strtol(arg, NULL, 10); + if (cfg->koblitz_value != 0 && cfg->koblitz_value != 1) { + argp_failure(state, 1, 0, "Wrong value for a = %li", + cfg->koblitz_value); + } + } break; case OPT_UNIQUE: cfg->unique = true; diff --git a/src/io/config.h b/src/io/config.h index 271a60e..0894b5e 100644 --- a/src/io/config.h +++ b/src/io/config.h @@ -38,6 +38,7 @@ typedef struct { char *order; bool anomalous; bool koblitz; + long koblitz_value; bool cofactor; long cofactor_bound; bool from_seed; diff --git a/src/math/subgroups.c b/src/math/subgroups.c index 4df4de0..903401e 100644 --- a/src/math/subgroups.c +++ b/src/math/subgroups.c @@ -2,8 +2,8 @@ * ecgen, tool for generating Elliptic curve domain parameters * Copyright (C) 2017 J08nY */ -#include "gen/types.h" #include "subgroups.h" +#include "gen/types.h" /** * @brief All prime divisors of a given integer. @@ -44,17 +44,17 @@ static GEN __attribute__((unused)) subgroups_divisors(GEN order) { /* static GEN subgroups_exponents(GEN order) { - GEN factors = Z_factor(order); - GEN primes = gel(factors, 1); - GEN multiples = gel(factors, 2); + GEN factors = Z_factor(order); + GEN primes = gel(factors, 1); + GEN multiples = gel(factors, 2); - long len = glength(primes); - pari_ulong count = 1; - for (long i = 1; i <= len; ++i) { - count *= itou(gel(multiples,i)) + 1; - } + long len = glength(primes); + pari_ulong count = 1; + for (long i = 1; i <= len; ++i) { + count *= itou(gel(multiples,i)) + 1; + } - GEN result = gtovec0(gen_0, count); + GEN result = gtovec0(gen_0, count); } */ diff --git a/test/ecgen.sh b/test/ecgen.sh index 4b4ce73..2f69c60 100755 --- a/test/ecgen.sh +++ b/test/ecgen.sh @@ -52,6 +52,10 @@ function exhaustive() { assert_raises "${ecgen} --fp -r -i -u 10" assert_raises "${ecgen} --f2m -r -i -u 10" assert_raises "${ecgen} --fp -r -k 10 10" + assert_raises "${ecgen} --fp -r -K 10" + assert_raises "${ecgen} --f2m -r -K 10" + assert_raises "${ecgen} --fp -r -K1 10" + assert_raises "${ecgen} --f2m -r -K1 10" assert_raises "${ecgen} --fp -r --points=random 10" assert_raises "${ecgen} --fp -r --points=10random 10" |
