diff options
Diffstat (limited to 'src/math/equation.c')
| -rw-r--r-- | src/math/equation.c | 84 |
1 files changed, 60 insertions, 24 deletions
diff --git a/src/math/equation.c b/src/math/equation.c index 47060ad..023b823 100644 --- a/src/math/equation.c +++ b/src/math/equation.c @@ -5,64 +5,100 @@ #include "equation.h" #include "io/input.h" -int eq_random(curve_t *curve, config_t *config, ...) { - int r = a_random(curve, config) + b_random(curve, config); - if (r == 2) { - return r; - } - return -1; -} - -int a_random(curve_t *curve, config_t *config, ...) { +int a_random(curve_t *curve, config_t *config, arg_t *args) { curve->a = genrand(curve->field); return 1; } -int a_input(curve_t *curve, config_t *config, ...) { - curve->a = fread_int(in, "a:", config->bits); - //TODO check if a is valid int here, if not repeat +int a_input(curve_t *curve, config_t *config, arg_t *args) { + pari_sp ltop = avma; + GEN inp = input_int("a:", config->bits); + if (gequalm1(inp)) { + avma = ltop; + return 0; + } + curve->a = gerepilecopy(ltop, inp); // TODO change a to a field element here?. a t_INTMOD or a t_FFELT. return 1; } -int a_zero(curve_t *curve, config_t *config, ...) { +static GEN a = NULL; + +int a_once(curve_t *curve, config_t *config, arg_t *args) { + if (a) { + curve->a = gcopy(a); + return 1; + } + + int inp = a_input(curve, config, args); + if (inp) { + a = gclone(curve->a); + } else { + return 0; + } + return 1; +} + +int a_zero(curve_t *curve, config_t *config, arg_t *args) { curve->a = gen_0; return 1; } -int a_one(curve_t *curve, config_t *config, ...) { +int a_one(curve_t *curve, config_t *config, arg_t *args) { curve->a = gen_1; return 1; } -int a_seed(curve_t *curve, config_t *config, ...) { - //TODO implement +int a_seed(curve_t *curve, config_t *config, arg_t *args) { + // TODO implement return INT_MIN; } -int b_random(curve_t *curve, config_t *config, ...) { +int b_random(curve_t *curve, config_t *config, arg_t *args) { curve->b = genrand(curve->field); return 1; } -int b_input(curve_t *curve, config_t *config, ...) { - curve->b = fread_int(in, "b:", config->bits); - //TODO check if a is valid int here, if not repeat +int b_input(curve_t *curve, config_t *config, arg_t *args) { + pari_sp ltop = avma; + GEN inp = input_int("b:", config->bits); + if (gequalm1(inp)) { + avma = ltop; + return 0; + } + curve->b = gerepilecopy(ltop, inp); // TODO change b to a field element here?. a t_INTMOD or a t_FFELT. return 1; } -int b_zero(curve_t *curve, config_t *config, ...) { +static GEN b = NULL; + +int b_once(curve_t *curve, config_t *config, arg_t *args) { + if (b) { + curve->b = gcopy(b); + return 1; + } + + int inp = b_input(curve, config, args); + if (inp) { + b = gclone(curve->b); + } else { + return 0; + } + return 1; +} + +int b_zero(curve_t *curve, config_t *config, arg_t *args) { curve->b = gen_0; return 1; } -int b_one(curve_t *curve, config_t *config, ...) { +int b_one(curve_t *curve, config_t *config, arg_t *args) { curve->b = gen_1; return 1; } -int b_seed(curve_t *curve, config_t *config, ...) { - //TODO implement +int b_seed(curve_t *curve, config_t *config, arg_t *args) { + // TODO implement return INT_MIN; } |
