aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/invalid/invalid.c10
-rw-r--r--src/math/order.c17
-rw-r--r--src/math/order.h11
3 files changed, 35 insertions, 3 deletions
diff --git a/src/invalid/invalid.c b/src/invalid/invalid.c
index 765a566..1d3f153 100644
--- a/src/invalid/invalid.c
+++ b/src/invalid/invalid.c
@@ -2,6 +2,7 @@
* ecgen, tool for generating Elliptic curve domain parameters
* Copyright (C) 2017 J08nY
*/
+#include <io/config.h>
#include "invalid.h"
#include "exhaustive/exhaustive.h"
#include "invalid_thread.h"
@@ -34,7 +35,14 @@ static void invalid_invalid_ginit(gen_t *generators, const config_t *cfg) {
generators[OFFSET_A] = &gen_skip;
generators[OFFSET_B] = &b_random;
generators[OFFSET_CURVE] = &curve_nonzero;
- generators[OFFSET_ORDER] = &order_any;
+ switch(cfg->field) {
+ case FIELD_PRIME:
+ generators[OFFSET_ORDER] = &order_sea;
+ break;
+ case FIELD_BINARY:
+ generators[OFFSET_ORDER] = &order_any;
+ break;
+ }
if (cfg->unique) {
generators[OFFSET_GENERATORS] = &gens_one;
} else {
diff --git a/src/math/order.c b/src/math/order.c
index 7f90849..3235a30 100644
--- a/src/math/order.c
+++ b/src/math/order.c
@@ -14,6 +14,19 @@ int order_any(curve_t *curve, const config_t *cfg, arg_t *args) {
return 1;
}
+int order_sea(curve_t *curve, const config_t *cfg, arg_t *args) {
+ pari_sp ltop = avma;
+ GEN order = ellsea(curve->curve, 0);
+ if (gequal0(order)) {
+ avma = ltop;
+ return -4;
+ } else {
+ curve->order = order;
+ obj_insert_shallow(curve->curve, 1, order);
+ return 1;
+ }
+}
+
int order_smallfact(curve_t *curve, const config_t *cfg, arg_t *args) {
if (!args) {
fprintf(stderr, "No args to an arged function. order_smallfact");
@@ -34,7 +47,7 @@ int order_smallfact(curve_t *curve, const config_t *cfg, arg_t *args) {
return -4;
} else {
curve->order = order;
- obj_insert(curve->curve, 1, curve->order);
+ obj_insert_shallow(curve->curve, 1, curve->order);
return 1;
}
}
@@ -47,7 +60,7 @@ int order_prime(curve_t *curve, const config_t *cfg, arg_t *args) {
return -4;
} else {
curve->order = order;
- obj_insert(curve->curve, 1, curve->order);
+ obj_insert_shallow(curve->curve, 1, curve->order);
return 1;
}
}
diff --git a/src/math/order.h b/src/math/order.h
index b883fe6..0ae5cf8 100644
--- a/src/math/order.h
+++ b/src/math/order.h
@@ -24,6 +24,17 @@ int order_any(curve_t *curve, const config_t *cfg, arg_t *args);
/**
* GENERATOR(gen_t)
+ * Calculates the curve order, using the SEA algorithm.
+ *
+ * @param curve
+ * @param cfg
+ * @param args
+ * @return
+ */
+int order_sea(curve_t *curve, const config_t *cfg, arg_t *args);
+
+/**
+ * GENERATOR(gen_t)
*
* @param curve
* @param cfg