diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/exhaustive/exhaustive.c | 3 | ||||
| -rw-r--r-- | src/io/cli.c | 1 | ||||
| -rw-r--r-- | src/math/order.c | 20 |
3 files changed, 16 insertions, 8 deletions
diff --git a/src/exhaustive/exhaustive.c b/src/exhaustive/exhaustive.c index ecc9a01..60b00a9 100644 --- a/src/exhaustive/exhaustive.c +++ b/src/exhaustive/exhaustive.c @@ -111,12 +111,11 @@ int exhaustive_gen(curve_t *curve, config_t *cfg, gen_t generators[], tops[state - start_offset] = avma; int diff = generators[state](curve, cfg, argss ? argss[state] : NULL); - state += diff; - if (diff == INT_MIN) { fprintf(stderr, "Error generating a curve. %i\n", state); return 0; } + state += diff; if (diff <= 0) { avma = tops[state - start_offset]; diff --git a/src/io/cli.c b/src/io/cli.c index efebfbc..2ee6aee 100644 --- a/src/io/cli.c +++ b/src/io/cli.c @@ -114,6 +114,7 @@ error_t cli_parse(int key, char *arg, struct argp_state *state) { if (arg) { cfg->cofactor_bound = strtol(arg, NULL, 10); } + break; case OPT_INVALID: cfg->invalid = true; break; diff --git a/src/math/order.c b/src/math/order.c index 8902524..89343e6 100644 --- a/src/math/order.c +++ b/src/math/order.c @@ -16,24 +16,32 @@ int order_smallfact(curve_t *curve, config_t *cfg, arg_t *args) { } pari_ulong smallfact = *(pari_ulong *)args->args; pari_sp ltop = avma; - curve->order = ellsea(curve->curve, smallfact); - obj_insert_shallow(curve->curve, 1, curve->order); - if (gequal0(curve->order)) { + GEN fact = mpfact(smallfact); + if (lgefint(fact) > 3) { + fprintf(stderr, "Cofactor too large."); + return INT_MIN; + } + + GEN order = ellsea(curve->curve, itou(fact)); + if (gequal0(order) || gequal1(gcdii(order, fact))) { avma = ltop; return -4; } else { + curve->order = order; + obj_insert_shallow(curve->curve, 1, curve->order); return 1; } } int order_prime(curve_t *curve, config_t *cfg, arg_t *args) { pari_sp ltop = avma; - curve->order = ellsea(curve->curve, 1); - obj_insert_shallow(curve->curve, 1, curve->order); - if (gequal0(curve->order) || !(isprime(curve->order))) { + GEN order = ellsea(curve->curve, 1); + if (gequal0(order) || !(isprime(order))) { avma = ltop; return -4; } else { + curve->order = order; + obj_insert_shallow(curve->curve, 1, curve->order); return 1; } } |
