aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/invalid/invalid.c24
-rw-r--r--src/io/cli.c38
-rw-r--r--src/misc/config.h9
3 files changed, 34 insertions, 37 deletions
diff --git a/src/invalid/invalid.c b/src/invalid/invalid.c
index 6a0f85a..9590564 100644
--- a/src/invalid/invalid.c
+++ b/src/invalid/invalid.c
@@ -3,6 +3,7 @@
* Copyright (C) 2017-2018 J08nY
*/
#include "invalid.h"
+#include <misc/config.h>
#include "exhaustive/arg.h"
#include "exhaustive/check.h"
#include "exhaustive/exhaustive.h"
@@ -69,14 +70,28 @@ static size_t invalid_primes(GEN order, pari_ulong **primes) {
GEN bound = sqri(order);
GEN product = gen_1;
pari_ulong last = 1;
+ pari_ulong upper = 0;
size_t nprimes = 0;
+ if (cfg->invalid_primes) {
+ char *end = NULL;
+ last = (pari_ulong)strtol(cfg->invalid_primes, &end, 10);
+ if (end && *end) {
+ end++;
+ upper = (pari_ulong)strtol(end, NULL, 10);
+ }
+ }
+
size_t size = 10;
*primes = try_calloc(size * sizeof(pari_ulong));
- while (cmpii(bound, product) >= 0) {
+ while (cmpii(bound, product) >= 0 && ((upper == 0) || last < upper)) {
product = mulis(product, last);
- (*primes)[nprimes] = unextprime(last + 1);
+ pari_ulong next = unextprime(last + 1);
+ if ((upper != 0) && next > upper) {
+ break;
+ }
+ (*primes)[nprimes] = next;
last = (*primes)[nprimes];
nprimes++;
if (nprimes == size) {
@@ -340,6 +355,11 @@ int invalid_do() {
size_t nprimes = invalid_primes(curve->order, &primes);
debug_log_end("Generated primes");
+ if (!nprimes) {
+ fprintf(err, "No orders to generate curves for, quitting.");
+ return EXIT_FAILURE;
+ }
+
curve_t **curves = try_calloc(nprimes * sizeof(curve_t *));
debug_log_start("Starting to generate invalid curves");
size_t ncurves;
diff --git a/src/io/cli.c b/src/io/cli.c
index 2cc6e0f..bc5764f 100644
--- a/src/io/cli.c
+++ b/src/io/cli.c
@@ -3,6 +3,7 @@
* Copyright (C) 2017-2018 J08nY
*/
#include "cli.h"
+#include <misc/config.h>
#include <string.h>
#include "exhaustive/ansi.h"
#include "exhaustive/brainpool.h"
@@ -53,7 +54,7 @@ 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},
- {"invalid", OPT_INVALID, 0, 0, "Generate a set of invalid curves, for a given curve (using Invalid curve algorithm).", 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},
{0, 0, 0, 0, "Generation options:", 3},
@@ -148,34 +149,6 @@ static void cli_end(struct argp_state *state) {
argp_failure(state, 1, 0,
"Brainpool algorithm only creates prime field curves.");
}
- /*
- // Invalid is not prime or seed by definition.
- if (cfg->invalid &&
- (cfg->prime || cfg->seed_algo || 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->seed_algo || cfg->invalid ||
- cfg->cofactor || cfg->anomalous)) {
- argp_failure(state, 1, 0,
- "Fixed order curve generation can not generate "
- "curves from seed, or invalid curves. Prime order "
- "also doesn't make sense if the given one isn't "
- "prime.");
- }
- if (cfg->anomalous &&
- (cfg->binary_field || cfg->cofactor || cfg->seed_algo ||
- cfg->cm || cfg->invalid || cfg->koblitz)) {
- argp_failure(
- state, 1, 0,
- "Anomalous curve generation can not generate "
- "binary field curves, curves with a cofactor, from seed "
- "with fixed order, invalid or Koblitz curves.");
- }
-
- */
// default values
if (!cfg->count) {
cfg->count = 1;
@@ -208,6 +181,13 @@ error_t cli_parse(int key, char *arg, struct argp_state *state) {
/* Generation method */
case OPT_INVALID:
cfg->method |= METHOD_INVALID;
+ if (arg) {
+ size_t span = strspn(arg, "0123456789-");
+ if (span != strlen(arg)) {
+ argp_failure(state, 1, 0, "Invalid range %s", arg);
+ }
+ cfg->invalid_primes = arg;
+ }
break;
case OPT_ORDER:
cfg->method |= METHOD_CM;
diff --git a/src/misc/config.h b/src/misc/config.h
index 1a732ba..7832e88 100644
--- a/src/misc/config.h
+++ b/src/misc/config.h
@@ -85,6 +85,9 @@ typedef struct {
/** @brief Whether the curves should have a bound on the cofactor value. */
bool cofactor;
long cofactor_value;
+ /** @brief A range of prime orders that should be generated in invalid
+ * generation. */
+ char *invalid_primes;
/** @brief What seed algorithm, if any, to use to generate the curves. */
seed_e seed_algo;
/** @brief What seed to use, if any, to generate the curves. */
@@ -92,12 +95,6 @@ typedef struct {
/** @brief Whether the curves should be uniquely generated (one generator).
*/
bool unique;
- /** @brief The GP gen functions. */
- char *gp_gens[10];
- size_t gp_gens_size;
- /** @brief The GP check functions. */
- char *gp_checks[10];
- size_t gp_checks_size;
/** @brief */
char *hex_check;
/** @brief What points to generate on the curves. */