aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJ08nY2017-05-20 22:03:43 +0200
committerJ08nY2017-05-20 22:03:43 +0200
commitfd170a41d12db27e722f39832d4689eed3ad14b2 (patch)
tree98915a6436b1dfb564f2b402cada8bfcde165709
parent132a768b5718cef1ff621380f2dcf21cd0553404 (diff)
downloadecgen-fd170a41d12db27e722f39832d4689eed3ad14b2.tar.gz
ecgen-fd170a41d12db27e722f39832d4689eed3ad14b2.tar.zst
ecgen-fd170a41d12db27e722f39832d4689eed3ad14b2.zip
-rw-r--r--CMakeLists.txt2
-rw-r--r--README.md15
-rw-r--r--src/Makefile2
-rw-r--r--src/ecgen.c8
-rw-r--r--src/io/cli.c58
-rw-r--r--src/io/cli.h6
6 files changed, 50 insertions, 41 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index dec4b32..49cf3d0 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -11,7 +11,7 @@ include_directories(lib)
find_library(parson parson/libparson.a)
find_library(sha1 sha1/libsha1.a)
-file(GLOB SRC "src/math/*.c" "src/cm/*.c" "src/invalid/*.c" "src/io/*.c" "src/exhaustive/*.c")
+file(GLOB SRC "src/math/*.c" "src/cm/*.c" "src/invalid/*.c" "src/io/*.c" "src/exhaustive/*.c" "src/util/*.c")
set(ECGEN_SRC "src/ecgen.c" ${SRC})
set(ECONVERT_SRC "src/econvert.c" ${SRC})
diff --git a/README.md b/README.md
index 25fedeb..ad5242d 100644
--- a/README.md
+++ b/README.md
@@ -15,14 +15,14 @@ Tool for generating Elliptic curve domain parameters.
- `-c / --count=COUNT` Generate multiple curves.
- `-i / --invalid` Generate a set of invalid curves, for a given curve (using Invalid curve algorithm).
- - `-k / --cofactor=BOUND` Generate a curve with cofactor up to `BOUND` **TODO**
+ - `-k / --cofactor=BOUND` Generate a curve with cofactor up to `BOUND` **TODO - NOT FINISHED**
- `--anomalous` Generate an anomalous curve (of trace one, with field order equal to curve order).
- `-K / --koblitz` Generate a Koblitz curve (a = 0).
- - `-n / --order=ORDER` Generate a curve with given `ORDER` (using Complex Multiplication). **TODO**
+ - `-n / --order=ORDER` Generate a curve with given `ORDER` (using Complex Multiplication). **TODO - NOT IMPLEMENTED**
- `-p / --prime` Generate a curve with prime order.
- `--points=TYPE` Generate points of given `TYPE` (random/prime/none).
- `-r / --random` Generate a random curve (using Random approach).
- - `-s / --seed[=SEED]` Generate a curve from `SEED` (ANSI X9.62 verifiable procedure).
+ - `-s / --seed[=SEED]` Generate a curve from `SEED` (ANSI X9.62 verifiable procedure). **TODO - NOT IMPLEMENTED**
- `-u / --unique` Generate a curve with only one generator.
#### IO options
@@ -137,10 +137,19 @@ Three different EC curve parameters generation methods are implemented.
- PARI/GP
+
ecgen uses the [PARI/GP](http://pari.math.u-bordeaux.fr/) library for elliptic
curve arithmetic and it's SEA point counting algorithm implementation. It also requires the
additional [seadata](http://pari.math.u-bordeaux.fr/packages.html) package (seadata and seadata-big recommended for large curves).
+### Libraries
+
+ - `lib/parson` *©MIT*
+ - `lib/sha1` *©MPL / GPLv2 or later*
+
+[parson](https://github.com/kgabis/parson) is used to input and output JSON and is included in the `lib/` directory.
+
+A [SHA-1](lib/sha1/sha1.c) implementation by Paul Kocher, based on the SHA 180-1 Reference Implementation (for ANSI X9.62 algorithm) is used and also included in the `lib/` directory.
### License
diff --git a/src/Makefile b/src/Makefile
index bf3fc48..7d0c83f 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -21,8 +21,6 @@ LIBS = -lrt -lpari -lpthread -lparson -lsha1
####
-VPATH = cm:invalid:io:exhaustive:math
-
ECGEN_SRC = ecgen.c $(wildcard */*.c)
ECGEN_OBJ = $(patsubst %.c,%.o, $(ECGEN_SRC))
diff --git a/src/ecgen.c b/src/ecgen.c
index 8ca63ca..ea8f8ff 100644
--- a/src/ecgen.c
+++ b/src/ecgen.c
@@ -27,6 +27,7 @@
#include "cm/cm.h"
#include "exhaustive/exhaustive.h"
#include "invalid/invalid.h"
+#include "io/cli.h"
#include "io/input.h"
#include "io/output.h"
@@ -37,9 +38,10 @@ const char *argp_program_version =
"<http://gnu.org/licenses/gpl.html>\n"
"This is free software: you are free to change and redistribute it.\n"
"There is NO WARRANTY, to the extent permitted by law.";
-const char *argp_program_bug_address = "<johny@neuromancer.sk>";
+const char *argp_program_bug_address = "<johny+ecgen@neuromancer.sk>";
-static struct argp argp = {options, cli_parse, args_doc, doc, 0, cli_filter};
+static struct argp argp = {cli_options, cli_parse, cli_args_doc,
+ cli_doc, 0, cli_filter};
static config_t cfg;
bool init(void) {
@@ -135,7 +137,7 @@ int main(int argc, char *argv[]) {
return quit(1);
}
- int status = 0;
+ int status;
if (cfg.cm) {
status = cm_do(&cfg);
} else if (cfg.invalid) {
diff --git a/src/io/cli.c b/src/io/cli.c
index 5c0a79f..dadb65e 100644
--- a/src/io/cli.c
+++ b/src/io/cli.c
@@ -7,10 +7,10 @@
#include <unistd.h>
#include "config.h"
-char doc[] =
+char cli_doc[] =
"ecgen, tool for generating Elliptic curve domain parameters.\v(C) 2017 "
"Eastern Seaboard Phishing Authority";
-char args_doc[] = "bits";
+char cli_args_doc[] = "bits";
enum opt_keys {
OPT_DATADIR = 'd',
@@ -38,33 +38,33 @@ enum opt_keys {
};
// clang-format off
-struct argp_option options[] = {
- {0, 0, 0, 0, "Field specification:", 1},
- {"fp", OPT_FP, 0, 0, "Prime field.", 1},
- {"f2m", OPT_F2M, 0, 0, "Binary field.", 1},
- {0, 0, 0, 0, "Generation options:", 2},
- {"random", OPT_RANDOM, 0, 0, "Generate a random curve (using Random approach).", 2},
- {"prime", OPT_PRIME, 0, 0, "Generate a curve with prime order.", 2},
- {"cofactor", OPT_COFACTOR, "BOUND", 0, "Generate a curve with cofactor up to BOUND.", 2},
- {"koblitz", OPT_KOBLITZ, 0, 0, "Generate a Koblitz curve (a = 0).", 2},
- {"unique", OPT_UNIQUE, 0, 0, "Generate a curve with only one generator.", 2},
- {"anomalous",OPT_ANOMALOUS,0, 0, "Generate an anomalous curve (of trace one, with field order equal to curve order).", 2},
- {"points", OPT_POINTS, "TYPE", 0, "Generate points of given type (random/prime/none).", 2},
- {"seed", OPT_SEED, "SEED", OPTION_ARG_OPTIONAL, "Generate a curve from SEED (ANSI X9.62 verifiable procedure).", 2},
- {"invalid", OPT_INVALID, 0, 0, "Generate a set of invalid curves, for a given curve (using Invalid curve algorithm).", 2},
- {"order", OPT_ORDER, "ORDER", 0, "Generate a curve with given order (using Complex Multiplication).", 2},
- {"count", OPT_COUNT, "COUNT", 0, "Generate multiple curves.", 2},
- {0, 0, 0, 0, "Input/Output options:", 3},
- {"format", OPT_FORMAT, "FORMAT", 0, "Format to output in. One of [csv,json], default is json.", 3},
- {"input", OPT_INPUT, "FILE", 0, "Input from file.", 3},
- {"output", OPT_OUTPUT, "FILE", 0, "Output into file. Overwrites any existing file!", 3},
- {"append", OPT_APPEND, 0, 0, "Append to output file (don't overwrite).", 3},
- {"verbose", OPT_VERBOSE, "FILE", OPTION_ARG_OPTIONAL, "Verbose logging (to stdout or file).", 3},
- {0, 0, 0, 0, "Other:", 4},
- {"data-dir", OPT_DATADIR, "DIR", 0, "Set PARI/GP data directory (containing seadata package).", 4},
- {"memory", OPT_MEMORY, "SIZE", 0, "Use PARI stack of SIZE (can have suffix k/m/g).", 4},
- {"threads", OPT_THREADS, "NUM", 0, "Use NUM threads.", 4},
- {"thread-stack",OPT_TSTACK,"SIZE", 0, "Use PARI stack of SIZE (per thread, can have suffix k/m/g).", 4},
+struct argp_option cli_options[] = {
+ {0, 0, 0, 0, "Field specification:", 1},
+ {"fp", OPT_FP, 0, 0, "Prime field.", 1},
+ {"f2m", OPT_F2M, 0, 0, "Binary field.", 1},
+ {0, 0, 0, 0, "Generation options:", 2},
+ {"random", OPT_RANDOM, 0, 0, "Generate a random curve (using Random approach).", 2},
+ {"prime", OPT_PRIME, 0, 0, "Generate a curve with prime order.", 2},
+ {"cofactor", OPT_COFACTOR, "BOUND", 0, "Generate a curve with cofactor up to BOUND.", 2},
+ {"koblitz", OPT_KOBLITZ, 0, 0, "Generate a Koblitz curve (a = 0).", 2},
+ {"unique", OPT_UNIQUE, 0, 0, "Generate a curve with only one generator.", 2},
+ {"anomalous", OPT_ANOMALOUS, 0, 0, "Generate an anomalous curve (of trace one, with field order equal to curve order).", 2},
+ {"points", OPT_POINTS, "TYPE", 0, "Generate points of given type (random/prime/none).", 2},
+ {"seed", OPT_SEED, "SEED", OPTION_ARG_OPTIONAL, "Generate a curve from SEED (ANSI X9.62 verifiable procedure). **NOT IMPLEMENTED**", 2},
+ {"invalid", OPT_INVALID, 0, 0, "Generate a set of invalid curves, for a given curve (using Invalid curve algorithm).", 2},
+ {"order", OPT_ORDER, "ORDER", 0, "Generate a curve with given order (using Complex Multiplication). **NOT IMPLEMENTED**", 2},
+ {"count", OPT_COUNT, "COUNT", 0, "Generate multiple curves.", 2},
+ {0, 0, 0, 0, "Input/Output options:", 3},
+ {"format", OPT_FORMAT, "FORMAT", 0, "Format to output in. One of [csv,json], default is json.", 3},
+ {"input", OPT_INPUT, "FILE", 0, "Input from file.", 3},
+ {"output", OPT_OUTPUT, "FILE", 0, "Output into file. Overwrites any existing file!", 3},
+ {"append", OPT_APPEND, 0, 0, "Append to output file (don't overwrite).", 3},
+ {"verbose", OPT_VERBOSE, "FILE", OPTION_ARG_OPTIONAL, "Verbose logging (to stdout or file).", 3},
+ {0, 0, 0, 0, "Other:", 4},
+ {"data-dir", OPT_DATADIR, "DIR", 0, "Set PARI/GP data directory (containing seadata package).", 4},
+ {"memory", OPT_MEMORY, "SIZE", 0, "Use PARI stack of SIZE (can have suffix k/m/g).", 4},
+ {"threads", OPT_THREADS, "NUM", 0, "Use NUM threads.", 4},
+ {"thread-stack", OPT_TSTACK, "SIZE", 0, "Use PARI stack of SIZE (per thread, can have suffix k/m/g).", 4},
{0}
};
// clang-format on
diff --git a/src/io/cli.h b/src/io/cli.h
index c670328..3ae314e 100644
--- a/src/io/cli.h
+++ b/src/io/cli.h
@@ -12,9 +12,9 @@
#include <stdbool.h>
#include <stdlib.h>
-extern char doc[];
-extern char args_doc[];
-extern struct argp_option options[];
+extern char cli_doc[];
+extern char cli_args_doc[];
+extern struct argp_option cli_options[];
error_t cli_parse(int key, char *arg, struct argp_state *state);