diff options
| author | J08nY | 2018-02-27 16:47:27 +0100 |
|---|---|---|
| committer | J08nY | 2018-02-27 16:47:27 +0100 |
| commit | b86ede073f78121f58cbad9a56f55041191a150b (patch) | |
| tree | 67b548d8540f57968d342499d9c68e42327b96a2 | |
| parent | 76b8866222b9abd5f25a795ff719914e852e14ab (diff) | |
| download | ecgen-b86ede073f78121f58cbad9a56f55041191a150b.tar.gz ecgen-b86ede073f78121f58cbad9a56f55041191a150b.tar.zst ecgen-b86ede073f78121f58cbad9a56f55041191a150b.zip | |
| -rw-r--r-- | Makefile | 1 | ||||
| -rw-r--r-- | README.md | 7 | ||||
| -rw-r--r-- | docs/output.md | 44 | ||||
| -rw-r--r-- | src/Makefile | 10 | ||||
| -rw-r--r-- | src/econvert.c | 29 | ||||
| -rw-r--r-- | src/exhaustive/brainpool.c | 10 | ||||
| -rw-r--r-- | src/exhaustive/brainpool_rfc.c | 8 | ||||
| -rw-r--r-- | src/io/cli.c | 13 | ||||
| -rw-r--r-- | src/io/output.c | 117 | ||||
| -rw-r--r-- | src/io/output.h | 25 | ||||
| -rw-r--r-- | src/misc/config.h | 2 | ||||
| -rw-r--r-- | test/Makefile | 7 | ||||
| -rwxr-xr-x | test/ecgen.sh | 16 | ||||
| -rwxr-xr-x | test/econvert.sh | 20 |
14 files changed, 31 insertions, 278 deletions
@@ -38,7 +38,6 @@ help: @echo "Available targets:" @echo " - all : builds all" @echo " - ecgen : builds the main binary" - @echo " - econvert : build the format conversion binary" @echo " - docs : generate doxygen docs" @echo " - test : test the main binary" @echo " - unittest : " @@ -32,7 +32,6 @@ Tool for generating Elliptic curve domain parameters. #### IO options -- `-t / --format=FORMAT` Format to output in. One of [csv,json], default is json. - `-f / --input=FILE` Input from `FILE`. - `-o / --output=FILE` Output into `FILE`. Overwrites any existing file! - `-a / --append` Append to output file (don't overwrite). @@ -52,9 +51,9 @@ Generate a prime field, uniquely generated, prime order, 192-bit curve, don't as > ecgen --fp -u -p -r 192 -Generate 5 random, binary field, 163-bit koblitz curves: +Generate 5 random, binary field, 163-bit curves: - > ecgen --f2m -r -K -c5 163 + > ecgen --f2m -r -c5 163 Generate invalid curves to a file, for a given prime field 192-bit curve: @@ -115,7 +114,7 @@ Three different EC curve parameters generation methods are implemented. - given input - 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 Koblitz curve. - `-u / --unique` generates a uniquely generated curve (with one generator/cyclic group). - etc.. diff --git a/docs/output.md b/docs/output.md index 26b30db..ec18419 100644 --- a/docs/output.md +++ b/docs/output.md @@ -1,6 +1,6 @@ # Output -There are two output formats currently supported in ecgen, JSON and CSV. These are enabled by using the `-tjson / --format=json`, `-tcsv / --format=csv` options, respectively. +There are only output format currently supported in ecgen is JSON. ## JSON @@ -102,45 +102,3 @@ Self-explanatory format. The curve dictionaries are enclosed in an array as you } ] }] - - -## CSV - -This format is useful mostly for input and is not uniquely parseable for most curves, thus is deprecated. It is uniquely parseable for the set of common cryptographic domain parameters. - -#### Notation - - - `p` - prime F_p - - `m` - binary field exponent F_2^m - - `e1` - largest exponent of the field polynomial - - `e2` - middle exponenet of the field polynomial, or `0000` if field poly is a trinomial - - `e3` - smallest exponent (except zero) of the field polynomial, or `0000` if field poly is a trinomial - - `a` - a parameter in short Weierstrass curve equation - - `b` - b parameter in short Weierstrass curve equation - - `gx` - x coordinate of the curve base-point g - - `gy` - y coordinate of the curve base-point g - - `n` - the base-point order - - `h` - the base-point cofactor - - `px` - the x coordinate of the point - - `py` - the y coordinate of the point - - `op` - the order of the point - -#### Prime field - - p, a, b, gx, gy, n, h - -More generaly: - - p, a, b, gx, gy(, gx2, gy2)?, n, (px, py, op)*, h - -#### Binary field - - m, e1, e2, e3, a, b, gx, gy, n, h - -More generaly: - - m, e1, e2, e3, a, b, gx, gy(, gx2, gy2)?, n, (px, py, op)*, h - -#### Example: - - 0x9bbd697be66af329,0x49ec7aa186e501f7,0x88e93b218fff3b55,0x9bbd697c54a8e780,0x206c5696b67702bb,0x328f7cb39358ae23,0x26ef5a5f152a39e0,0x4,0x1af56d479450c41b,0x01902f3d0c1ae199,0x9bbd697c54a8e78,0x10,0x21fdf0cd456005f6,0x0000000000000000,0x2,0x682f77abb827b2fa,0x8b7adcd4b4bbdb7f,0x685,0x94bc802fc965c386,0x212c07693dbabc19,0x2fc6c2a43943
\ No newline at end of file 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, diff --git a/test/Makefile b/test/Makefile index 0823862..13bcd32 100644 --- a/test/Makefile +++ b/test/Makefile @@ -5,9 +5,9 @@ # #### -test: ecgen econvert +test: ecgen -unittest: unit ecgen econvert +unittest: unit ecgen unit: cd lib/criterion && mkdir -p build && cd build && cmake .. >/dev/null && cmake --build . >/dev/null @@ -16,9 +16,6 @@ unit: ecgen: ./ecgen.sh -econvert: - ./econvert.sh - clean: +$(MAKE) -C src clean diff --git a/test/ecgen.sh b/test/ecgen.sh index 145c3a4..22ac164 100755 --- a/test/ecgen.sh +++ b/test/ecgen.sh @@ -15,18 +15,12 @@ function runs() { assert_raises "${ecgen}" 64 } -function csv() { - start_test - assert_matches "${ecgen} --fp -tcsv --input=data/fp_10_a.csv.in 10" "$(cat data/fp_10_a.csv)" - assert_matches "${ecgen} --f2m -tcsv --input=data/f2m_10_a.csv.in 10" "$(cat data/f2m_10_a.csv)" -} - function json() { start_test - assert_raises "${ecgen} --fp -tjson --input=data/fp_10_a.csv.in 10" - assert_raises "${ecgen} --f2m -tjson --input=data/f2m_10_a.csv.in 10" - fp=$(${ecgen} --fp -tjson --input=data/fp_10_a.csv.in 10 2>/dev/null) - f2m=$(${ecgen} --f2m -tjson --input=data/f2m_10_a.csv.in 10 2>/dev/null) + assert_raises "${ecgen} --fp --input=data/fp_10_a.csv.in 10" + assert_raises "${ecgen} --f2m --input=data/f2m_10_a.csv.in 10" + fp=$(${ecgen} --fp --input=data/fp_10_a.csv.in 10 2>/dev/null) + f2m=$(${ecgen} --f2m --input=data/f2m_10_a.csv.in 10 2>/dev/null) assert_raises "${JSON}" 0 "${fp}" assert_matches "${JSON} -x field\\\",\\\"p" "0x000b" "${fp}" assert_matches "${JSON} -x \\\"a\\\"" "0x0001" "${fp}" @@ -116,7 +110,6 @@ function twist() { function cli() { start_test assert_raises "${ecgen} --threads=a" 1 - assert_raises "${ecgen} --format=something" 1 assert_raises "${ecgen} --koblitz=2" 1 assert_raises "${ecgen} --points=something" 1 assert_raises "${ecgen} --seed=some" 64 @@ -137,7 +130,6 @@ function hex() { . ${ASSERT} -v start_suite runs -csv json exhaustive ansix962 diff --git a/test/econvert.sh b/test/econvert.sh deleted file mode 100755 index ed1943c..0000000 --- a/test/econvert.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env bash -#### -# -# ecgen, tool for generating Elliptic curve domain parameters -# Copyright (C) 2017 J08nY -# -#### - -. ./common.sh - -function runs() { - start_test - assert_raises "${econvert} --help" - assert_raises "${econvert} --version" -} - -. ${ASSERT} -v -start_suite -runs -end_suite econvert
\ No newline at end of file |
