aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ecgen.c4
-rw-r--r--src/exhaustive/exhaustive.c5
-rw-r--r--src/exhaustive/seed.h2
-rw-r--r--src/invalid/invalid.c9
-rw-r--r--src/invalid/invalid.h1
-rw-r--r--src/invalid/invalid_thread.h1
-rw-r--r--src/io/cli.c1
-rw-r--r--src/io/output.c90
-rw-r--r--src/io/output.h134
-rw-r--r--src/math/curve.c1
-rw-r--r--src/math/curve.h1
-rw-r--r--src/math/equation.h1
-rw-r--r--src/math/field.h1
-rw-r--r--src/math/gens.c1
-rw-r--r--src/math/point.c1
-rw-r--r--src/math/point.h1
-rw-r--r--src/math/types.h19
17 files changed, 207 insertions, 66 deletions
diff --git a/src/ecgen.c b/src/ecgen.c
index f482fcd..8ca63ca 100644
--- a/src/ecgen.c
+++ b/src/ecgen.c
@@ -27,8 +27,6 @@
#include "cm/cm.h"
#include "exhaustive/exhaustive.h"
#include "invalid/invalid.h"
-#include "io/cli.h"
-#include "io/config.h"
#include "io/input.h"
#include "io/output.h"
@@ -125,7 +123,7 @@ int quit(int status) {
* - Can generate curves repeatedly until one satisfies requested
* properties:
* - -p / --prime generates curves until a prime order curve is found.
- * - -k / --koblitz generates a curve with fixed A = 0 parameter.
+ * - -K / --koblitz generates a curve with fixed A = 0 parameter.
*
*/
int main(int argc, char *argv[]) {
diff --git a/src/exhaustive/exhaustive.c b/src/exhaustive/exhaustive.c
index 8fab389..3e0209f 100644
--- a/src/exhaustive/exhaustive.c
+++ b/src/exhaustive/exhaustive.c
@@ -232,6 +232,7 @@ int exhaustive_do(config_t *cfg) {
exhaustive_uinit(unrolls, cfg);
exhaustive_init();
+ output_o_begin(cfg);
for (unsigned long i = 0; i < cfg->count; ++i) {
curve_t *curve = curve_new();
if (!exhaustive_gen_retry(curve, cfg, generators, argss, unrolls,
@@ -240,8 +241,12 @@ int exhaustive_do(config_t *cfg) {
return 1;
}
output_o(curve, cfg);
+ if (i != cfg->count - 1) {
+ output_o_separator(cfg);
+ }
curve_free(&curve);
}
+ output_o_end(cfg);
exhaustive_quit(argss);
return 0;
diff --git a/src/exhaustive/seed.h b/src/exhaustive/seed.h
index d4236ce..89c7e07 100644
--- a/src/exhaustive/seed.h
+++ b/src/exhaustive/seed.h
@@ -8,7 +8,7 @@
#ifndef ECGEN_SEED_H
#define ECGEN_SEED_H
-#include "io/cli.h"
+#include "io/input.h"
#include "math/types.h"
/**
diff --git a/src/invalid/invalid.c b/src/invalid/invalid.c
index 20a7063..18224e8 100644
--- a/src/invalid/invalid.c
+++ b/src/invalid/invalid.c
@@ -155,6 +155,9 @@ static size_t invalid_curves(curve_t *curve, config_t *cfg, pari_ulong *primes,
curves[i] = curve_new_copy(invalid);
}
output_o(curves[i], cfg);
+ if (ncurves != nprimes - 1) {
+ output_o_separator(cfg);
+ }
ncurves++;
count++;
}
@@ -241,6 +244,9 @@ static size_t invalid_curves_threaded(curve_t *curve, config_t *cfg,
for (size_t i = 0; i < nprimes; ++i) {
if (old_states[i] != states[i] && states[i] == STATE_GENERATED) {
output_o(local_curves[i], cfg);
+ if (generated != nprimes) {
+ output_o_separator(cfg);
+ }
old_states[i] = states[i];
}
}
@@ -285,7 +291,9 @@ int invalid_do(config_t *cfg) {
curve_free(&curve);
return 1;
}
+ output_o_begin(cfg);
output_o(curve, cfg);
+ output_o_separator(cfg);
// now, generate primes upto order^2
pari_ulong *primes;
@@ -316,6 +324,7 @@ int invalid_do(config_t *cfg) {
ncurves = invalid_curves_threaded(curve, cfg, primes, nprimes, curves,
invalid_gen, unrolls);
}
+ output_o_end(cfg);
for (size_t i = 0; i < ncurves; ++i) {
curve_free(&curves[i]);
diff --git a/src/invalid/invalid.h b/src/invalid/invalid.h
index 43de25a..035692c 100644
--- a/src/invalid/invalid.h
+++ b/src/invalid/invalid.h
@@ -8,7 +8,6 @@
#ifndef ECGEN_INVALID_H
#define ECGEN_INVALID_H
-#include "io/cli.h"
#include "io/config.h"
/**
diff --git a/src/invalid/invalid_thread.h b/src/invalid/invalid_thread.h
index d8c1b76..2c6275f 100644
--- a/src/invalid/invalid_thread.h
+++ b/src/invalid/invalid_thread.h
@@ -8,7 +8,6 @@
#ifndef ECGEN_INVALID_THREAD_H
#define ECGEN_INVALID_THREAD_H
-#include <pari/pari.h>
#include <pthread.h>
#include "math/types.h"
diff --git a/src/io/cli.c b/src/io/cli.c
index 228e339..cc2f156 100644
--- a/src/io/cli.c
+++ b/src/io/cli.c
@@ -6,7 +6,6 @@
#include <string.h>
#include <unistd.h>
#include "config.h"
-#include "io/config.h"
char doc[] =
"ecgen, tool for generating Elliptic curve domain parameters.\v(C) 2017 "
diff --git a/src/io/output.c b/src/io/output.c
index fd83965..6fe8802 100644
--- a/src/io/output.c
+++ b/src/io/output.c
@@ -11,6 +11,16 @@
FILE *out;
FILE *verbose;
+char *output_malloc(const char *what) {
+ char *s = pari_malloc(sizeof(char) * (strlen(what) + 1));
+ if (!s) {
+ perror("Couldn't malloc.");
+ exit(1);
+ }
+ strcpy(s, what);
+ return s;
+}
+
char *output_scsv(curve_t *curve, const config_t *cfg) {
pari_sp ltop = avma;
GEN vector = curve_params(curve);
@@ -48,15 +58,11 @@ char *output_scsv(curve_t *curve, const config_t *cfg) {
return result;
}
-void output_fcsv(FILE *out, curve_t *curve, const config_t *cfg) {
- char *string = output_scsv(curve, cfg);
- fprintf(out, "%s\n", string);
- free(string);
-}
+char *output_scsv_separator(const config_t *cfg) { return output_malloc("\n"); }
-void output_csv(curve_t *curve, const config_t *cfg) {
- output_fcsv(out, curve, cfg);
-}
+char *output_scsv_begin(const config_t *cfg) { return NULL; }
+
+char *output_scsv_end(const config_t *cfg) { return output_malloc("\n"); }
static JSON_Value *output_jjson(curve_t *curve, const config_t *cfg) {
pari_sp ltop = avma;
@@ -176,16 +182,56 @@ char *output_sjson(curve_t *curve, const config_t *cfg) {
return result;
}
-void output_fjson(FILE *out, curve_t *curve, const config_t *cfg) {
- char *s = output_sjson(curve, cfg);
- fprintf(out, "%s\n", s);
- json_free_serialized_string(s);
+char *output_sjson_separator(const config_t *cfg) {
+ return output_malloc(",\n");
}
-void output_json(curve_t *curve, const config_t *cfg) {
- output_fjson(out, curve, cfg);
+char *output_sjson_begin(const config_t *cfg) { return output_malloc("[\n"); }
+
+char *output_sjson_end(const config_t *cfg) { return output_malloc("]\n"); }
+
+void output_f(FILE *out, curve_t *curve, const config_t *cfg) {
+ char *s = output_s(curve, cfg);
+ if (s) {
+ fprintf(out, "%s", s);
+ pari_free(s);
+ }
}
+void output_o(curve_t *curve, const config_t *cfg) {
+ output_f(out, curve, cfg);
+}
+
+void output_f_separator(FILE *out, const config_t *cfg) {
+ char *s = output_s_separator(cfg);
+ if (s) {
+ fprintf(out, "%s", s);
+ pari_free(s);
+ }
+}
+
+void output_o_separator(const config_t *cfg) { output_f_separator(out, cfg); }
+
+void output_f_begin(FILE *out, const config_t *cfg) {
+ char *s = output_s_begin(cfg);
+ if (s) {
+ fprintf(out, "%s", s);
+ pari_free(s);
+ }
+}
+
+void output_o_begin(const config_t *cfg) { output_f_begin(out, cfg); }
+
+void output_f_end(FILE *out, const config_t *cfg) {
+ char *s = output_s_end(cfg);
+ if (s) {
+ fprintf(out, "%s", s);
+ pari_free(s);
+ }
+}
+
+void output_o_end(const config_t *cfg) { output_f_end(out, cfg); }
+
void output_init(const config_t *cfg) {
json_set_allocation_functions(pari_malloc, pari_free);
@@ -212,16 +258,20 @@ void output_init(const config_t *cfg) {
setvbuf(verbose, NULL, _IONBF, 0);
switch (cfg->format) {
- case FORMAT_JSON:
+ case FORMAT_JSON: {
output_s = &output_sjson;
- output_f = &output_fjson;
- output_o = &output_json;
+ output_s_separator = &output_sjson_separator;
+ output_s_begin = &output_sjson_begin;
+ output_s_end = &output_sjson_end;
break;
- case FORMAT_CSV:
+ }
+ case FORMAT_CSV: {
output_s = &output_scsv;
- output_f = &output_fcsv;
- output_o = &output_csv;
+ output_s_separator = &output_scsv_separator;
+ output_s_begin = &output_scsv_begin;
+ output_s_end = &output_scsv_end;
break;
+ }
}
}
diff --git a/src/io/output.h b/src/io/output.h
index bf85e60..ef36f99 100644
--- a/src/io/output.h
+++ b/src/io/output.h
@@ -13,7 +13,7 @@
#include "math/types.h"
/**
- *
+ * @brief Output curve to a pari_malloc'ed string in CSV format.
* @param curve
* @param config
* @return
@@ -21,22 +21,29 @@
char *output_scsv(curve_t *curve, const config_t *cfg);
/**
- *
- * @param out
- * @param curve
- * @param config
+ * @brief Output CSV separator(newline) to a pari_malloc'ed string in CSV
+ * format.
+ * @param cfg
+ * @return
*/
-void output_fcsv(FILE *out, curve_t *curve, const config_t *cfg);
+char *output_scsv_separator(const config_t *cfg);
/**
- *
- * @param curve
- * @param config
+ * @brief Output CSV output header to a pari_malloc'ed string in CSV format.
+ * @param cfg
+ * @return
*/
-void output_csv(curve_t *curve, const config_t *cfg);
+char *output_scsv_begin(const config_t *cfg);
/**
- *
+ * @brief Output CSV output footer to a pari_malloc'ed string in CSV format.
+ * @param cfg
+ * @return
+ */
+char *output_scsv_end(const config_t *cfg);
+
+/**
+ * @brief Output curve to a pari_malloc'ed string in JSON format.
* @param curve
* @param config
* @return
@@ -44,22 +51,31 @@ void output_csv(curve_t *curve, const config_t *cfg);
char *output_sjson(curve_t *curve, const config_t *cfg);
/**
- *
- * @param out
- * @param curve
- * @param config
+ * @brief Output JSON separator(a ",\n") to a pari_malloc'ed string in CSV
+ * format.
+ * @param cfg
+ * @return
*/
-void output_fjson(FILE *out, curve_t *curve, const config_t *cfg);
+char *output_sjson_separator(const config_t *cfg);
/**
- *
- * @param curve
- * @param config
+ * @brief Output JSON output header(a "[") to a pari_malloc'ed string in CSV
+ * format.
+ * @param cfg
+ * @return
*/
-void output_json(curve_t *curve, const config_t *cfg);
+char *output_sjson_begin(const config_t *cfg);
/**
- *
+ * @brief Output JSON output footer(a "]") to a pari_malloc'ed string in CSV
+ * format.
+ * @param cfg
+ * @return
+ */
+char *output_sjson_end(const config_t *cfg);
+
+/**
+ * @brief Output curve to a pari_malloc'ed string in configured format.
* @param curve
* @param config
* @return
@@ -67,38 +83,98 @@ void output_json(curve_t *curve, const config_t *cfg);
char *(*output_s)(curve_t *curve, const config_t *cfg);
/**
- *
+ * @brief Output curve to a FILE *out in configured format.
* @param out
* @param curve
* @param config
*/
-void (*output_f)(FILE *out, curve_t *curve, const config_t *cfg);
+void output_f(FILE *out, curve_t *curve, const config_t *cfg);
/**
- *
+ * @brief Output curve to configured output in configured format.
* @param curve
* @param config
*/
-void (*output_o)(curve_t *curve, const config_t *cfg);
+void output_o(curve_t *curve, const config_t *cfg);
+
+/**
+ * @brief Output separator to a pari_malloc'ed string in configured format.
+ * @param cfg
+ * @return
+ */
+char *(*output_s_separator)(const config_t *cfg);
+
+/**
+ * @brief Output separator to a FILE *out in configured format.
+ * @param out
+ * @param cfg
+ */
+void output_f_separator(FILE *out, const config_t *cfg);
+
+/**
+ * @brief Output separator to configured output in configured format.
+ * @param cfg
+ */
+void output_o_separator(const config_t *cfg);
+
+/**
+ * @brief Output header to a pari_malloc'ed string in configured format.
+ * @param cfg
+ * @return
+ */
+char *(*output_s_begin)(const config_t *cfg);
+
+/**
+ * @brief Output header to a FILE *out in configured format.
+ * @param out
+ * @param cfg
+ */
+void output_f_begin(FILE *out, const config_t *cfg);
+
+/**
+ * @brief Output header to configured output in configured format.
+ * @param cfg
+ */
+void output_o_begin(const config_t *cfg);
+
+/**
+ * @brief Output footer to a pari_malloc'ed string in configured format.
+ * @param cfg
+ * @return
+ */
+char *(*output_s_end)(const config_t *cfg);
+
+/**
+ * @brief Output footer to a FILE *out in configured format.
+ * @param out
+ * @param cfg
+ */
+void output_f_end(FILE *out, const config_t *cfg);
+
+/**
+ * @brief Output header to configured output in configured format.
+ * @param cfg
+ */
+void output_o_end(const config_t *cfg);
/**
- *
+ * @brief Configured output FILE*.
*/
extern FILE *out;
/**
- *
+ * @brief Configured verbose output FILE*.
*/
extern FILE *verbose;
/**
- *
+ * @brief Initialize output based on cfg.
* @param cfg
*/
void output_init(const config_t *cfg);
/**
- *
+ * @brief Deinitialize output.
*/
void output_quit(void);
diff --git a/src/math/curve.c b/src/math/curve.c
index 32c4b84..00e65f0 100644
--- a/src/math/curve.c
+++ b/src/math/curve.c
@@ -5,7 +5,6 @@
#include "curve.h"
#include "exhaustive/seed.h"
#include "field.h"
-#include "io/output.h"
#include "point.h"
curve_t *curve_new(void) {
diff --git a/src/math/curve.h b/src/math/curve.h
index d1aaf27..c250040 100644
--- a/src/math/curve.h
+++ b/src/math/curve.h
@@ -9,7 +9,6 @@
#define ECGEN_CURVE_H
#include <pari/pari.h>
-#include "io/cli.h"
#include "types.h"
/**
diff --git a/src/math/equation.h b/src/math/equation.h
index 1f80f21..858d318 100644
--- a/src/math/equation.h
+++ b/src/math/equation.h
@@ -8,7 +8,6 @@
#ifndef ECGEN_EQUATION_H
#define ECGEN_EQUATION_H
-#include "io/cli.h"
#include "types.h"
/**
diff --git a/src/math/field.h b/src/math/field.h
index b1dc4f3..0bd79df 100644
--- a/src/math/field.h
+++ b/src/math/field.h
@@ -8,7 +8,6 @@
#ifndef ECGEN_FIELD_H
#define ECGEN_FIELD_H
-#include "io/cli.h"
#include "types.h"
/**
diff --git a/src/math/gens.c b/src/math/gens.c
index ef47525..5965f9a 100644
--- a/src/math/gens.c
+++ b/src/math/gens.c
@@ -3,7 +3,6 @@
* Copyright (C) 2017 J08nY
*/
#include "gens.h"
-#include "io/output.h"
#include "point.h"
static int gens_put(curve_t *curve, GEN generators, long len) {
diff --git a/src/math/point.c b/src/math/point.c
index 5233b6d..d8a9d8d 100644
--- a/src/math/point.c
+++ b/src/math/point.c
@@ -3,7 +3,6 @@
* Copyright (C) 2017 J08nY
*/
#include "point.h"
-#include "io/output.h"
point_t *point_new(void) {
point_t *point = pari_malloc(sizeof(point_t));
diff --git a/src/math/point.h b/src/math/point.h
index ef6facf..15c626b 100644
--- a/src/math/point.h
+++ b/src/math/point.h
@@ -8,7 +8,6 @@
#ifndef ECGEN_POINT_H
#define ECGEN_POINT_H
-#include <pari/pari.h>
#include "types.h"
/**
diff --git a/src/math/types.h b/src/math/types.h
index 8a7d004..64b9c99 100644
--- a/src/math/types.h
+++ b/src/math/types.h
@@ -8,8 +8,8 @@
#ifndef ECGEN_TYPES_H
#define ECGEN_TYPES_H
+#include <limits.h>
#include <pari/pari.h>
-#include "io/cli.h"
#include "io/config.h"
/**
@@ -22,7 +22,10 @@ typedef struct seed_t {
} seed_t;
/**
- * @brief
+ * @brief A point type.
+ * @param point a t_VEC with t_INTMOD or t_FFELT components [x,y]
+ * @param order a t_INT
+ * @param cofactor a t_INT
*/
typedef struct {
GEN point;
@@ -31,7 +34,17 @@ typedef struct {
} point_t;
/**
- * @brief
+ * @brief A curve type.
+ * @param seed a seed_t
+ * @param field a t_INT or t_FFELT
+ * @param a a t_INTMOD or t_FFELT a parameter
+ * @param b a t_INTMOD or t_FFELT b parameter
+ * @param curve a t_ELL, curve object
+ * @param order a t_INT, curve order
+ * @param generators generators saved
+ * @param ngens numver of generators saved in the curve type
+ * @param points points saved
+ * @param npoints number of points saved in the curve type
*/
typedef struct {
seed_t *seed;