aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJ08nY2017-02-28 17:00:39 +0100
committerJ08nY2017-02-28 17:00:39 +0100
commit2cbd1a82a756f15cfb987713bce6ac02dad64623 (patch)
tree01dac90a9f27645ccdb1d1d42c6facfb257915c0
parent55fd80d2563f461e96dfd680730a2bc416ca5f98 (diff)
downloadecgen-2cbd1a82a756f15cfb987713bce6ac02dad64623.tar.gz
ecgen-2cbd1a82a756f15cfb987713bce6ac02dad64623.tar.zst
ecgen-2cbd1a82a756f15cfb987713bce6ac02dad64623.zip
-rw-r--r--Doxyfile2
-rw-r--r--Makefile22
-rw-r--r--src/Makefile17
-rw-r--r--src/ecgen.c1
-rw-r--r--src/exhaustive/exhaustive.c10
-rw-r--r--src/invalid/invalid.c6
-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
16 files changed, 131 insertions, 36 deletions
diff --git a/Doxyfile b/Doxyfile
index 3134d4c..7ef0fc0 100644
--- a/Doxyfile
+++ b/Doxyfile
@@ -38,7 +38,7 @@ PROJECT_NAME = "ecgen"
# could be handy for archiving the generated documentation or if some version
# control system is used.
-PROJECT_NUMBER = 0.2
+PROJECT_NUMBER = 0.3
# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
diff --git a/Makefile b/Makefile
index 80cad13..d29dcca 100644
--- a/Makefile
+++ b/Makefile
@@ -7,7 +7,27 @@
all:
+$(MAKE) -C src all
+docs:
+ doxygen Doxyfile
+
+help:
+ @echo "ecgen, tool for generating Elliptic curve domain parameters"
+ @echo
+ @echo "Available targets:"
+ @echo " - all : builds all"
+ @echo " - ecgen : builds the main binary"
+ @echo " - gp2c : generates the .c and .h files from gp code"
+ @echo " - docs : generate doxygen docs"
+ @echo " - clean : cleans up after a build"
+ @echo " - clean-gp : cleans up after gp2c generation"
+ @echo " - clean-all : cleans all"
+ @echo " - format : run clang-format on source files"
+ @echo " - help : print this help"
+
+.PHONY: all docs help
+
+ifeq (, $(filter all docs help, $(MAKECMDGOALS)))
# Just pass all targets to a Makefile in src
$(MAKECMDGOALS):
+$(MAKE) -C src $@
-
+endif
diff --git a/src/Makefile b/src/Makefile
index 546008b..74378ab 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -14,7 +14,7 @@ LDFLAGS = -L../lib
GP_CFLAGS = -O3 -Wall -fomit-frame-pointer -fno-strict-aliasing -fPIC
GPFLAGS = -g -i4
-INCLUDES = -I. -I../lib -Icm -Iinvalid -Iio -Irandom -Iexhaustive
+INCLUDES = -I. -I../lib -Icm -Iinvalid -Iio -Irandom -Iexhaustive -Imath
LIBS = -lrt -lpari -lparson
####
@@ -54,27 +54,14 @@ $(GPO): $(GPC) $(GPH)
clean-all: clean clean-gp
clean:
- rm -f ecgen
find . -type f -name '*.o' -exec rm {} +
clean-gp:
rm -f $(GPH)
rm -f $(GPC)
-help:
- @echo "ecgen, tool for generating Elliptic curve domain parameters"
- @echo
- @echo "Available targets:"
- @echo " - all : builds all"
- @echo " - ecgen : builds the main binary"
- @echo " - gp2c : generates the .c and .h files from gp code"
- @echo " - clean : cleans up after a build"
- @echo " - clean-gp : cleans up after gp2c generation"
- @echo " - clean-all : cleans all"
- @echo " - format : run clang-format on source files"
-
format:
clang-format -i $(SRC)
clang-format -i $(HDR)
-.PHONY: all gp2c clean-all clean clean-gp help format
+.PHONY: all gp2c clean-all clean clean-gp format
diff --git a/src/ecgen.c b/src/ecgen.c
index 2783e8f..3585d59 100644
--- a/src/ecgen.c
+++ b/src/ecgen.c
@@ -80,6 +80,7 @@ int quit(int status) {
*
* [Baier] -
* https://www.cdc.informatik.tu-darmstadt.de/reports/reports/harald_baier.diss.pdf
+ *
* [Baier, Buchmann] -
* https://www.ipa.go.jp/security/enc/CRYPTREC/fy15/doc/1030_Buchmann.evaluation.pdf
*
diff --git a/src/exhaustive/exhaustive.c b/src/exhaustive/exhaustive.c
index e1e5487..a405ec1 100644
--- a/src/exhaustive/exhaustive.c
+++ b/src/exhaustive/exhaustive.c
@@ -46,10 +46,10 @@ void exhaustive_ginit(gen_t *generators, config_t *config) {
if (config->prime) {
generators[OFFSET_ORDER] = &order_prime;
} else {
- generators[OFFSET_ORDER] = &order_init;
+ generators[OFFSET_ORDER] = &order_any;
}
}
- generators[OFFSET_GENERATORS] = &gens_init;
+ generators[OFFSET_GENERATORS] = &gens_any;
if (config->random) {
generators[OFFSET_FIELD] = &field_random;
@@ -92,6 +92,10 @@ int exhaustive_gen(curve_t *curve, config_t *config, gen_t generators[],
return 1;
}
+void exhaustive_quit(void) {
+ equation_quit();
+}
+
int exhaustive_do(config_t *cfg) {
gen_t generators[OFFSET_END];
arg_t *argss[OFFSET_END];
@@ -106,5 +110,7 @@ int exhaustive_do(config_t *cfg) {
}
output_o(curve, cfg);
curve_free(&curve);
+
+ exhaustive_quit();
return 0;
}
diff --git a/src/invalid/invalid.c b/src/invalid/invalid.c
index 7663213..69c7021 100644
--- a/src/invalid/invalid.c
+++ b/src/invalid/invalid.c
@@ -24,7 +24,7 @@ void invalid_ginit(gen_t *generators, config_t *cfg) {
generators[OFFSET_B] = &b_input;
}
generators[OFFSET_CURVE] = &curve_nonzero;
- generators[OFFSET_ORDER] = &order_init;
+ generators[OFFSET_ORDER] = &order_any;
}
size_t invalid_primes(GEN order, pari_ulong **primes) {
@@ -76,8 +76,8 @@ size_t invalid_curves(curve_t *curve, config_t *cfg, pari_ulong *primes,
invalid_gen[OFFSET_A] = &gen_skip;
invalid_gen[OFFSET_B] = &b_random;
invalid_gen[OFFSET_CURVE] = &curve_nonzero;
- invalid_gen[OFFSET_ORDER] = &order_init;
- invalid_gen[OFFSET_GENERATORS] = &gens_init;
+ invalid_gen[OFFSET_ORDER] = &order_any;
+ invalid_gen[OFFSET_GENERATORS] = &gens_any;
invalid_gen[OFFSET_POINTS] = &points_primet;
arg_t *invalid_argss[OFFSET_END];
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