aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Makefile10
-rw-r--r--src/econvert.c29
-rw-r--r--src/exhaustive/brainpool.c10
-rw-r--r--src/exhaustive/brainpool_rfc.c8
-rw-r--r--src/io/cli.c13
-rw-r--r--src/io/output.c117
-rw-r--r--src/io/output.h25
-rw-r--r--src/misc/config.h2
8 files changed, 21 insertions, 193 deletions
diff --git a/src/Makefile b/src/Makefile
index 65b0135..06d3642 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -27,24 +27,17 @@ LIBS = -lrt -lpari -lpthread -lparson -lsha1
ECGEN_SRC = ecgen.c $(wildcard */*.c)
ECGEN_OBJ = $(patsubst %.c,%.o, $(ECGEN_SRC))
-ECONVERT_SRC = econvert.c
-ECONVERT_OBJ = $(patsubst %.c,%.o, $(ECONVERT_SRC))
-
SRC = $(wildcard *.c) $(wildcard */*.c)
HDR = $(wildcard */*.h)
####
-all: ecgen econvert
+all: ecgen
ecgen: ecgen.o $(ECGEN_OBJ)
$(CC) $(CFLAGS) $(INCLUDES) -o $@ $^ $(LDFLAGS) $(LIBS)
mv ecgen ..
-econvert: econvert.o $(ECONVERT_OBJ)
- $(CC) $(CFLAGS) $(INCLUDES) -o $@ $^ $(LDFLAGS) $(LIBS)
- mv econvert ..
-
%.o: %.c
$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $<
@@ -52,7 +45,6 @@ econvert: econvert.o $(ECONVERT_OBJ)
clean-all: clean clean-cov
rm -f ../ecgen
- rm -f ../econvert
clean:
find . -type f -name '*.o' -exec rm {} +
diff --git a/src/econvert.c b/src/econvert.c
deleted file mode 100644
index ae1e143..0000000
--- a/src/econvert.c
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * ecgen, tool for generating Elliptic curve domain parameters
- * Copyright (C) 2017-2018 J08nY
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
- * USA.
- */
-#include <stdio.h>
-
-/**
- * @file econvert.c
- * @author J08nY <johny@neuromancer.sk>
- * @version 0.6.3
- * @copyright GPL v2.0
- */
-
-int main(void) { fprintf(stderr, "This is not implemented *yet*.\n"); }
diff --git a/src/exhaustive/brainpool.c b/src/exhaustive/brainpool.c
index 30558eb..17c2c65 100644
--- a/src/exhaustive/brainpool.c
+++ b/src/exhaustive/brainpool.c
@@ -169,7 +169,7 @@ GENERATOR(brainpool_gen_equation) {
avma = btop;
continue;
}
- //seed->brainpool.seed_a = bits_copy(seed->seed);
+ // seed->brainpool.seed_a = bits_copy(seed->seed);
brainpool_update_seed(seed->seed);
@@ -179,11 +179,11 @@ GENERATOR(brainpool_gen_equation) {
bits_free(&b_bits);
if (!Fp_issquare(b, curve->field)) {
brainpool_update_seed(seed->seed);
- //bits_free(&seed->brainpool.seed_a);
+ // bits_free(&seed->brainpool.seed_a);
avma = btop;
continue;
}
- //seed->brainpool.seed_b = bits_copy(seed->seed);
+ // seed->brainpool.seed_b = bits_copy(seed->seed);
GEN mod_a = gmodulo(a, curve->field);
GEN mod_b = gmodulo(b, curve->field);
@@ -191,8 +191,8 @@ GENERATOR(brainpool_gen_equation) {
if (gequal0(gmulsg(-16, gadd(gmulsg(4, gpowgs(mod_a, 3)),
gmulsg(27, gsqr(mod_b)))))) {
brainpool_update_seed(seed->seed);
- //bits_free(&seed->brainpool.seed_a);
- //bits_free(&seed->brainpool.seed_b);
+ // bits_free(&seed->brainpool.seed_a);
+ // bits_free(&seed->brainpool.seed_b);
avma = btop;
continue;
}
diff --git a/src/exhaustive/brainpool_rfc.c b/src/exhaustive/brainpool_rfc.c
index 0c0eed6..4e41dec 100644
--- a/src/exhaustive/brainpool_rfc.c
+++ b/src/exhaustive/brainpool_rfc.c
@@ -57,7 +57,7 @@ GENERATOR(brainpool_rfc_gen_equation) {
avma = btop;
continue;
}
- //seed->brainpool.seed_a = bits_copy(seed->seed);
+ // seed->brainpool.seed_a = bits_copy(seed->seed);
GEN b = NULL;
pari_sp bbtop = avma;
@@ -72,7 +72,7 @@ GENERATOR(brainpool_rfc_gen_equation) {
bits_free(&b_bits);
} while (Fp_issquare(b, curve->field));
- //seed->brainpool.seed_b = bits_copy(seed->seed);
+ // seed->brainpool.seed_b = bits_copy(seed->seed);
GEN mod_a = gmodulo(a, curve->field);
GEN mod_b = gmodulo(b, curve->field);
@@ -80,8 +80,8 @@ GENERATOR(brainpool_rfc_gen_equation) {
if (gequal0(gmulsg(-16, gadd(gmulsg(4, gpowgs(mod_a, 3)),
gmulsg(27, gsqr(mod_b)))))) {
brainpool_update_seed(seed->seed);
- //bits_free(&seed->brainpool.seed_a);
- //bits_free(&seed->brainpool.seed_b);
+ // bits_free(&seed->brainpool.seed_a);
+ // bits_free(&seed->brainpool.seed_b);
avma = btop;
continue;
}
diff --git a/src/io/cli.c b/src/io/cli.c
index 2ea14f8..c192021 100644
--- a/src/io/cli.c
+++ b/src/io/cli.c
@@ -72,7 +72,6 @@ struct argp_option cli_options[] = {
{"count", OPT_COUNT, "COUNT", 0, "Generate multiple curves.", 3},
{0, 0, 0, 0, "Input/Output options:", 4},
- {"format", OPT_FORMAT, "FORMAT", 0, "Format to output in. One of {csv, json}, default is json.", 4},
{"input", OPT_INPUT, "FILE", 0, "Input from file.", 4},
{"output", OPT_OUTPUT, "FILE", 0, "Output into file. Overwrites any existing file!", 4},
{"append", OPT_APPEND, 0, 0, "Append to output file (don't overwrite).", 4},
@@ -198,6 +197,7 @@ static void cli_end(struct argp_state *state) {
if (!cfg->points.type) {
cfg->points.type = POINTS_PRIME;
}
+ cfg->format = FORMAT_JSON;
}
error_t cli_parse(int key, char *arg, struct argp_state *state) {
@@ -335,17 +335,6 @@ error_t cli_parse(int key, char *arg, struct argp_state *state) {
break;
}
/* IO options */
- case OPT_FORMAT:
- if (!strcmp(arg, "csv")) {
- cfg->format = FORMAT_CSV;
- } else if (!strcmp(arg, "json")) {
- cfg->format = FORMAT_JSON;
- } else {
- argp_failure(state, 1, 0,
- "Invalid format specified. One of [csv, json] "
- "is valid.");
- }
- break;
case OPT_INPUT:
cfg->input = arg;
break;
diff --git a/src/io/output.c b/src/io/output.c
index df3d6a4..4d8fca0 100644
--- a/src/io/output.c
+++ b/src/io/output.c
@@ -19,105 +19,6 @@ char *output_malloc(const char *what) {
return s;
}
-char *output_scsv(curve_t *curve) {
- pari_sp ltop = avma;
- char *params[OFFSET_END] = {NULL};
-
- switch (cfg->field) {
- case FIELD_PRIME:
- params[OFFSET_FIELD] =
- pari_sprintf("%P0#*x", cfg->hex_digits, curve->field);
- break;
- case FIELD_BINARY: {
- GEN field = field_params(curve->field);
- params[OFFSET_FIELD] =
- pari_sprintf("%P#x,%P#x,%P#x,%P#x", gel(field, 1),
- gel(field, 2), gel(field, 3), gel(field, 4));
- break;
- }
- }
-
- if (curve->a)
- params[OFFSET_A] =
- pari_sprintf("%P0#*x", cfg->hex_digits, field_elementi(curve->a));
- if (curve->b)
- params[OFFSET_B] =
- pari_sprintf("%P0#*x", cfg->hex_digits, field_elementi(curve->b));
-
- if (curve->generators) {
- char *gens[curve->ngens];
- size_t len = 0;
- for (size_t i = 0; i < curve->ngens; ++i) {
- point_t *generator = curve->generators[i];
- GEN x = field_elementi(gel(generator->point, 1));
- GEN y = field_elementi(gel(generator->point, 2));
- gens[i] = pari_sprintf("%P0#*x,%P0#*x,%P#x,%P#x", cfg->hex_digits,
- x, cfg->hex_digits, y, generator->order,
- generator->cofactor);
- len += strlen(gens[i]);
- }
- size_t lenn = sizeof(char) * (len + curve->ngens);
- params[OFFSET_GENERATORS] = pari_calloc(lenn);
- for (size_t i = 0; i < curve->ngens; ++i) {
- if (i > 0) strncat(params[OFFSET_GENERATORS], ",", lenn - 1);
- strncat(params[OFFSET_GENERATORS], gens[i], lenn - 1);
- pari_free(gens[i]);
- }
- }
-
- if (curve->order)
- params[OFFSET_ORDER] =
- pari_sprintf("%P0#*x", cfg->hex_digits, curve->order);
-
- if (curve->points) {
- char *points[curve->npoints];
- size_t len = 0;
- for (size_t i = 0; i < curve->npoints; ++i) {
- point_t *point = curve->points[i];
- GEN x = field_elementi(gel(point->point, 1));
- GEN y = field_elementi(gel(point->point, 2));
- points[i] = pari_sprintf("%P0#*x,%P0#*x,%P#x", cfg->hex_digits, x,
- cfg->hex_digits, y, point->order);
- len += strlen(points[i]);
- }
- size_t lenn = sizeof(char) * (len + curve->npoints);
- params[OFFSET_POINTS] = pari_calloc(lenn);
- for (size_t i = 0; i < curve->npoints; ++i) {
- if (i > 0) strncat(params[OFFSET_POINTS], ",", lenn - 1);
- strncat(params[OFFSET_POINTS], points[i], lenn - 1);
- pari_free(points[i]);
- }
- }
-
- size_t len = 0;
- size_t count = 0;
- for (int i = OFFSET_FIELD; i < OFFSET_END; ++i) {
- if (params[i]) {
- len += strlen(params[i]);
- ++count;
- }
- }
- size_t lenn = sizeof(char) * (len + count);
- char *result = try_calloc(lenn);
-
- for (int i = OFFSET_FIELD; i < OFFSET_END; ++i) {
- if (params[i]) {
- if (i > OFFSET_FIELD) strncat(result, ",", lenn - 1);
- strncat(result, params[i], lenn - 1);
- pari_free(params[i]);
- }
- }
-
- avma = ltop;
- return result;
-}
-
-char *output_scsv_separator() { return output_malloc("\n"); }
-
-char *output_scsv_begin() { return NULL; }
-
-char *output_scsv_end() { return output_malloc("\n"); }
-
static JSON_Value *output_jjson(curve_t *curve) {
pari_sp ltop = avma;
// root object/value is curve
@@ -333,22 +234,22 @@ bool output_init() {
output_s_end = &output_sjson_end;
break;
}
- case FORMAT_CSV: {
- output_s = &output_scsv;
- output_s_separator = &output_scsv_separator;
- output_s_begin = &output_scsv_begin;
- output_s_end = &output_scsv_end;
- break;
- }
}
return true;
}
+static bool output_is_std(FILE *stream) {
+ return (stream == stdout || stream == stderr || stream == stdin);
+}
+
void output_quit(void) {
- if (out != NULL && out != stdout) {
+ if (!output_is_std(out)) {
fclose(out);
}
- if (err != NULL && err != stdout) {
+ if (!output_is_std(err)) {
fclose(err);
}
+ if (!output_is_std(verbose)) {
+ fclose(verbose); // My name is fClose Verbose!
+ }
}
diff --git a/src/io/output.h b/src/io/output.h
index 1037c00..6c048d9 100644
--- a/src/io/output.h
+++ b/src/io/output.h
@@ -78,31 +78,6 @@
#define output_log(...) pari_fprintf(out, __VA_ARGS__)
/**
- * @brief Output curve to a malloc'ed string in CSV format.
- * @param curve
- * @return
- */
-char *output_scsv(curve_t *curve);
-
-/**
- * @brief Output CSV separator(newline) to a malloc'ed string in CSV format.
- * @return
- */
-char *output_scsv_separator();
-
-/**
- * @brief Output CSV output header to a malloc'ed string in CSV format.
- * @return
- */
-char *output_scsv_begin();
-
-/**
- * @brief Output CSV output footer to a malloc'ed string in CSV format.
- * @return
- */
-char *output_scsv_end();
-
-/**
* @brief Output curve to a malloc'ed string in JSON format.
* @param curve
* @return
diff --git a/src/misc/config.h b/src/misc/config.h
index 367de52..9a8f8af 100644
--- a/src/misc/config.h
+++ b/src/misc/config.h
@@ -12,7 +12,7 @@
#include <stddef.h>
enum field_e { FIELD_PRIME = 1 << 0, FIELD_BINARY = 1 << 1 };
-enum format_e { FORMAT_JSON, FORMAT_CSV };
+enum format_e { FORMAT_JSON };
enum points_e {
POINTS_NONE = 0,
POINTS_PRIME,