aboutsummaryrefslogtreecommitdiff
path: root/src/math
diff options
context:
space:
mode:
authorJ08nY2017-02-10 01:24:48 +0100
committerJ08nY2017-02-10 01:24:48 +0100
commitde90c5cd76bcd45c82f34d1f3d60b529b7d5a86d (patch)
tree6d5b6923cf7443e14004e779258b4c546cf769b5 /src/math
parent79b29481b1c4d13063dd8b6ee6a1d0d70a54faab (diff)
downloadecgen-de90c5cd76bcd45c82f34d1f3d60b529b7d5a86d.tar.gz
ecgen-de90c5cd76bcd45c82f34d1f3d60b529b7d5a86d.tar.zst
ecgen-de90c5cd76bcd45c82f34d1f3d60b529b7d5a86d.zip
Properly split into submodules
Diffstat (limited to 'src/math')
-rw-r--r--src/math/curve.c19
-rw-r--r--src/math/equation.c2
-rw-r--r--src/math/field.c2
-rw-r--r--src/math/order.c21
-rw-r--r--src/math/order.h28
-rw-r--r--src/math/types.c7
-rw-r--r--src/math/types.h44
7 files changed, 103 insertions, 20 deletions
diff --git a/src/math/curve.c b/src/math/curve.c
index 422156b..e9d1364 100644
--- a/src/math/curve.c
+++ b/src/math/curve.c
@@ -3,8 +3,8 @@
* Copyright (C) 2017 J08nY
*/
#include "curve.h"
+#include "exhaustive/seed.h"
#include "field.h"
-#include "random/seed.h"
curve_t *curve_new() {
curve_t *curve = pari_malloc(sizeof(curve_t));
@@ -59,23 +59,6 @@ int curve_nonzero(curve_t *curve, config_t *config, ...) {
}
}
-int curve_prime(curve_t *curve, config_t *config, ...) {
- pari_sp ltop = avma;
- int nonzero = curve_nonzero(curve, config);
- if (nonzero == 1) {
- curve->order = ellsea(curve->curve, 1);
- if (gequal0(curve->order) || !(isprime(curve->order))) {
- avma = ltop;
- return -3;
- } else {
- return 1;
- }
- } else {
- avma = ltop;
- return nonzero;
- }
-}
-
int curve_seed_fp(curve_t *curve, config_t *config, ...) {}
int curve_seed_f2m(curve_t *curve, config_t *config, ...) {}
diff --git a/src/math/equation.c b/src/math/equation.c
index 571ee71..b699b9a 100644
--- a/src/math/equation.c
+++ b/src/math/equation.c
@@ -2,8 +2,8 @@
* ecgen, tool for generating Elliptic curve domain parameters
* Copyright (C) 2017 J08nY
*/
-#include <io/input.h>
#include "equation.h"
+#include "io/input.h"
int eq_random(curve_t *curve, config_t *config, ...) {
int r = a_random(curve, config) + b_random(curve, config);
diff --git a/src/math/field.c b/src/math/field.c
index ba2972c..a4b038e 100644
--- a/src/math/field.c
+++ b/src/math/field.c
@@ -32,7 +32,7 @@ int field_random(curve_t *curve, config_t *config, ...) {
}
int field_input(curve_t *curve, config_t *config, ...) {
- return -1; // NOT IMPLEMENTED
+ return INT_MIN; // NOT IMPLEMENTED
}
GEN field_params(GEN field) {
diff --git a/src/math/order.c b/src/math/order.c
new file mode 100644
index 0000000..5e15279
--- /dev/null
+++ b/src/math/order.c
@@ -0,0 +1,21 @@
+/*
+ * ecgen, tool for generating Elliptic curve domain parameters
+ * Copyright (C) 2017 J08nY
+ */
+#include "order.h"
+
+int order_init(curve_t *curve, config_t *cfg, ...) {
+ curve->order = ellff_get_card(curve->curve);
+ return 1;
+}
+
+int order_prime(curve_t *curve, config_t *cfg, ...) {
+ pari_sp ltop = avma;
+ curve->order = ellsea(curve->curve, 1);
+ if (gequal0(curve->order) || !(isprime(curve->order))) {
+ avma = ltop;
+ return -4;
+ } else {
+ return 1;
+ }
+} \ No newline at end of file
diff --git a/src/math/order.h b/src/math/order.h
new file mode 100644
index 0000000..4af994a
--- /dev/null
+++ b/src/math/order.h
@@ -0,0 +1,28 @@
+/*
+ * ecgen, tool for generating Elliptic curve domain parameters
+ * Copyright (C) 2017 J08nY
+ */
+#ifndef ECGEN_ORDER_H
+#define ECGEN_ORDER_H
+
+#include "types.h"
+
+/**
+ *
+ * @param curve
+ * @param cfg
+ * @param ...
+ * @return
+ */
+int order_init(curve_t *curve, config_t *cfg, ...);
+
+/**
+ *
+ * @param curve
+ * @param cfg
+ * @param ...
+ * @return
+ */
+int order_prime(curve_t *curve, config_t *cfg, ...);
+
+#endif //ECGEN_ORDER_H
diff --git a/src/math/types.c b/src/math/types.c
new file mode 100644
index 0000000..958de7f
--- /dev/null
+++ b/src/math/types.c
@@ -0,0 +1,7 @@
+/*
+ * ecgen, tool for generating Elliptic curve domain parameters
+ * Copyright (C) 2017 J08nY
+ */
+#include "types.h"
+
+int gen_skip(curve_t *curve, config_t *config, ...) { return 1; }
diff --git a/src/math/types.h b/src/math/types.h
new file mode 100644
index 0000000..8185078
--- /dev/null
+++ b/src/math/types.h
@@ -0,0 +1,44 @@
+/*
+ * ecgen, tool for generating Elliptic curve domain parameters
+ * Copyright (C) 2017 J08nY
+ */
+#ifndef ECGEN_TYPES_H
+#define ECGEN_TYPES_H
+
+#include <pari/pari.h>
+#include "io/cli.h"
+
+typedef struct seed { GEN seed; } seed_t;
+
+typedef struct point_t {
+ GEN point;
+ GEN order;
+} point_t;
+
+typedef struct curve {
+ seed_t *seed;
+ GEN field;
+ GEN a;
+ GEN b;
+ GEN curve;
+ GEN order;
+ point_t **points;
+ size_t npoints;
+} curve_t;
+
+enum curve_offset {
+ OFFSET_SEED,
+ OFFSET_FIELD,
+ OFFSET_A,
+ OFFSET_B,
+ OFFSET_CURVE,
+ OFFSET_ORDER,
+ OFFSET_POINTS,
+ OFFSET_END
+};
+
+typedef int (*gen_t)(curve_t *, config_t *, ...);
+
+int gen_skip(curve_t *curve, config_t *config, ...);
+
+#endif // ECGEN_TYPES_H