diff options
| author | J08nY | 2017-03-25 18:27:33 +0100 |
|---|---|---|
| committer | J08nY | 2017-03-25 18:27:33 +0100 |
| commit | 63da66f5a5ae9532430215ec854f7f7d238b96ec (patch) | |
| tree | 37af2141f5ae56e2531aa7a41745b61254e7dcd0 /src/math | |
| parent | bf0c62c191bf1a557623963bf7b2d31a093d7bc9 (diff) | |
| download | ecgen-63da66f5a5ae9532430215ec854f7f7d238b96ec.tar.gz ecgen-63da66f5a5ae9532430215ec854f7f7d238b96ec.tar.zst ecgen-63da66f5a5ae9532430215ec854f7f7d238b96ec.zip | |
Fixed generation with cofactor.
Diffstat (limited to 'src/math')
| -rw-r--r-- | src/math/order.c | 20 |
1 files changed, 14 insertions, 6 deletions
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; } } |
