diff options
| author | J08nY | 2017-03-01 11:33:16 +0100 |
|---|---|---|
| committer | J08nY | 2017-03-01 11:33:16 +0100 |
| commit | fdd2bbaf35270c5ab63bf3c601ab199f2092ab2c (patch) | |
| tree | 6bb9eec9d4608545ec6bc61056061f7e92d7c409 /src/math | |
| parent | 8c230aa00002b57d47160756a183d65fb895a7b4 (diff) | |
| download | ecgen-fdd2bbaf35270c5ab63bf3c601ab199f2092ab2c.tar.gz ecgen-fdd2bbaf35270c5ab63bf3c601ab199f2092ab2c.tar.zst ecgen-fdd2bbaf35270c5ab63bf3c601ab199f2092ab2c.zip | |
Added requested points type option + count option
Diffstat (limited to 'src/math')
| -rw-r--r-- | src/math/arg.c | 19 | ||||
| -rw-r--r-- | src/math/arg.h | 17 | ||||
| -rw-r--r-- | src/math/equation.c | 20 | ||||
| -rw-r--r-- | src/math/field.c | 19 | ||||
| -rw-r--r-- | src/math/field.h | 9 | ||||
| -rw-r--r-- | src/math/point.c | 4 | ||||
| -rw-r--r-- | src/math/point.h | 2 |
7 files changed, 78 insertions, 12 deletions
diff --git a/src/math/arg.c b/src/math/arg.c index 1a0d1ca..be3f92e 100644 --- a/src/math/arg.c +++ b/src/math/arg.c @@ -3,4 +3,21 @@ * Copyright (C) 2017 J08nY */ #include "arg.h" -#include "types.h" + + +arg_t *arg_new() { + arg_t *arg = pari_malloc(sizeof(arg_t)); + if (!arg) { + perror("Couldn't malloc."); + exit(1); + } + memset(arg, 0, sizeof(arg_t)); + return arg; +} + +void arg_free(arg_t **arg) { + if (*arg) { + pari_free(*arg); + *arg = NULL; + } +} diff --git a/src/math/arg.h b/src/math/arg.h index 65ea311..55e1b19 100644 --- a/src/math/arg.h +++ b/src/math/arg.h @@ -2,7 +2,24 @@ * ecgen, tool for generating Elliptic curve domain parameters * Copyright (C) 2017 J08nY */ +/** + * @file arg.h + */ #ifndef ECGEN_ARG_H #define ECGEN_ARG_H +#include "types.h" + +/** + * @brief + * @return + */ +arg_t *arg_new(); + +/** + * @brief + * @param arg + */ +void arg_free (arg_t **arg); + #endif // ECGEN_ARG_H diff --git a/src/math/equation.c b/src/math/equation.c index 2f57d03..45b849b 100644 --- a/src/math/equation.c +++ b/src/math/equation.c @@ -17,26 +17,28 @@ int a_input(curve_t *curve, config_t *config, arg_t *args) { avma = ltop; return 0; } - curve->a = gerepilecopy(ltop, inp); + curve->a = inp; // TODO change a to a field element here?. a t_INTMOD or a t_FFELT. return 1; } static GEN a = NULL; +static curve_t *curve_a = NULL; int a_once(curve_t *curve, config_t *config, arg_t *args) { - if (a) { + if (a && curve_a == curve) { curve->a = gcopy(a); return 1; } int inp = a_input(curve, config, args); - if (inp) { + if (inp > 0) { a = gclone(curve->a); + curve_a = curve; + return 1; } else { return 0; } - return 1; } int a_zero(curve_t *curve, config_t *config, arg_t *args) { @@ -66,26 +68,28 @@ int b_input(curve_t *curve, config_t *config, arg_t *args) { avma = ltop; return 0; } - curve->b = gerepilecopy(ltop, inp); + curve->b = inp; // TODO change b to a field element here?. a t_INTMOD or a t_FFELT. return 1; } static GEN b = NULL; +static curve_t* curve_b = NULL; int b_once(curve_t *curve, config_t *config, arg_t *args) { - if (b) { + if (b && curve_b == curve) { curve->b = gcopy(b); return 1; } int inp = b_input(curve, config, args); - if (inp) { + if (inp > 0) { b = gclone(curve->b); + curve_b = curve; + return 1; } else { return 0; } - return 1; } int b_zero(curve_t *curve, config_t *config, arg_t *args) { diff --git a/src/math/field.c b/src/math/field.c index 983aa09..2d6d358 100644 --- a/src/math/field.c +++ b/src/math/field.c @@ -90,6 +90,25 @@ int field_input(curve_t *curve, config_t *config, arg_t *args) { } } +static GEN field = NULL; +static curve_t *curve_field = NULL; + +int field_once(curve_t *curve, config_t *cfg, arg_t *args) { + if (field && curve_field == curve) { + curve->field = gcopy(field); + return 1; + } + + int inp = field_input(curve, cfg, args); + if (inp > 0) { + field = gclone(curve->field); + curve_field = curve; + return 1; + } else { + return 0; + } +} + GEN field_params(GEN field) { pari_sp ltop = avma; diff --git a/src/math/field.h b/src/math/field.h index 2d6d92a..0491a83 100644 --- a/src/math/field.h +++ b/src/math/field.h @@ -37,6 +37,15 @@ int field_random(curve_t *curve, config_t *config, arg_t *args); int field_input(curve_t *curve, config_t *config, arg_t *args); /** + * + * @param curve + * @param cfg + * @param args + * @return + */ +int field_once(curve_t *curve, config_t *cfg, arg_t *args); + +/** * Extract a field representation from a field. * - char(field) == 2: * returns the vector of powers of middle coefficients of the reduction diff --git a/src/math/point.c b/src/math/point.c index 8505954..6368c60 100644 --- a/src/math/point.c +++ b/src/math/point.c @@ -110,10 +110,10 @@ int points_random(curve_t *curve, config_t *config, arg_t *args) { } */ -int points_primet(curve_t *curve, config_t *config, arg_t *args) { +int points_trial(curve_t *curve, config_t *config, arg_t *args) { // TODO stack code!!! if (!args) { - fprintf(stderr, "No args to an arged function. points_primet"); + fprintf(stderr, "No args to an arged function. points_trial"); return INT_MIN; } points_free_deep(&curve->points, curve->npoints); diff --git a/src/math/point.h b/src/math/point.h index 9a0dd89..76f095a 100644 --- a/src/math/point.h +++ b/src/math/point.h @@ -96,7 +96,7 @@ int points_random(curve_t *curve, config_t *config, arg_t *args); * @param args * @return state diff */ -int points_primet(curve_t *curve, config_t *config, arg_t *args); +int points_trial(curve_t *curve, config_t *config, arg_t *args); /** * GENERATOR(gen_t) |
