From 6187e06d92adfe093d47791b9028ebf45c8afa75 Mon Sep 17 00:00:00 2001 From: J08nY Date: Sat, 30 Sep 2017 17:42:37 +0200 Subject: Fixed generation with cofactor bound. Might be slow, but should work. Needs to factor curve order. I wonder if I should store the factored curve order somewhere. --- src/gen/order.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) (limited to 'src/gen/order.c') diff --git a/src/gen/order.c b/src/gen/order.c index 2e20294..1ad7a93 100644 --- a/src/gen/order.c +++ b/src/gen/order.c @@ -48,21 +48,36 @@ GENERATOR(order_gen_smallfact) { pari_ulong smallfact = *(pari_ulong *)args->args; pari_sp ltop = avma; GEN fact = mpfact(smallfact); + pari_ulong lfact = 0; if (lgefint(fact) > 3) { - smallfact = 0; + lfact = 0; } else { - smallfact = itou(fact); + lfact = itou(fact); } - GEN order = ellsea(curve->curve, smallfact); - if (gequal0(order) || gequal1(gcdii(order, fact))) { + GEN order = ellsea(curve->curve, lfact); + if (gequal0(order)) { avma = ltop; return -4; - } else { - curve->order = order; - obj_insert_shallow(curve->curve, 1, curve->order); - return 1; } + + GEN factors = factor(order); + GEN primes = gel(factors, 1); + GEN powers = gel(factors, 2); + long len = glength(primes); + GEN total = gen_1; + for (long i = 1; i < len; ++i) { + GEN pow = powii(gel(primes, i), gel(powers, i)); + total = mulii(total, pow); + if (abscmpiu(total, smallfact) > 0) { + avma = ltop; + return -4; + } + } + + curve->order = gerepileupto(ltop, order); + obj_insert_shallow(curve->curve, 1, curve->order); + return 1; } GENERATOR(order_gen_prime) { -- cgit v1.2.3-70-g09d2