aboutsummaryrefslogtreecommitdiff
path: root/src/cm
diff options
context:
space:
mode:
authorJ08nY2024-12-01 13:56:04 +0100
committerJ08nY2024-12-01 13:56:04 +0100
commit23c460dff96f57a4fa480ab6426700b0be384f12 (patch)
tree81a61274f2279556eb09547190e2baa41d0b89f1 /src/cm
parent2e3b816158447a963af903afe5259f3d82097aa3 (diff)
downloadecgen-23c460dff96f57a4fa480ab6426700b0be384f12.tar.gz
ecgen-23c460dff96f57a4fa480ab6426700b0be384f12.tar.zst
ecgen-23c460dff96f57a4fa480ab6426700b0be384f12.zip
Add curve family generation.
Diffstat (limited to 'src/cm')
-rw-r--r--src/cm/cm_any.c38
-rw-r--r--src/cm/cm_any.h6
2 files changed, 44 insertions, 0 deletions
diff --git a/src/cm/cm_any.c b/src/cm/cm_any.c
index e1dab54..f948ac1 100644
--- a/src/cm/cm_any.c
+++ b/src/cm/cm_any.c
@@ -143,6 +143,7 @@ GEN cm_construct_curve(GEN order, GEN d, GEN p, bool ord_prime) {
GEN r = FpX_roots(H, p);
debug_log("roots = %Ps", r);
if (gequal(r, gtovec(gen_0))) {
+ avma = ltop;
return NULL;
}
@@ -206,6 +207,43 @@ GEN cm_construct_curve(GEN order, GEN d, GEN p, bool ord_prime) {
}
}
}
+ avma = ltop;
+ return NULL;
+}
+
+GEN cm_construct_curve_subgroup(GEN r, GEN d, GEN p) {
+ debug_log("Constructing a curve with r = %Pi, d = %Pi, p = %Pi", r, d,
+ p);
+ pari_sp ltop = avma;
+ GEN H = polclass(d, 0, 0);
+ debug_log("H = %Ps", H);
+
+ GEN roots = FpX_roots(H, p);
+ debug_log("roots = %Ps", roots);
+ if (gequal(roots, gtovec(gen_0))) {
+ avma = ltop;
+ return NULL;
+ }
+
+ long rlen = glength(roots);
+ pari_sp btop = avma;
+ for (long i = 1; i <= rlen; ++i) {
+ GEN root = gel(roots, i);
+ debug_log("trying root = %Pi", root);
+
+ GEN e = ellinit(ellfromj(mkintmod(root, p)), p, 0);
+ pari_CATCH(e_TYPE) { avma = btop; continue; }
+ pari_TRY { checkell(e); };
+ pari_ENDCATCH{};
+
+ GEN ord = ellff_get_card(e);
+ if (dvdii(ord, r)) {
+ debug_log("Got curve.");
+ return gerepilecopy(ltop, e);
+ }
+ avma = btop;
+ }
+ avma = ltop;
return NULL;
}
diff --git a/src/cm/cm_any.h b/src/cm/cm_any.h
index 42fc68e..a49fd7f 100644
--- a/src/cm/cm_any.h
+++ b/src/cm/cm_any.h
@@ -24,6 +24,12 @@ typedef struct {
GEN cm_construct_curve(GEN order, GEN d, GEN p, bool ord_prime);
/**
+ * @brief Construct an elliptic curve given a factor of its order, CM
+ * discriminant and field order.
+ */
+GEN cm_construct_curve_subgroup(GEN r, GEN d, GEN p);
+
+/**
* @brief
* @param curve
* @param args