aboutsummaryrefslogtreecommitdiff
path: root/src/gen/order.c
diff options
context:
space:
mode:
authorJ08nY2018-03-03 01:02:08 +0100
committerJ08nY2018-03-03 01:02:08 +0100
commitac60f78a253efde94cab36264b0555b0691fdd8a (patch)
tree12ce2bfdee1f13f0b6e56a017c3c29979475fe02 /src/gen/order.c
parent40cbb213ac910ddcaf22a26a247d2a9eeddca1fc (diff)
downloadecgen-ac60f78a253efde94cab36264b0555b0691fdd8a.tar.gz
ecgen-ac60f78a253efde94cab36264b0555b0691fdd8a.tar.zst
ecgen-ac60f78a253efde94cab36264b0555b0691fdd8a.zip
Diffstat (limited to 'src/gen/order.c')
-rw-r--r--src/gen/order.c38
1 files changed, 11 insertions, 27 deletions
diff --git a/src/gen/order.c b/src/gen/order.c
index 16d597a..0c0779c 100644
--- a/src/gen/order.c
+++ b/src/gen/order.c
@@ -44,39 +44,23 @@ GENERATOR(order_gen_sea) {
}
}
-GENERATOR(order_gen_smallfact) {
+GENERATOR(order_gen_cofactor) {
HAS_ARG(args);
- pari_ulong smallfact = *(pari_ulong *)args->args;
+ pari_ulong cofactor = *(pari_ulong *)args->args;
pari_sp ltop = avma;
- GEN fact = mpfact(smallfact);
- pari_ulong lfact = 0;
- if (lgefint(fact) > 3) {
- lfact = 0;
- } else {
- lfact = itou(fact);
- }
-
- GEN order = ellsea(curve->curve, lfact);
- if (gequal0(order)) {
+ GEN order = ellff_get_card(curve->curve);
+ GEN res = cgeti(DEFAULTPREC);
+ if (!dvdiiz(order, utoi(cofactor), res)) {
avma = ltop;
- return -4;
+ return -4;
}
-
- 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;
- }
+ if (!isprime(res)) {
+ avma = ltop;
+ return -4;
}
+ verbose_log("cofactor");
- curve->order = gerepileupto(ltop, order);
+ curve->order = gerepilecopy(ltop, order);
obj_insert_shallow(curve->curve, 1, curve->order);
return 1;
}