diff options
| author | J08nY | 2018-01-18 18:37:44 +0100 |
|---|---|---|
| committer | J08nY | 2018-01-18 18:40:06 +0100 |
| commit | cf074191532caef918fb9f502b37697094da317a (patch) | |
| tree | 9826a5f436aba9fcbfbba8dfd5e615267213123f /src | |
| parent | f940f80a2cb69ffcd1f0d608cbb1b0f06e0854d6 (diff) | |
| download | ecgen-cf074191532caef918fb9f502b37697094da317a.tar.gz ecgen-cf074191532caef918fb9f502b37697094da317a.tar.zst ecgen-cf074191532caef918fb9f502b37697094da317a.zip | |
Diffstat (limited to 'src')
| -rw-r--r-- | src/ecgen.c | 1 | ||||
| -rw-r--r-- | src/exhaustive/exhaustive.c | 7 | ||||
| -rw-r--r-- | src/gen/curve.c | 11 | ||||
| -rw-r--r-- | src/gen/curve.h | 11 | ||||
| -rw-r--r-- | src/io/cli.c | 8 | ||||
| -rw-r--r-- | src/math/twists.c | 12 | ||||
| -rw-r--r-- | src/math/twists.h | 8 | ||||
| -rw-r--r-- | src/misc/config.h | 3 |
8 files changed, 55 insertions, 6 deletions
diff --git a/src/ecgen.c b/src/ecgen.c index 3e5b145..4a7f94a 100644 --- a/src/ecgen.c +++ b/src/ecgen.c @@ -29,7 +29,6 @@ #include "invalid/invalid.h" #include "io/input.h" #include "io/output.h" -#include "misc/config.h" #include "util/timeout.h" const char *argp_program_version = diff --git a/src/exhaustive/exhaustive.c b/src/exhaustive/exhaustive.c index c6b54e9..fa748f5 100644 --- a/src/exhaustive/exhaustive.c +++ b/src/exhaustive/exhaustive.c @@ -3,6 +3,7 @@ * Copyright (C) 2017-2018 J08nY */ #include "exhaustive.h" +#include <misc/config.h> #include "anomalous.h" #include "ansi.h" #include "brainpool.h" @@ -166,7 +167,11 @@ static void exhaustive_ginit(gen_f *generators) { } } // setup common generators - generators[OFFSET_CURVE] = &curve_gen_any; + if (cfg->method == METHOD_TWIST) { + generators[OFFSET_CURVE] = &curve_gen_any_twist; + } else { + generators[OFFSET_CURVE] = &curve_gen_any; + } switch (cfg->points.type) { case POINTS_RANDOM: diff --git a/src/gen/curve.c b/src/gen/curve.c index 4996c28..f89044a 100644 --- a/src/gen/curve.c +++ b/src/gen/curve.c @@ -3,6 +3,7 @@ * Copyright (C) 2017-2018 J08nY */ #include "curve.h" +#include "math/twists.h" #include "point.h" #include "seed.h" #include "util/memory.h" @@ -116,6 +117,16 @@ GENERATOR(curve_gen_any) { } } +GENERATOR(curve_gen_any_twist) { + int result = curve_gen_any(curve, args, state); + if (result != 1) { + return result; + } else { + twist_rand(curve); + return 1; + } +} + CHECK(curve_check_nonzero) { if (gequal0(ell_get_disc(curve->curve))) { return -3; diff --git a/src/gen/curve.h b/src/gen/curve.h index 8b82fa9..e2316c6 100644 --- a/src/gen/curve.h +++ b/src/gen/curve.h @@ -18,11 +18,22 @@ * * @param curve A curve_t being generated * @param args unused + * @param state * @return state diff */ GENERATOR(curve_gen_any); /** + * GENERATOR(gen_f) + * + * @param curve + * @param args + * @param state + * @return state diff + */ +GENERATOR(curve_gen_any_twist); + +/** * CHECK(check_f) * Checks that the curve has non-zero discriminant. * diff --git a/src/io/cli.c b/src/io/cli.c index efedb8b..46ef47a 100644 --- a/src/io/cli.c +++ b/src/io/cli.c @@ -41,7 +41,8 @@ enum opt_keys { OPT_GPGEN, OPT_GPCHECK, OPT_HEXCHECK, - OPT_BRAINPOOL_RFC + OPT_BRAINPOOL_RFC, + OPT_TWIST, }; // clang-format off @@ -57,6 +58,7 @@ struct argp_option cli_options[] = { {"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}, {"invalid", OPT_INVALID, 0, 0, "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}, {0, 0, 0, 0, "Generation options:", 3}, {"random", OPT_RANDOM, 0, 0, "Generate a random curve (using Random approach).", 3}, @@ -139,6 +141,7 @@ static void cli_end(struct argp_state *state) { case METHOD_ANOMALOUS: case METHOD_SEED: case METHOD_INVALID: + case METHOD_TWIST: break; default: printf("%u\n", cfg->method); @@ -257,6 +260,9 @@ error_t cli_parse(int key, char *arg, struct argp_state *state) { cfg->seed = arg; } break; + case OPT_TWIST: + cfg->method |= METHOD_TWIST; + break; /* Generation options */ case OPT_COUNT: diff --git a/src/math/twists.c b/src/math/twists.c index 78481f4..3f1296d 100644 --- a/src/math/twists.c +++ b/src/math/twists.c @@ -3,8 +3,10 @@ * Copyright (C) 2017-2018 J08nY */ #include "twists.h" +#include "gen/point.h" +#include "gen/seed.h" -void curve_twist_rand(curve_t *to, const curve_t *of) { +void twist_rand_to(curve_t *to, const curve_t *of) { to->field = gcopy(of->field); GEN v = elltwist(of->curve, NULL); to->curve = ellinit(v, to->field, -1); @@ -15,4 +17,12 @@ void curve_twist_rand(curve_t *to, const curve_t *of) { to->a = ell_get_a2(to->curve); to->b = ell_get_a6(to->curve); } +} + +void twist_rand(curve_t *what) { + twist_rand_to(what, what); + seed_free(&what->seed); + what->order = NULL; + points_free_deep(&what->points, what->npoints); + points_free_deep(&what->generators, what->ngens); }
\ No newline at end of file diff --git a/src/math/twists.h b/src/math/twists.h index 3249047..dcbdb31 100644 --- a/src/math/twists.h +++ b/src/math/twists.h @@ -12,6 +12,12 @@ * @param to The result of the twist. * @param of The curve to be twisted. */ -void curve_twist_rand(curve_t *to, const curve_t *of); +void twist_rand_to(curve_t *to, const curve_t *of); + +/** + * @brief + * @param what + */ +void twist_rand(curve_t *what); #endif // ECGEN_TWIST_H diff --git a/src/misc/config.h b/src/misc/config.h index de1c95e..367de52 100644 --- a/src/misc/config.h +++ b/src/misc/config.h @@ -33,7 +33,8 @@ typedef enum { METHOD_CM = 1 << 0, METHOD_ANOMALOUS = 1 << 1, METHOD_SEED = 1 << 2, - METHOD_INVALID = 1 << 3 + METHOD_INVALID = 1 << 3, + METHOD_TWIST } method_e; /** |
