aboutsummaryrefslogtreecommitdiff
path: root/src/math
diff options
context:
space:
mode:
authorJ08nY2017-02-28 17:00:39 +0100
committerJ08nY2017-02-28 17:00:39 +0100
commit2cbd1a82a756f15cfb987713bce6ac02dad64623 (patch)
tree01dac90a9f27645ccdb1d1d42c6facfb257915c0 /src/math
parent55fd80d2563f461e96dfd680730a2bc416ca5f98 (diff)
downloadecgen-2cbd1a82a756f15cfb987713bce6ac02dad64623.tar.gz
ecgen-2cbd1a82a756f15cfb987713bce6ac02dad64623.tar.zst
ecgen-2cbd1a82a756f15cfb987713bce6ac02dad64623.zip
Added irreducibility check, equation_quit, gens_one
- irreducibility check in field_input for f2m - equation_quit frees stuff possibly allocated by a_once and b_once - gens_one requests the curve to have only one generator - renamed some base generators to _any from _init, as they dont really init anythong, just do no checks
Diffstat (limited to 'src/math')
-rw-r--r--src/math/curve.c6
-rw-r--r--src/math/curve.h2
-rw-r--r--src/math/equation.c9
-rw-r--r--src/math/equation.h19
-rw-r--r--src/math/field.c6
-rw-r--r--src/math/gens.c27
-rw-r--r--src/math/gens.h27
-rw-r--r--src/math/order.c4
-rw-r--r--src/math/order.h2
-rw-r--r--src/math/types.h7
10 files changed, 95 insertions, 14 deletions
diff --git a/src/math/curve.c b/src/math/curve.c
index b01c795..284cd39 100644
--- a/src/math/curve.c
+++ b/src/math/curve.c
@@ -41,7 +41,7 @@ void curve_free(curve_t **curve) {
}
}
-int curve_init(curve_t *curve, config_t *config, arg_t *args) {
+int curve_any(curve_t *curve, config_t *config, arg_t *args) {
pari_sp ltop = avma;
GEN v = gen_0;
switch (typ(curve->field)) {
@@ -57,7 +57,7 @@ int curve_init(curve_t *curve, config_t *config, arg_t *args) {
gel(v, 5) = curve->b;
break;
default:
- pari_err_TYPE("curve_init", curve->field);
+ pari_err_TYPE("curve_any", curve->field);
}
curve->curve = gerepilecopy(ltop, ellinit(v, curve->field, -1));
@@ -66,7 +66,7 @@ int curve_init(curve_t *curve, config_t *config, arg_t *args) {
int curve_nonzero(curve_t *curve, config_t *config, arg_t *args) {
pari_sp ltop = avma;
- curve_init(curve, config, args);
+ curve_any(curve, config, args);
if (gequal0(ell_get_disc(curve->curve))) {
avma = ltop;
return -3;
diff --git a/src/math/curve.h b/src/math/curve.h
index cc241b4..3da391b 100644
--- a/src/math/curve.h
+++ b/src/math/curve.h
@@ -22,7 +22,7 @@
* @param args unused
* @return state diff
*/
-int curve_init(curve_t *curve, config_t *config, arg_t *args);
+int curve_any(curve_t *curve, config_t *config, arg_t *args);
/**
* GENERATOR(gen_t)
diff --git a/src/math/equation.c b/src/math/equation.c
index 023b823..2f57d03 100644
--- a/src/math/equation.c
+++ b/src/math/equation.c
@@ -102,3 +102,12 @@ int b_seed(curve_t *curve, config_t *config, arg_t *args) {
// TODO implement
return INT_MIN;
}
+
+void equation_quit(void) {
+ if (a && isclone(a)) {
+ gunclone(a);
+ }
+ if (b && isclone(b)) {
+ gunclone(b);
+ }
+}
diff --git a/src/math/equation.h b/src/math/equation.h
index 4e0202e..28ded06 100644
--- a/src/math/equation.h
+++ b/src/math/equation.h
@@ -68,6 +68,13 @@ int a_zero(curve_t *curve, config_t *config, arg_t *args);
*/
int a_one(curve_t *curve, config_t *config, arg_t *args);
+/**
+ * @brief
+ * @param curve
+ * @param config
+ * @param args
+ * @return
+ */
int a_seed(curve_t *curve, config_t *config, arg_t *args);
/**
@@ -126,6 +133,18 @@ int b_zero(curve_t *curve, config_t *config, arg_t *args);
*/
int b_one(curve_t *curve, config_t *config, arg_t *args);
+/**
+ * @brief
+ * @param curve
+ * @param config
+ * @param args
+ * @return
+ */
int b_seed(curve_t *curve, config_t *config, arg_t *args);
+/**
+ *
+ */
+void equation_quit(void);
+
#endif // ECGEN_EQUATION_H
diff --git a/src/math/field.c b/src/math/field.c
index 09b9a51..983aa09 100644
--- a/src/math/field.c
+++ b/src/math/field.c
@@ -75,7 +75,11 @@ int field_input(curve_t *curve, config_t *config, arg_t *args) {
gel(v, 1) = gen_1;
GEN poly = gmul(gtopolyrev(v, -1), gmodulss(1, 2));
- // TODO check irreducibility here
+ if (!isirreducible(poly)) {
+ fprintf(stderr, "Polynomial is reducible.\n");
+ avma = ltop;
+ return 0;
+ }
GEN field = gerepilecopy(ltop, ffgen(poly, -1));
curve->field = field;
diff --git a/src/math/gens.c b/src/math/gens.c
index ac81960..f211a82 100644
--- a/src/math/gens.c
+++ b/src/math/gens.c
@@ -1,11 +1,11 @@
-
+/*
+ * ecgen, tool for generating Elliptic curve domain parameters
+ * Copyright (C) 2017 J08nY
+ */
#include "gens.h"
#include "point.h"
-int gens_init(curve_t *curve, config_t *config, arg_t *args) {
- // TODO stack code!!!
- GEN generators = ellff_get_gens(curve->curve);
- long len = glength(generators);
+int gens_put(curve_t *curve, GEN generators, long len) {
curve->generators = points_new((size_t)len);
curve->ngens = (size_t)len;
@@ -19,3 +19,20 @@ int gens_init(curve_t *curve, config_t *config, arg_t *args) {
return 1;
}
+
+int gens_any(curve_t *curve, config_t *config, arg_t *args) {
+ GEN generators = ellff_get_gens(curve->curve);
+ long len = glength(generators);
+ return gens_put(curve, generators, len);
+}
+
+int gens_one(curve_t *curve, config_t *config, arg_t *args) {
+ pari_sp ltop = avma;
+ GEN generators = ellff_get_gens(curve->curve);
+ long len = glength(generators);
+ if (len == 2) {
+ avma = ltop;
+ return -5;
+ }
+ return gens_put(curve, generators, len);
+}
diff --git a/src/math/gens.h b/src/math/gens.h
index b3f7774..a1ae34f 100644
--- a/src/math/gens.h
+++ b/src/math/gens.h
@@ -1,9 +1,32 @@
-
+/*
+ * ecgen, tool for generating Elliptic curve domain parameters
+ * Copyright (C) 2017 J08nY
+ */
+/**
+ * @brief
+ * @file gens.h
+ */
#ifndef ECGEN_GENS_H
#define ECGEN_GENS_H
#include "types.h"
-int gens_init(curve_t *curve, config_t *config, arg_t *args);
+/**
+ * @brief
+ * @param curve
+ * @param config
+ * @param args
+ * @return
+ */
+int gens_any(curve_t *curve, config_t *config, arg_t *args);
+
+/**
+ * @brief
+ * @param curve
+ * @param config
+ * @param args
+ * @return
+ */
+int gens_one(curve_t *curve, config_t *config, arg_t *args);
#endif // ECGEN_GENS_H
diff --git a/src/math/order.c b/src/math/order.c
index 7e7eeda..83d7e0d 100644
--- a/src/math/order.c
+++ b/src/math/order.c
@@ -4,7 +4,7 @@
*/
#include "order.h"
-int order_init(curve_t *curve, config_t *cfg, arg_t *args) {
+int order_any(curve_t *curve, config_t *cfg, arg_t *args) {
curve->order = ellff_get_card(curve->curve);
return 1;
}
@@ -17,6 +17,7 @@ int order_smallfact(curve_t *curve, config_t *cfg, arg_t *args) {
pari_ulong smallfact = *(pari_ulong *)args->args;
pari_sp ltop = avma;
curve->order = ellsea(curve->curve, smallfact);
+ obj_insert_shallow(curve->curve, 1, curve->order);
if (gequal0(curve->order)) {
avma = ltop;
return -4;
@@ -28,6 +29,7 @@ int order_smallfact(curve_t *curve, config_t *cfg, arg_t *args) {
int order_prime(curve_t *curve, config_t *cfg, arg_t *args) {
pari_sp ltop = avma;
curve->order = ellsea(curve->curve, 1);
+ obj_insert_shallow(curve->curve, 1, curve->order);
if (gequal0(curve->order) || !(isprime(curve->order))) {
avma = ltop;
return -4;
diff --git a/src/math/order.h b/src/math/order.h
index 4562fab..14adc79 100644
--- a/src/math/order.h
+++ b/src/math/order.h
@@ -20,7 +20,7 @@
* @param args
* @return state diff
*/
-int order_init(curve_t *curve, config_t *cfg, arg_t *args);
+int order_any(curve_t *curve, config_t *cfg, arg_t *args);
/**
* GENERATOR(gen_t)
diff --git a/src/math/types.h b/src/math/types.h
index 70696ad..43ee7cf 100644
--- a/src/math/types.h
+++ b/src/math/types.h
@@ -51,6 +51,13 @@ typedef struct arg_t {
typedef int (*gen_t)(curve_t *, config_t *, arg_t *);
+/**
+ * @brief
+ * @param curve
+ * @param config
+ * @param args
+ * @return
+ */
int gen_skip(curve_t *curve, config_t *config, arg_t *args);
#endif // ECGEN_TYPES_H