aboutsummaryrefslogtreecommitdiff
path: root/src/exhaustive
diff options
context:
space:
mode:
authorJ08nY2018-07-02 18:04:15 +0200
committerJ08nY2018-07-02 18:08:52 +0200
commit26d89788658df8a65eebc64eff021882efc1e819 (patch)
tree4116b1354f569a8955f6ce7c098ffaa874b89a4c /src/exhaustive
parentf2b30a0bdbc46c3c7651ea0efb657d99a7369447 (diff)
downloadecgen-26d89788658df8a65eebc64eff021882efc1e819.tar.gz
ecgen-26d89788658df8a65eebc64eff021882efc1e819.tar.zst
ecgen-26d89788658df8a65eebc64eff021882efc1e819.zip
Diffstat (limited to 'src/exhaustive')
-rw-r--r--src/exhaustive/exhaustive.c4
-rw-r--r--src/exhaustive/supersingular.c44
-rw-r--r--src/exhaustive/supersingular.h28
3 files changed, 76 insertions, 0 deletions
diff --git a/src/exhaustive/exhaustive.c b/src/exhaustive/exhaustive.c
index dbc1125..5ecac24 100644
--- a/src/exhaustive/exhaustive.c
+++ b/src/exhaustive/exhaustive.c
@@ -20,6 +20,7 @@
#include "io/output.h"
#include "misc/config.h"
#include "obj/curve.h"
+#include "supersingular.h"
#include "util/memory.h"
#include "util/timeout.h"
@@ -124,6 +125,9 @@ static void exhaustive_ginit(gen_f *generators) {
if (cfg->method == METHOD_ANOMALOUS) {
generators[OFFSET_A] = &gen_skip;
generators[OFFSET_B] = &anomalous_gen_equation;
+ } else if (cfg->method == METHOD_SUPERSINGULAR) {
+ generators[OFFSET_A] = &gen_skip;
+ generators[OFFSET_B] = &supersingular_gen_equation;
} else if (cfg->koblitz) {
switch (cfg->koblitz_value) {
case 0:
diff --git a/src/exhaustive/supersingular.c b/src/exhaustive/supersingular.c
new file mode 100644
index 0000000..87e6786
--- /dev/null
+++ b/src/exhaustive/supersingular.c
@@ -0,0 +1,44 @@
+/*
+ * ecgen, tool for generating Elliptic curve domain parameters
+ * Copyright (C) 2017-2018 J08nY
+ */
+#include "supersingular.h"
+
+GENERATOR(supersingular_gen_equation) {
+ if (equalis(curve->field, 2)) {
+ return -2;
+ }
+ if (mod4(curve->field) == 3) {
+ curve->a = mkintmod(subis(curve->field, 1), curve->field);
+ curve->b = mkintmod(stoi(0), curve->field);
+ return 1;
+ }
+ GEN q = stoi(3);
+ while (mod4(q) != 3 && kronecker(curve->field, q) != -1) {
+ q = nextprime(q);
+ }
+
+ if (equalis(q, 3)) {
+ curve->a = mkintmod(stoi(0), curve->field);
+ curve->b = mkintmod(stoi(1), curve->field);
+ return 1;
+ } else {
+ GEN H = polclass(negi(q), 0, 0);
+ GEN r = FpX_roots(H, curve->field);
+ GEN root = gel(r, 1);
+ curve->a =
+ Fp_div(Fp_mul(stoi(27), root, curve->field),
+ Fp_mul(stoi(4), Fp_sub(stoi(1728), root, curve->field),
+ curve->field),
+ curve->field);
+ curve->b = negi(curve->a);
+ return 1;
+ }
+}
+
+GENERATOR(supersingular_gen_order) {
+ // copy field to order
+ curve->order = addis(curve->field, 1);
+ obj_insert(curve->curve, 1, curve->order);
+ return 1;
+}
diff --git a/src/exhaustive/supersingular.h b/src/exhaustive/supersingular.h
new file mode 100644
index 0000000..bf7f267
--- /dev/null
+++ b/src/exhaustive/supersingular.h
@@ -0,0 +1,28 @@
+/*
+ * ecgen, tool for generating Elliptic curve domain parameters
+ * Copyright (C) 2017-2018 J08nY
+ */
+#ifndef ECGEN_EXHAUSTIVE_SUPERSINGULAR_H
+#define ECGEN_EXHAUSTIVE_SUPERSINGULAR_H
+
+#include "misc/types.h"
+
+/**
+ * @brief
+ * @param curve
+ * @param args
+ * @param state
+ * @return
+ */
+GENERATOR(supersingular_gen_equation);
+
+/**
+ * @brief
+ * @param curve
+ * @param args
+ * @param state
+ * @return
+ */
+GENERATOR(supersingular_gen_order);
+
+#endif // ECGEN_EXHAUSTIVE_SUPERSINGULAR_H