aboutsummaryrefslogtreecommitdiff
path: root/src/math
diff options
context:
space:
mode:
authorJ08nY2017-04-07 02:45:32 +0200
committerJ08nY2017-04-07 02:45:32 +0200
commit7f4596f2735d6011f7413edd7211b8673ecb4a14 (patch)
treed2c745ee2bb615933a9efde7476ef258319609db /src/math
parent59b338cf8734f89c04042f217fcccf8509c3a197 (diff)
downloadecgen-7f4596f2735d6011f7413edd7211b8673ecb4a14.tar.gz
ecgen-7f4596f2735d6011f7413edd7211b8673ecb4a14.tar.zst
ecgen-7f4596f2735d6011f7413edd7211b8673ecb4a14.zip
Fix binary field curve generation, move config into config.h
Diffstat (limited to 'src/math')
-rw-r--r--src/math/equation.c18
-rw-r--r--src/math/field.c19
-rw-r--r--src/math/field.h8
-rw-r--r--src/math/types.h3
4 files changed, 42 insertions, 6 deletions
diff --git a/src/math/equation.c b/src/math/equation.c
index d676350..d60a8cd 100644
--- a/src/math/equation.c
+++ b/src/math/equation.c
@@ -3,7 +3,9 @@
* Copyright (C) 2017 J08nY
*/
#include "equation.h"
+#include "io/cli.h"
#include "io/input.h"
+#include "math/field.h"
int a_random(curve_t *curve, config_t *cfg, arg_t *args) {
curve->a = genrand(curve->field);
@@ -17,8 +19,12 @@ int a_input(curve_t *curve, config_t *cfg, arg_t *args) {
avma = ltop;
return 0;
}
- curve->a = inp;
- // TODO change a to a field element here?. a t_INTMOD or a t_FFELT.
+ GEN elem = field_ielement(curve->field, inp);
+ if (!elem) {
+ avma = ltop;
+ return 0;
+ }
+ curve->a = elem;
return 1;
}
@@ -68,8 +74,12 @@ int b_input(curve_t *curve, config_t *cfg, arg_t *args) {
avma = ltop;
return 0;
}
- curve->b = inp;
- // TODO change b to a field element here?. a t_INTMOD or a t_FFELT.
+ GEN elem = field_ielement(curve->field, inp);
+ if (!elem) {
+ avma = ltop;
+ return 0;
+ }
+ curve->b = elem;
return 1;
}
diff --git a/src/math/field.c b/src/math/field.c
index f717bf8..5f7bea3 100644
--- a/src/math/field.c
+++ b/src/math/field.c
@@ -2,11 +2,12 @@
* ecgen, tool for generating Elliptic curve domain parameters
* Copyright (C) 2017 J08nY
*/
-#include <io/cli.h>
#include "field.h"
+#include <io/cli.h>
#include "io/input.h"
#include "poly.h"
#include "random.h"
+#include "types.h"
static GEN field_primer(long bits) { return random_prime(bits); }
@@ -158,3 +159,19 @@ GEN field_elementi(GEN element) {
return NULL; /* NOT REACHABLE */
}
}
+
+GEN field_ielement(GEN field, GEN in) {
+ switch (typ(field)) {
+ case t_INT:
+ return Fp_to_mod(in, field);
+ case t_FFELT: {
+ pari_sp ltop = avma;
+ GEN coeffs = digits(in, gen_2);
+ GEN poly = gtopoly(coeffs, -1);
+ return gerepilecopy(ltop, Fq_to_FF(poly, field));
+ }
+ default:
+ pari_err_TYPE("field_ielement, field is unknown type. ", field);
+ return gen_m1; /* NOT REACHABLE */
+ }
+}
diff --git a/src/math/field.h b/src/math/field.h
index 3ed300c..66c8920 100644
--- a/src/math/field.h
+++ b/src/math/field.h
@@ -67,4 +67,12 @@ GEN field_params(GEN field);
*/
GEN field_elementi(GEN element);
+/**
+ *
+ * @param field
+ * @param in
+ * @return
+ */
+GEN field_ielement(GEN field, GEN in);
+
#endif // ECGEN_FIELD_H
diff --git a/src/math/types.h b/src/math/types.h
index 4eb2bd4..a726021 100644
--- a/src/math/types.h
+++ b/src/math/types.h
@@ -10,6 +10,7 @@
#include <pari/pari.h>
#include "io/cli.h"
+#include "io/config.h"
typedef struct { GEN seed; } seed_t;
@@ -19,7 +20,7 @@ typedef struct {
GEN cofactor;
} point_t;
-typedef struct {
+typedef struct {
seed_t *seed;
GEN field;
GEN a;