diff options
| -rwxr-xr-x | gen.sh | 32 | ||||
| -rw-r--r-- | src/ecgen.c | 10 | ||||
| -rw-r--r-- | src/exhaustive/exhaustive.c | 23 | ||||
| -rw-r--r-- | src/exhaustive/exhaustive.h | 12 | ||||
| -rw-r--r-- | src/exhaustive/seed.c | 2 | ||||
| -rw-r--r-- | src/invalid/invalid.c | 150 | ||||
| -rw-r--r-- | src/io/cli.c | 30 | ||||
| -rw-r--r-- | src/io/input.c | 47 | ||||
| -rw-r--r-- | src/io/input.h | 20 | ||||
| -rw-r--r-- | src/io/output.c | 11 | ||||
| -rw-r--r-- | src/io/output.h | 4 | ||||
| -rw-r--r-- | src/math/curve.c | 2 | ||||
| -rw-r--r-- | src/math/curve.h | 21 | ||||
| -rw-r--r-- | src/math/equation.c | 4 | ||||
| -rw-r--r-- | src/math/field.c | 60 | ||||
| -rw-r--r-- | src/math/order.h | 2 | ||||
| -rw-r--r-- | src/math/point.c | 29 | ||||
| -rw-r--r-- | src/math/point.h | 42 | ||||
| -rw-r--r-- | src/math/random.c | 2 |
19 files changed, 364 insertions, 139 deletions
@@ -1,32 +0,0 @@ -#!/bin/bash - -if [ "$#" -lt 3 ]; then - echo "gen.sh [-l|-s|-p] [num_curves] [prime_size] [timeout]" - exit -fi - -option=$1 -curves=$2 -bits=$3 -timeout=$4 - -time for (( i=1; i <= "$curves"; i++ )); do -p=$(openssl prime -generate -hex -bits "$bits"); -a=$(openssl rand -hex $(($bits / 8))); -b=$(openssl rand -hex $(($bits / 8))); -params="$p\n$a\n$b\n"; - -if [ "$#" -eq 4 ]; then - res=$(echo -e "$params" | timeout "$timeout" ./ecgen "$option"); -else - res=$(echo -e "$params" | ./ecgen "$option"); -fi - -if [ "$?" -ne 0 ]; then - i=$((i - 1)); -else - r=($res); - echo "${r[3]}" | tee -a "${bits}b.curves"; -fi -done - diff --git a/src/ecgen.c b/src/ecgen.c index 3b98e12..21acea9 100644 --- a/src/ecgen.c +++ b/src/ecgen.c @@ -55,10 +55,10 @@ bool init() { } // open outfile - out = output_open(cfg.output, cfg.append); + output_init(cfg.output, cfg.append); // open infile - in = input_open(cfg.input); + input_init(cfg.input); return true; } @@ -66,8 +66,8 @@ bool init() { int quit(int status) { pari_close(); - output_close(out); - input_close(in); + output_quit(); + input_quit(); return status; } @@ -101,8 +101,8 @@ int quit(int status) { * - Generates field and equation parameters: * - randomly * - using ANSI X9.62 verifiably random method(from seed) - * - given input * , until a curve with requested properties appears. + * - given input */ int main(int argc, char *argv[]) { // Parse cli args diff --git a/src/exhaustive/exhaustive.c b/src/exhaustive/exhaustive.c index 402443c..c5cdebd 100644 --- a/src/exhaustive/exhaustive.c +++ b/src/exhaustive/exhaustive.c @@ -55,17 +55,30 @@ void exhaustive_init(gen_t generators[], config_t *config) { } } +int exhaustive_gen(curve_t *curve, config_t *config, gen_t generators[], + int start_offset, int end_offset) { + int state = start_offset; + while (state != end_offset) { + int diff = generators[state](curve, config); + if (diff == INT_MIN) { + fprintf(stderr, "Error generating a curve. %i\n", state); + return 0; + } + state += diff; + } + return 1; +} + int exhaustive_do(config_t *cfg) { gen_t generators[OFFSET_END]; exhaustive_init(generators, cfg); curve_t *curve = curve_new(); - int state = 0; - while (state != OFFSET_POINTS) { - int diff = generators[state](curve, cfg); - state += diff; + if (!exhaustive_gen(curve, cfg, generators, OFFSET_FIELD, OFFSET_POINTS)) { + curve_free(&curve); + return 1; } - output_csv(out, "%Px", ';', curve_params(curve)); + output_csv(out, "%P#x", ';', curve_params(curve)); curve_free(&curve); return 0; }
\ No newline at end of file diff --git a/src/exhaustive/exhaustive.h b/src/exhaustive/exhaustive.h index ee103f4..93c185a 100644 --- a/src/exhaustive/exhaustive.h +++ b/src/exhaustive/exhaustive.h @@ -9,6 +9,18 @@ /** * + * @param curve + * @param config + * @param generators + * @param start_offset + * @param end_offset + * @return + */ +int exhaustive_gen(curve_t *curve, config_t *config, gen_t generators[], + int start_offset, int end_offset); + +/** + * * @param cfg * @return */ diff --git a/src/exhaustive/seed.c b/src/exhaustive/seed.c index a78ff24..0656db5 100644 --- a/src/exhaustive/seed.c +++ b/src/exhaustive/seed.c @@ -53,7 +53,7 @@ int seed_argument(curve_t *curve, config_t *config, ...) { int seed_input(curve_t *curve, config_t *config, ...) { pari_sp ltop = avma; - GEN str = fread_string(in, "seed:", '\n'); + GEN str = fread_string(in, "seed:"); const char *cstr = GSTR(str); if (strlen(cstr) < 20) { fprintf(stderr, "SEED must be at least 160 bits(20 characters).\n"); diff --git a/src/invalid/invalid.c b/src/invalid/invalid.c index 3259908..7fe2dd4 100644 --- a/src/invalid/invalid.c +++ b/src/invalid/invalid.c @@ -3,26 +3,154 @@ * Copyright (C) 2017 J08nY */ #include "invalid.h" +#include "exhaustive/exhaustive.h" +#include "io/output.h" #include "math/curve.h" -#include "math/field.h" #include "math/equation.h" +#include "math/field.h" +#include "math/order.h" + +void invalid_init(gen_t generators[], config_t *cfg) { + generators[OFFSET_SEED] = &gen_skip; + if (cfg->random) { + generators[OFFSET_FIELD] = &field_random; + generators[OFFSET_A] = &a_random; + generators[OFFSET_B] = &b_random; + } else { + generators[OFFSET_FIELD] = &field_input; + generators[OFFSET_A] = &a_input; + generators[OFFSET_B] = &b_input; + } + generators[OFFSET_CURVE] = &curve_nonzero; + generators[OFFSET_ORDER] = &order_init; +} + +size_t invalid_primes(GEN order, pari_ulong **primes) { + pari_sp ltop = avma; + + GEN bound = sqri(order); + GEN product = gen_1; + pari_ulong last = 1; + size_t nprimes = 0; + + size_t size = 10; + *primes = pari_malloc(size * sizeof(pari_ulong)); + while (cmpii(bound, product) >= 0) { + product = mulis(product, last); + (*primes)[nprimes] = unextprime(last + 1); + last = (*primes)[nprimes]; + nprimes++; + if (nprimes == size) { + pari_ulong *new_primes = + pari_realloc(*primes, size * 2 * sizeof(pari_ulong)); + if (new_primes) { + *primes = new_primes; + size *= 2; + } else { + perror("Couldn't malloc."); + return 0; + } + } + } + pari_ulong *new_primes = + pari_realloc(*primes, nprimes * sizeof(pari_ulong)); + if (new_primes) { + *primes = new_primes; + } else { + perror("Couldn't malloc."); + return 0; + } + avma = ltop; + + return nprimes; +} + +size_t invalid_curves(curve_t *curve, config_t *cfg, pari_ulong *primes, + size_t nprimes, curve_t ***curves) { + // Have primes, now generate random b + gen_t invalid_gen[OFFSET_END]; + invalid_gen[OFFSET_FIELD] = &gen_skip; + invalid_gen[OFFSET_A] = &gen_skip; + invalid_gen[OFFSET_B] = &b_random; + invalid_gen[OFFSET_CURVE] = &curve_nonzero; + invalid_gen[OFFSET_ORDER] = &order_init; + + // We will have nprimes curves in the end + *curves = pari_malloc(nprimes * sizeof(curve_t *)); + if (!(*curves)) { + perror("Couldn't malloc."); + return 0; + } + memset(*curves, 0, nprimes * sizeof(curve_t *)); + + // Alloc a curve, and only alloc a new one when this pointer is saved into + // **curves + curve_t *invalid = curve_new(); + // copy field + a from curve to invalid + invalid->field = gcopy(curve->field); + invalid->a = gcopy(curve->a); + + size_t ncurves = 0; + while (ncurves < nprimes) { + pari_sp btop = avma; + // generate a curve with random b + exhaustive_gen(invalid, cfg, invalid_gen, OFFSET_B, OFFSET_POINTS); + + // does some small prime from our array divide the curve order? + size_t count = 0; + for (size_t i = nprimes; i-- > 0;) { + if (dvdis(invalid->order, primes[i]) && (*curves)[i] == NULL) { + if (count == 0) { + (*curves)[i] = invalid; + } else { + (*curves)[i] = curve_new(); + (*curves)[i]->field = gcopy(invalid->field); + (*curves)[i]->a = gcopy(invalid->a); + (*curves)[i]->b = gcopy(invalid->b); + (*curves)[i]->curve = gcopy(invalid->curve); + (*curves)[i]->order = gcopy(invalid->order); + } + output_csv(out, "%P#x", ';', curve_params((*curves)[i])); + ncurves++; + count++; + } + } + if (count > 0) { + invalid = curve_new(); + invalid->field = gcopy(curve->field); + invalid->a = gcopy(curve->a); + } else { + avma = btop; + } + } + return ncurves; +} int invalid_do(config_t *cfg) { // create the curve to invalidate // Either from input or random with -r - curve_t *curve = curve_new(); gen_t gen[OFFSET_END]; - gen[OFFSET_SEED] = &gen_skip; - if (cfg->random) { - gen[OFFSET_FIELD] = &field_random; - gen[OFFSET_A] = &a_random; - gen[OFFSET_B] = &b_random; - } else { - gen[OFFSET_FIELD] = &field_input; - gen[OFFSET_A] = &a_input; - gen[OFFSET_B] = &b_input; + invalid_init(gen, cfg); + + // actually generate the curve + if (!exhaustive_gen(curve, cfg, gen, OFFSET_FIELD, OFFSET_POINTS)) { + curve_free(&curve); + return 1; + } + + // now, generate primes upto order^2 + pari_ulong *primes; + size_t nprimes = invalid_primes(curve->order, &primes); + + curve_t **curves; + size_t ncurves = invalid_curves(curve, cfg, primes, nprimes, &curves); + + for (size_t i = 0; i < ncurves; ++i) { + curve_free(&curves[i]); } + pari_free(curves); + pari_free(primes); curve_free(&curve); return 0; diff --git a/src/io/cli.c b/src/io/cli.c index 43d75f5..d00a0c5 100644 --- a/src/io/cli.c +++ b/src/io/cli.c @@ -6,8 +6,8 @@ #include <string.h> char doc[] = - "ecgen, tool for generating Elliptic curve domain parameters.\v(C) 2017 " - "Eastern Seaboard Phishing Authority"; + "ecgen, tool for generating Elliptic curve domain parameters.\v(C) 2017 " + "Eastern Seaboard Phishing Authority"; char args_doc[] = "bits"; enum opt_keys { @@ -85,8 +85,8 @@ error_t parse_opt(int key, char *arg, struct argp_state *state) { // ANSI X9.62 specifies seed as at least 160 bits in length. if (strlen(arg) < 20) { argp_failure( - state, 1, 0, - "SEED must be at least 160 bits(20 characters)."); + state, 1, 0, + "SEED must be at least 160 bits(20 characters)."); } cfg->seed = arg; } @@ -111,22 +111,22 @@ error_t parse_opt(int key, char *arg, struct argp_state *state) { // Only one field if (!cfg->prime_field && !cfg->binary_field) { argp_failure(state, 1, 0, - "Specify field type, prime or binary, with --fp / " - "--f2m(but not both)."); + "Specify field type, prime or binary, with --fp / " + "--f2m(but not both)."); } - // Invalid is not prime or seed or exhaustive by definition. - if (cfg->invalid && (cfg->prime || cfg->from_seed || cfg->random)) { - // not seed, not prime, not exhaustive + // Invalid is not prime or seed by definition. + if (cfg->invalid && (cfg->prime || cfg->from_seed)) { + // not seed, not prime argp_failure(state, 1, 0, - "Invalid curve generation can not generate curves " - "from seed, exhaustive or prime order."); + "Invalid curve generation can not generate curves " + "from seed, exhaustive or prime order."); } if (cfg->cm && (cfg->prime || cfg->from_seed || cfg->invalid)) { argp_failure(state, 1, 0, - "Fixed order curve generation can not generate " - "curves from seed, or invalid curves. Prime order " - "also doesn't make sense if the given one isn't " - "prime."); + "Fixed order curve generation can not generate " + "curves from seed, or invalid curves. Prime order " + "also doesn't make sense if the given one isn't " + "prime."); } break; case ARGP_KEY_NO_ARGS: diff --git a/src/io/input.c b/src/io/input.c index 7d6b614..184924f 100644 --- a/src/io/input.c +++ b/src/io/input.c @@ -6,8 +6,9 @@ #include <parson/parson.h> FILE *in; +int delim; -GEN fread_i(FILE *stream, const char *prompt, long bits, int delim) { +GEN fread_i(FILE *stream, const char *prompt, long bits) { if (prompt) { printf("%s ", prompt); } @@ -25,7 +26,7 @@ GEN fread_i(FILE *stream, const char *prompt, long bits, int delim) { // check bitsize here GEN size = int2n(bits); - if (cmpii(in, size)) { + if (cmpii(in, size) <= 0) { return gerepileupto(ltop, in); } else { fprintf(stderr, "Number too big(> %ld bits).\n", bits); @@ -33,8 +34,8 @@ GEN fread_i(FILE *stream, const char *prompt, long bits, int delim) { } } -GEN fread_prime(FILE *stream, const char *prompt, long bits, int delim) { - GEN read = fread_i(stream, prompt, bits, delim); +GEN fread_prime(FILE *stream, const char *prompt, long bits) { + GEN read = fread_i(stream, prompt, bits); if (equalii(read, gen_m1)) { return read; } else { @@ -47,15 +48,15 @@ GEN fread_prime(FILE *stream, const char *prompt, long bits, int delim) { } } -GEN fread_int(FILE *stream, const char *prompt, long bits, int delim) { - return fread_i(stream, prompt, bits, delim); +GEN fread_int(FILE *stream, const char *prompt, long bits) { + return fread_i(stream, prompt, bits); } -GEN fread_short(FILE *stream, const char *prompt, int delim) { - return fread_i(stream, prompt, 16, delim); +GEN fread_short(FILE *stream, const char *prompt) { + return fread_i(stream, prompt, 16); } -GEN fread_string(FILE *stream, const char *prompt, int delim) { +GEN fread_string(FILE *stream, const char *prompt) { if (prompt) { printf("%s ", prompt); } @@ -74,41 +75,43 @@ GEN fread_string(FILE *stream, const char *prompt, int delim) { return result; } -GEN fread_param(param_t param, FILE *stream, const char *prompt, long bits, - int delim) { +GEN fread_param(param_t param, FILE *stream, const char *prompt, long bits) { switch (param) { case PARAM_PRIME: - return fread_prime(stream, prompt, bits, delim); + return fread_prime(stream, prompt, bits); case PARAM_INT: - return fread_int(stream, prompt, bits, delim); + return fread_int(stream, prompt, bits); case PARAM_SHORT: - return fread_short(stream, prompt, delim); + return fread_short(stream, prompt); case PARAM_STRING: - return fread_string(stream, prompt, delim); + return fread_string(stream, prompt); } return gen_m1; } -GEN read_param(param_t param, const char *prompt, long bits, int delim) { - return fread_param(param, stdin, prompt, bits, delim); +GEN read_param(param_t param, const char *prompt, long bits) { + return fread_param(param, stdin, prompt, bits); } -FILE *input_open(const char *input) { +void input_init(const char *input) { json_set_allocation_functions(pari_malloc, pari_free); + if (input) { - FILE *in = fopen(input, "r"); + in = fopen(input, "r"); + delim = ','; if (!in) { // fallback to stdin or quit? in = stdin; + delim = '\n'; perror("Failed to open input file."); } - return in; } else { - return stdin; + in = stdin; + delim = '\n'; } } -void input_close(FILE *in) { +void input_quit() { if (in != NULL && in != stdout) { fclose(in); } diff --git a/src/io/input.h b/src/io/input.h index f403661..9cdd008 100644 --- a/src/io/input.h +++ b/src/io/input.h @@ -19,41 +19,37 @@ typedef enum PARAM { * @param stream * @param prompt * @param bits - * @param delim * @return */ -GEN fread_prime(FILE *stream, const char *prompt, long bits, int delim); +GEN fread_prime(FILE *stream, const char *prompt, long bits); /** * * @param stream * @param prompt * @param bits - * @param delim * @return */ -GEN fread_int(FILE *stream, const char *prompt, long bits, int delim); +GEN fread_int(FILE *stream, const char *prompt, long bits); /** * * @param stream * @param prompt - * @param delim * @return */ -GEN fread_short(FILE *stream, const char *prompt, int delim); +GEN fread_short(FILE *stream, const char *prompt); -GEN fread_string(FILE *stream, const char *prompt, int delim); +GEN fread_string(FILE *stream, const char *prompt); -GEN fread_param(param_t param, FILE *stream, const char *prompt, long bits, - int delim); +GEN fread_param(param_t param, FILE *stream, const char *prompt, long bits); -GEN read_param(param_t param, const char *prompt, long bits, int delim); +GEN read_param(param_t param, const char *prompt, long bits); extern FILE *in; -FILE *input_open(const char *input); +void input_init(const char *input); -void input_close(FILE *in); +void input_quit(); #endif // ECGEN_INPUT_H diff --git a/src/io/output.c b/src/io/output.c index 141360e..31e9f4c 100644 --- a/src/io/output.c +++ b/src/io/output.c @@ -43,7 +43,7 @@ char *output_scsv(const char *format, char delim, GEN vector) { void output_csv(FILE *out, const char *format, char delim, GEN vector) { char *string = output_scsv(format, delim, vector); - fprintf(out, "%s", string); + fprintf(out, "%s\n", string); free(string); } @@ -51,23 +51,22 @@ char *output_sjson(GEN vector) {} void output_json(FILE *out, GEN vector) {} -FILE *output_open(const char *output, bool append) { +void output_init(const char *output, bool append) { json_set_allocation_functions(pari_malloc, pari_free); if (output) { - FILE *out = fopen(output, append ? "a" : "w"); + out = fopen(output, append ? "a" : "w"); if (!out) { // fallback to stdout and output err out = stdout; perror("Failed to open output file."); } - return out; } else { - return stdout; + out = stdout; } } -void output_close(FILE *out) { +void output_quit() { if (out != NULL && out != stdout) { fclose(out); } diff --git a/src/io/output.h b/src/io/output.h index 99b92b7..35d2178 100644 --- a/src/io/output.h +++ b/src/io/output.h @@ -42,8 +42,8 @@ void output_json(FILE *out, GEN vector); extern FILE *out; -FILE *output_open(const char *output, bool append); +void output_init(const char *output, bool append); -void output_close(FILE *out); +void output_quit(); #endif // ECGEN_OUTPUT_H diff --git a/src/math/curve.c b/src/math/curve.c index e9d1364..57f46e6 100644 --- a/src/math/curve.c +++ b/src/math/curve.c @@ -71,7 +71,7 @@ int curve_seed(curve_t *curve, config_t *config, ...) { return curve_seed_f2m(curve, config); default: pari_err_TYPE("curve_seed", curve->field); - return 0; /* NOT REACHABLE */ + return INT_MIN; /* NOT REACHABLE */ } } diff --git a/src/math/curve.h b/src/math/curve.h index d1688ff..1a8fb0b 100644 --- a/src/math/curve.h +++ b/src/math/curve.h @@ -10,6 +10,8 @@ #include "types.h" /** + * Creates a curve GEN in curve_t curve from field, a and b. + * Always succeeds. * * @param curve * @param config @@ -18,6 +20,8 @@ int curve_init(curve_t *curve, config_t *config, ...); /** + * Creates a curve GEN in curve_t curve from field, a and b. + * Succeeds if a curve exists(non-zero discriminant). * * @param curve * @param config @@ -26,14 +30,9 @@ int curve_init(curve_t *curve, config_t *config, ...); int curve_nonzero(curve_t *curve, config_t *config, ...); /** - * - * @param curve - * @param config - * @return - */ -int curve_prime(curve_t *curve, config_t *config, ...); - -/** + * Creates a curve GEN in curve_t curve from field, a and b. Using the ANSI + * X9.62 verifiably random algorithm. + * Succeeds if a curve exists(non-zero discriminant). * * @param curve * @param config @@ -43,7 +42,7 @@ int curve_seed(curve_t *curve, config_t *config, ...); /** * @param curve - * @return + * @return a t_VEC of curve parameters: field,a,b,order */ GEN curve_params(curve_t *curve); @@ -54,8 +53,8 @@ GEN curve_params(curve_t *curve); curve_t *curve_new(); /** - * - * @param curve + * Free a curve_t along with it's seed_t and point_ts. + * @param curve to free */ void curve_free(curve_t **curve); diff --git a/src/math/equation.c b/src/math/equation.c index b699b9a..4e44747 100644 --- a/src/math/equation.c +++ b/src/math/equation.c @@ -19,7 +19,7 @@ int a_random(curve_t *curve, config_t *config, ...) { } int a_input(curve_t *curve, config_t *config, ...) { - curve->a = fread_int(in, "a: ", config->bits, '\n'); + curve->a = fread_int(in, "a:", config->bits); return 1; } @@ -41,7 +41,7 @@ int b_random(curve_t *curve, config_t *config, ...) { } int b_input(curve_t *curve, config_t *config, ...) { - curve->b = fread_int(in, "a: ", config->bits, '\n'); + curve->b = fread_int(in, "b:", config->bits); return 1; } diff --git a/src/math/field.c b/src/math/field.c index a4b038e..4d62c73 100644 --- a/src/math/field.c +++ b/src/math/field.c @@ -3,6 +3,7 @@ * Copyright (C) 2017 J08nY */ #include "field.h" +#include "io/input.h" #include "poly.h" #include "random.h" @@ -27,21 +28,68 @@ int field_random(curve_t *curve, config_t *config, ...) { curve->field = field_binaryr(config->bits); return 1; default: - return 0; /* NOT REACHABLE */ + return INT_MIN; /* NOT REACHABLE */ } } int field_input(curve_t *curve, config_t *config, ...) { - return INT_MIN; // NOT IMPLEMENTED + pari_sp ltop = avma; + switch (config->field) { + case FIELD_PRIME: { + GEN p = fread_prime(in, "p:", config->bits); + if (equalii(p, gen_m1)) { + avma = ltop; + return 0; + } + curve->field = p; + return 1; + } + case FIELD_BINARY: { + GEN e1 = fread_short(in, "e1:"); + if (equalii(e1, gen_m1)) { + avma = ltop; + return 0; + } + GEN e2 = fread_short(in, "e2:"); + if (equalii(e2, gen_m1)) { + avma = ltop; + return 0; + } + GEN e3 = fread_short(in, "e3:"); + if (equalii(e3, gen_m1)) { + avma = ltop; + return 0; + } + + if (isintzero(e1) && isintzero(e2) && isintzero(e3)) { + fprintf(stderr, "At least one exponent must be nonzero.\n"); + avma = ltop; + return 0; + } + + GEN v = gtovec0(gen_0, config->bits + 1); + gel(v, config->bits + 1) = gen_1; + if (gsigne(e1) == 1) gel(v, itos(e1) + 1) = gen_1; + if (gsigne(e2) == 1) gel(v, itos(e2) + 1) = gen_1; + if (gsigne(e3) == 1) gel(v, itos(e3) + 1) = gen_1; + gel(v, 1) = gen_1; + + GEN poly = gmul(gtopolyrev(v, -1), gmodulss(1, 2)); + + GEN field = gerepilecopy(ltop, ffgen(poly, -1)); + curve->field = field; + return 1; + } + default: + return INT_MIN; /* NOT REACHABLE */ + } } GEN field_params(GEN field) { pari_sp ltop = avma; if (typ(field) == t_INT) { - GEN p3 = cgetg(2, t_VEC); - gel(p3, 1) = gcopy(field); - return gerepilecopy(ltop, p3); + return gtovec(field); } GEN out = gtovec0(gen_0, 3); @@ -50,7 +98,7 @@ GEN field_params(GEN field) { long l2 = glength(member_mod(field)) - 2; { pari_sp btop = avma; - for (long i = 0; i <= l2; ++i) { + for (long i = l2; i > 0; --i) { GEN c = polcoeff0(member_mod(field), i, -1); if (cmpis(c, 0) != 0) { gel(out, j) = stoi(i); diff --git a/src/math/order.h b/src/math/order.h index 4af994a..1f0baa2 100644 --- a/src/math/order.h +++ b/src/math/order.h @@ -25,4 +25,4 @@ int order_init(curve_t *curve, config_t *cfg, ...); */ int order_prime(curve_t *curve, config_t *cfg, ...); -#endif //ECGEN_ORDER_H +#endif // ECGEN_ORDER_H diff --git a/src/math/point.c b/src/math/point.c index a5a1c69..ebe6288 100644 --- a/src/math/point.c +++ b/src/math/point.c @@ -4,9 +4,28 @@ */ #include "point.h" -point_t *gerepile_point(pari_sp ltop, point_t *point) { - if (point) { - gerepileall(ltop, 2, &point->point, &point->order); +point_t *point_new() {} + +point_t **points_new(size_t num) {} + +void point_free(point_t **point) {} + +void points_free(point_t ***point) {} + +int point_random(curve_t *curve, config_t *config, ...) {} + +int points_random(curve_t *curve, config_t *config, ...) { + va_list arg; + va_start(arg, config); + size_t npoints = va_arg(arg, size_t); + va_end(arg); + + curve->points = points_new(npoints); + curve->npoints = npoints; + for (size_t i = 0; i < npoints; ++i) { } - return point; -}
\ No newline at end of file +} + +int points_prime(curve_t *curve, config_t *config, ...) {} + +int points_generators(curve_t *curve, config_t *config, ...) {}
\ No newline at end of file diff --git a/src/math/point.h b/src/math/point.h index 3b69144..064dadc 100644 --- a/src/math/point.h +++ b/src/math/point.h @@ -7,7 +7,47 @@ #include <pari/pari.h> #include "types.h" +/** + * + * @return + */ +point_t *point_new(); + +/** + * + * @param num + * @return + */ +point_t **points_new(size_t num); + +/** + * + * @param point + */ +void point_free(point_t **point); -point_t *gerepile_point(pari_sp ltop, point_t *point); +/** + * + * @param point + */ +void points_free(point_t ***point); + +/** + * + * @param curve + * @param config + * @param ... + * @return + */ +int point_random(curve_t *curve, config_t *config, ...); + +/** + * + * @param curve + * @param config + * @param ... + * @return + */ +int points_random(curve_t *curve, config_t *config, ...); #endif // ECGEN_POINT_H diff --git a/src/math/random.c b/src/math/random.c index 319ed3c..37fd882 100644 --- a/src/math/random.c +++ b/src/math/random.c @@ -10,7 +10,7 @@ bool random_init() { // Try urandom first FILE *rand = fopen("/dev/urandom", "rb"); if (rand) { - fread(&seed, sizeof(char), sizeof(pari_ulong), rand); + fread(&seed, 1, sizeof(pari_ulong), rand); fclose(rand); } // Try worse methods later |
