aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ecgen.c3
-rw-r--r--src/io/cli.c2
-rw-r--r--src/io/cli.h2
-rw-r--r--src/math/curve.c5
-rw-r--r--src/math/field.c12
-rw-r--r--src/math/poly.h2
-rw-r--r--src/math/types.h8
7 files changed, 21 insertions, 13 deletions
diff --git a/src/ecgen.c b/src/ecgen.c
index 7d457f7..9b978a0 100644
--- a/src/ecgen.c
+++ b/src/ecgen.c
@@ -24,6 +24,7 @@
* @copyright GPL v2.0
*/
#include <pari/pari.h>
+#include "io/cli.h"
#include "cm/cm.h"
#include "exhaustive/exhaustive.h"
#include "invalid/invalid.h"
@@ -40,7 +41,7 @@ const char *argp_program_version =
const char *argp_program_bug_address = "<johny@neuromancer.sk>";
static struct argp argp = {options, cli_parse, args_doc, doc, 0, cli_filter};
-static struct config_t cfg;
+static config_t cfg;
bool init(void) {
// Init PARI, 1GB stack, 1M primes
diff --git a/src/io/cli.c b/src/io/cli.c
index 84f5794..4e4a7f9 100644
--- a/src/io/cli.c
+++ b/src/io/cli.c
@@ -62,7 +62,7 @@ struct argp_option options[] = {
// clang-format on
error_t cli_parse(int key, char *arg, struct argp_state *state) {
- struct config_t *cfg = state->input;
+ config_t *cfg = state->input;
switch (key) {
case OPT_DATADIR:
diff --git a/src/io/cli.h b/src/io/cli.h
index a62f95b..9960aca 100644
--- a/src/io/cli.h
+++ b/src/io/cli.h
@@ -24,7 +24,7 @@ struct points_s {
size_t amount;
};
-typedef struct config_t {
+typedef struct{
enum field_e field;
bool binary_field;
bool prime_field;
diff --git a/src/math/curve.c b/src/math/curve.c
index 812dbcc..15ce0f5 100644
--- a/src/math/curve.c
+++ b/src/math/curve.c
@@ -6,6 +6,7 @@
#include "exhaustive/seed.h"
#include "field.h"
#include "point.h"
+#include "types.h"
curve_t *curve_new(void) {
curve_t *curve = pari_malloc(sizeof(curve_t));
@@ -68,8 +69,8 @@ int curve_any(curve_t *curve, config_t *cfg, arg_t *args) {
case t_FFELT:
v = gtovec0(gen_0, 5);
gel(v, 1) = gen_1;
- gel(v, 4) = curve->a;
- gel(v, 5) = curve->b;
+ gel(v, 2) = curve->a;
+ gel(v, 4) = curve->b;
break;
default:
pari_err_TYPE("curve_any", curve->field);
diff --git a/src/math/field.c b/src/math/field.c
index cc3656f..f717bf8 100644
--- a/src/math/field.c
+++ b/src/math/field.c
@@ -2,6 +2,7 @@
* ecgen, tool for generating Elliptic curve domain parameters
* Copyright (C) 2017 J08nY
*/
+#include <io/cli.h>
#include "field.h"
#include "io/input.h"
#include "poly.h"
@@ -45,6 +46,12 @@ int field_input(curve_t *curve, config_t *cfg, arg_t *args) {
return 1;
}
case FIELD_BINARY: {
+ GEN m = input_short("m:");
+ if (!equalis(m, cfg->bits)) {
+ avma = ltop;
+ return 0;
+ }
+
GEN e1 = input_short("e1:");
if (equalii(e1, gen_m1)) {
avma = ltop;
@@ -68,7 +75,7 @@ int field_input(curve_t *curve, config_t *cfg, arg_t *args) {
}
GEN v = gtovec0(gen_0, cfg->bits + 1);
- gel(v, cfg->bits + 1) = gen_1;
+ gel(v, itos(m) + 1) = gen_1;
if (gsigne(e1) == 1) gel(v, itos(e1) + 1) = gen_1;
if (gsigne(e2) == 1) gel(v, itos(e2) + 1) = gen_1;
if (gsigne(e3) == 1) gel(v, itos(e3) + 1) = gen_1;
@@ -81,8 +88,7 @@ int field_input(curve_t *curve, config_t *cfg, arg_t *args) {
return 0;
}
- GEN field = gerepilecopy(ltop, ffgen(poly, -1));
- curve->field = field;
+ curve->field = gerepilecopy(ltop, ffgen(poly, -1));
return 1;
}
default:
diff --git a/src/math/poly.h b/src/math/poly.h
index c69313f..f9793f4 100644
--- a/src/math/poly.h
+++ b/src/math/poly.h
@@ -11,7 +11,7 @@
#include <pari/pari.h>
#include <stdbool.h>
-typedef struct polynomial_t {
+typedef struct {
int m;
int e1;
int e2;
diff --git a/src/math/types.h b/src/math/types.h
index 38dadbe..4eb2bd4 100644
--- a/src/math/types.h
+++ b/src/math/types.h
@@ -11,15 +11,15 @@
#include <pari/pari.h>
#include "io/cli.h"
-typedef struct seed_t { GEN seed; } seed_t;
+typedef struct { GEN seed; } seed_t;
-typedef struct point_t {
+typedef struct {
GEN point;
GEN order;
GEN cofactor;
} point_t;
-typedef struct curve_t {
+typedef struct {
seed_t *seed;
GEN field;
GEN a;
@@ -44,7 +44,7 @@ enum curve_offset {
OFFSET_END
};
-typedef struct arg_t {
+typedef struct {
void *args;
size_t nargs;
} arg_t;