aboutsummaryrefslogtreecommitdiff
path: root/src/math
diff options
context:
space:
mode:
authorJ08nY2017-02-16 21:31:50 +0100
committerJ08nY2017-02-16 21:31:50 +0100
commit7ae0d913d7bbfb286aaa9a5c9984e9bd7eb81df2 (patch)
treeb0f2d97310b9d0a3e4ba2e0a1cfbcf31d608383e /src/math
parent5d9d12811441930169b0517318dcf21c51b72e2d (diff)
downloadecgen-7ae0d913d7bbfb286aaa9a5c9984e9bd7eb81df2.tar.gz
ecgen-7ae0d913d7bbfb286aaa9a5c9984e9bd7eb81df2.tar.zst
ecgen-7ae0d913d7bbfb286aaa9a5c9984e9bd7eb81df2.zip
Optimized invalid curve generation, added optional args to gen_t
- Optimized invalid curve generation - Invalid curve generation for secp256r1 now takes around 90minutes instead of 5hours as before - Optimized prime point generation(if only some small prime order points are needed -> points_primet) - Added a_once and b_once that prompt for parameter input and then set the input parameter repeatedly - Added optional args to gen_t functions - Integer input now ignores whitespace and doesnt errorneously prompt stdout when reading from file - Specified C standard(C11) + feature macros in code.
Diffstat (limited to 'src/math')
-rw-r--r--src/math/arg.c6
-rw-r--r--src/math/arg.h8
-rw-r--r--src/math/curve.c27
-rw-r--r--src/math/curve.h12
-rw-r--r--src/math/equation.c84
-rw-r--r--src/math/equation.h58
-rw-r--r--src/math/field.c22
-rw-r--r--src/math/field.h8
-rw-r--r--src/math/order.c6
-rw-r--r--src/math/order.h8
-rw-r--r--src/math/point.c82
-rw-r--r--src/math/point.h41
-rw-r--r--src/math/random.c3
-rw-r--r--src/math/types.c2
-rw-r--r--src/math/types.h9
15 files changed, 268 insertions, 108 deletions
diff --git a/src/math/arg.c b/src/math/arg.c
new file mode 100644
index 0000000..1a0d1ca
--- /dev/null
+++ b/src/math/arg.c
@@ -0,0 +1,6 @@
+/*
+ * ecgen, tool for generating Elliptic curve domain parameters
+ * Copyright (C) 2017 J08nY
+ */
+#include "arg.h"
+#include "types.h"
diff --git a/src/math/arg.h b/src/math/arg.h
new file mode 100644
index 0000000..65ea311
--- /dev/null
+++ b/src/math/arg.h
@@ -0,0 +1,8 @@
+/*
+ * ecgen, tool for generating Elliptic curve domain parameters
+ * Copyright (C) 2017 J08nY
+ */
+#ifndef ECGEN_ARG_H
+#define ECGEN_ARG_H
+
+#endif // ECGEN_ARG_H
diff --git a/src/math/curve.c b/src/math/curve.c
index 42844ff..3892704 100644
--- a/src/math/curve.c
+++ b/src/math/curve.c
@@ -35,18 +35,13 @@ curve_t *curve_copy(curve_t *src, curve_t *dest) {
void curve_free(curve_t **curve) {
if (*curve) {
seed_free(&(*curve)->seed);
- if ((*curve)->points) {
- for (size_t i = 0; i < (*curve)->npoints; ++i) {
- point_free(&(*curve)->points[i]);
- }
- points_free(&(*curve)->points);
- }
+ points_free_deep(&(*curve)->points, (*curve)->npoints);
pari_free(*curve);
*curve = NULL;
}
}
-int curve_init(curve_t *curve, config_t *config, ...) {
+int curve_init(curve_t *curve, config_t *config, arg_t *args) {
pari_sp ltop = avma;
GEN v = gen_0;
switch (typ(curve->field)) {
@@ -69,9 +64,9 @@ int curve_init(curve_t *curve, config_t *config, ...) {
return 1;
}
-int curve_nonzero(curve_t *curve, config_t *config, ...) {
+int curve_nonzero(curve_t *curve, config_t *config, arg_t *args) {
pari_sp ltop = avma;
- curve_init(curve, config);
+ curve_init(curve, config, args);
if (gequal0(ell_get_disc(curve->curve))) {
avma = ltop;
return -3;
@@ -80,22 +75,22 @@ int curve_nonzero(curve_t *curve, config_t *config, ...) {
}
}
-int curve_seed_fp(curve_t *curve, config_t *config, ...) {
- //TODO implement
+int curve_seed_fp(curve_t *curve, config_t *config, arg_t *args) {
+ // TODO implement
return INT_MIN;
}
-int curve_seed_f2m(curve_t *curve, config_t *config, ...) {
- //TODO implement
+int curve_seed_f2m(curve_t *curve, config_t *config, arg_t *args) {
+ // TODO implement
return INT_MIN;
}
-int curve_seed(curve_t *curve, config_t *config, ...) {
+int curve_seed(curve_t *curve, config_t *config, arg_t *args) {
switch (typ(curve->field)) {
case t_INT:
- return curve_seed_fp(curve, config);
+ return curve_seed_fp(curve, config, args);
case t_FFELT:
- return curve_seed_f2m(curve, config);
+ return curve_seed_f2m(curve, config, args);
default:
pari_err_TYPE("curve_seed", curve->field);
return INT_MIN; /* NOT REACHABLE */
diff --git a/src/math/curve.h b/src/math/curve.h
index 425d9a6..cc241b4 100644
--- a/src/math/curve.h
+++ b/src/math/curve.h
@@ -19,10 +19,10 @@
*
* @param curve
* @param config
- * @param ... unused
+ * @param args unused
* @return state diff
*/
-int curve_init(curve_t *curve, config_t *config, ...);
+int curve_init(curve_t *curve, config_t *config, arg_t *args);
/**
* GENERATOR(gen_t)
@@ -31,10 +31,10 @@ int curve_init(curve_t *curve, config_t *config, ...);
*
* @param curve
* @param config
- * @param ... unused
+ * @param args unused
* @return state diff
*/
-int curve_nonzero(curve_t *curve, config_t *config, ...);
+int curve_nonzero(curve_t *curve, config_t *config, arg_t *args);
/**
* GENERATOR(gen_t)
@@ -44,10 +44,10 @@ int curve_nonzero(curve_t *curve, config_t *config, ...);
*
* @param curve
* @param config
- * @param ... unused
+ * @param args unused
* @return state diff
*/
-int curve_seed(curve_t *curve, config_t *config, ...);
+int curve_seed(curve_t *curve, config_t *config, arg_t *args);
/**
* Serializes curve parameters into a t_VEC:
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;
}
diff --git a/src/math/equation.h b/src/math/equation.h
index 76b5e06..4e0202e 100644
--- a/src/math/equation.h
+++ b/src/math/equation.h
@@ -19,10 +19,10 @@
*
* @param curve
* @param config
- * @param ...
+ * @param args
* @return state diff
*/
-int a_random(curve_t *curve, config_t *config, ...);
+int a_random(curve_t *curve, config_t *config, arg_t *args);
/**
* GENERATOR(gen_t)
@@ -30,10 +30,21 @@ int a_random(curve_t *curve, config_t *config, ...);
*
* @param curve
* @param config
- * @param ...
+ * @param args
* @return state diff
*/
-int a_input(curve_t *curve, config_t *config, ...);
+int a_input(curve_t *curve, config_t *config, arg_t *args);
+
+/**
+ * GENERATOR(gen_t)
+ * Creates a parameter by reading once from input.
+ *
+ * @param curve
+ * @param config
+ * @param args
+ * @return
+ */
+int a_once(curve_t *curve, config_t *config, arg_t *args);
/**
* GENERATOR(gen_t)
@@ -41,10 +52,10 @@ int a_input(curve_t *curve, config_t *config, ...);
*
* @param curve
* @param config
- * @param ...
+ * @param args
* @return state diff
*/
-int a_zero(curve_t *curve, config_t *config, ...);
+int a_zero(curve_t *curve, config_t *config, arg_t *args);
/**
* GENERATOR(gen_t)
@@ -52,12 +63,12 @@ int a_zero(curve_t *curve, config_t *config, ...);
*
* @param curve
* @param config
- * @param ...
+ * @param args
* @return state diff
*/
-int a_one(curve_t *curve, config_t *config, ...);
+int a_one(curve_t *curve, config_t *config, arg_t *args);
-int a_seed(curve_t *curve, config_t *config, ...);
+int a_seed(curve_t *curve, config_t *config, arg_t *args);
/**
* GENERATOR(gen_t)
@@ -66,10 +77,10 @@ int a_seed(curve_t *curve, config_t *config, ...);
*
* @param curve
* @param config
- * @param ...
+ * @param args
* @return state diff
*/
-int b_random(curve_t *curve, config_t *config, ...);
+int b_random(curve_t *curve, config_t *config, arg_t *args);
/**
* GENERATOR(gen_t)
@@ -77,10 +88,21 @@ int b_random(curve_t *curve, config_t *config, ...);
*
* @param curve
* @param config
- * @param ...
+ * @param args
* @return state diff
*/
-int b_input(curve_t *curve, config_t *config, ...);
+int b_input(curve_t *curve, config_t *config, arg_t *args);
+
+/**
+ * GENERATOR(gen_t)
+ * Creates b parameter by reading once from input.
+ *
+ * @param curve
+ * @param config
+ * @param args
+ * @return
+ */
+int b_once(curve_t *curve, config_t *config, arg_t *args);
/**
* GENERATOR(gen_t)
@@ -88,10 +110,10 @@ int b_input(curve_t *curve, config_t *config, ...);
*
* @param curve
* @param config
- * @param ...
+ * @param args
* @return state diff
*/
-int b_zero(curve_t *curve, config_t *config, ...);
+int b_zero(curve_t *curve, config_t *config, arg_t *args);
/**
* GENERATOR(gen_t)
@@ -99,11 +121,11 @@ int b_zero(curve_t *curve, config_t *config, ...);
*
* @param curve
* @param config
- * @param ...
+ * @param args
* @return state diff
*/
-int b_one(curve_t *curve, config_t *config, ...);
+int b_one(curve_t *curve, config_t *config, arg_t *args);
-int b_seed(curve_t *curve, config_t *config, ...);
+int b_seed(curve_t *curve, config_t *config, arg_t *args);
#endif // ECGEN_EQUATION_H
diff --git a/src/math/field.c b/src/math/field.c
index cd35990..09b9a51 100644
--- a/src/math/field.c
+++ b/src/math/field.c
@@ -19,7 +19,7 @@ GEN field_binaryr(long bits) {
}
}
-int field_random(curve_t *curve, config_t *config, ...) {
+int field_random(curve_t *curve, config_t *config, arg_t *args) {
switch (config->field) {
case FIELD_PRIME:
curve->field = field_primer(config->bits);
@@ -32,11 +32,11 @@ int field_random(curve_t *curve, config_t *config, ...) {
}
}
-int field_input(curve_t *curve, config_t *config, ...) {
+int field_input(curve_t *curve, config_t *config, arg_t *args) {
pari_sp ltop = avma;
switch (config->field) {
case FIELD_PRIME: {
- GEN p = fread_prime(in, "p:", config->bits);
+ GEN p = input_prime("p:", config->bits);
if (equalii(p, gen_m1)) {
avma = ltop;
return 0;
@@ -45,17 +45,17 @@ int field_input(curve_t *curve, config_t *config, ...) {
return 1;
}
case FIELD_BINARY: {
- GEN e1 = fread_short(in, "e1:");
+ GEN e1 = input_short("e1:");
if (equalii(e1, gen_m1)) {
avma = ltop;
return 0;
}
- GEN e2 = fread_short(in, "e2:");
+ GEN e2 = input_short("e2:");
if (equalii(e2, gen_m1)) {
avma = ltop;
return 0;
}
- GEN e3 = fread_short(in, "e3:");
+ GEN e3 = input_short("e3:");
if (equalii(e3, gen_m1)) {
avma = ltop;
return 0;
@@ -75,7 +75,7 @@ int field_input(curve_t *curve, config_t *config, ...) {
gel(v, 1) = gen_1;
GEN poly = gmul(gtopolyrev(v, -1), gmodulss(1, 2));
- //TODO check irreducibility here
+ // TODO check irreducibility here
GEN field = gerepilecopy(ltop, ffgen(poly, -1));
curve->field = field;
@@ -93,10 +93,10 @@ GEN field_params(GEN field) {
return gtovec(field);
}
- GEN out = gtovec0(gen_0, 3);
+ GEN out = gtovec0(gen_0, 4);
long j = 1;
- long l2 = glength(member_mod(field)) - 2;
+ long l2 = glength(member_mod(field)) - 1;
{
pari_sp btop = avma;
for (long i = l2; i > 0; --i) {
@@ -105,7 +105,7 @@ GEN field_params(GEN field) {
gel(out, j) = stoi(i);
j++;
}
- if (gc_needed(btop, 1)) gerepileall(btop, 3, &out, &c);
+ if (gc_needed(btop, 1)) gerepileall(btop, 2, &out, &c);
}
}
return gerepilecopy(ltop, out);
@@ -128,4 +128,4 @@ GEN field_elementi(GEN element) {
pari_err_TYPE("field_elementi", element);
return NULL; /* NOT REACHABLE */
}
-} \ No newline at end of file
+}
diff --git a/src/math/field.h b/src/math/field.h
index 13cb283..2d6d92a 100644
--- a/src/math/field.h
+++ b/src/math/field.h
@@ -18,10 +18,10 @@
*
* @param curve
* @param config
- * @param ... unused
+ * @param args unused
* @return state diff
*/
-int field_random(curve_t *curve, config_t *config, ...);
+int field_random(curve_t *curve, config_t *config, arg_t *args);
/**
* GENERATOR(gen_t)
@@ -31,10 +31,10 @@ int field_random(curve_t *curve, config_t *config, ...);
*
* @param curve
* @param config
- * @param ... unused
+ * @param args unused
* @return state diff
*/
-int field_input(curve_t *curve, config_t *config, ...);
+int field_input(curve_t *curve, config_t *config, arg_t *args);
/**
* Extract a field representation from a field.
diff --git a/src/math/order.c b/src/math/order.c
index 5e15279..39222b4 100644
--- a/src/math/order.c
+++ b/src/math/order.c
@@ -4,12 +4,12 @@
*/
#include "order.h"
-int order_init(curve_t *curve, config_t *cfg, ...) {
+int order_init(curve_t *curve, config_t *cfg, arg_t *args) {
curve->order = ellff_get_card(curve->curve);
return 1;
}
-int order_prime(curve_t *curve, config_t *cfg, ...) {
+int order_prime(curve_t *curve, config_t *cfg, arg_t *args) {
pari_sp ltop = avma;
curve->order = ellsea(curve->curve, 1);
if (gequal0(curve->order) || !(isprime(curve->order))) {
@@ -18,4 +18,4 @@ int order_prime(curve_t *curve, config_t *cfg, ...) {
} else {
return 1;
}
-} \ No newline at end of file
+}
diff --git a/src/math/order.h b/src/math/order.h
index 91b0ada..a1ed861 100644
--- a/src/math/order.h
+++ b/src/math/order.h
@@ -17,10 +17,10 @@
*
* @param curve
* @param cfg
- * @param ...
+ * @param args
* @return state diff
*/
-int order_init(curve_t *curve, config_t *cfg, ...);
+int order_init(curve_t *curve, config_t *cfg, arg_t *args);
/**
* GENERATOR(gen_t)
@@ -30,9 +30,9 @@ int order_init(curve_t *curve, config_t *cfg, ...);
*
* @param curve
* @param cfg
- * @param ...
+ * @param args
* @return state diff
*/
-int order_prime(curve_t *curve, config_t *cfg, ...);
+int order_prime(curve_t *curve, config_t *cfg, arg_t *args);
#endif // ECGEN_ORDER_H
diff --git a/src/math/point.c b/src/math/point.c
index 0bedc11..c2cd02a 100644
--- a/src/math/point.c
+++ b/src/math/point.c
@@ -52,7 +52,16 @@ void points_free(point_t ***points) {
}
}
-int point_random(curve_t *curve, config_t *config, ...) {
+void points_free_deep(point_t ***points, size_t npoints) {
+ if (*points) {
+ for (size_t i = 0; i < npoints; ++i) {
+ point_free(&(*points)[i]);
+ }
+ points_free(points);
+ }
+}
+
+int point_random(curve_t *curve, config_t *config, arg_t *args) {
point_t *p = point_new();
p->point = genrand(curve->curve);
p->order = ellorder(curve->curve, p->point, NULL);
@@ -63,11 +72,12 @@ int point_random(curve_t *curve, config_t *config, ...) {
return 1;
}
-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);
+int points_random(curve_t *curve, config_t *config, arg_t *args) {
+ if (!args) {
+ fprintf(stderr, "No args to an arged function. points_random");
+ return INT_MIN;
+ }
+ size_t npoints = *(size_t *)args->args;
curve->points = points_new(npoints);
curve->npoints = npoints;
@@ -80,7 +90,58 @@ int points_random(curve_t *curve, config_t *config, ...) {
return 1;
}
-int points_prime(curve_t *curve, config_t *config, ...) {
+/*
+ * GEN o = utoi(dprimes[i]);
+ GEN mul = ellmul(curve->curve, rand, o);
+
+ if (gequal0(mul)) {
+ printf("Success! %lu\n", npoints);
+ curve->points[i] = point_new();
+
+ gerepileall(btop, 2, &rand, &o);
+ curve->points[i]->point = rand;
+ curve->points[i]->order = o;
+ npoints++;
+ break;
+ }
+ */
+
+int points_primet(curve_t *curve, config_t *config, arg_t *args) {
+ // TODO stack code!!!
+ if (!args) {
+ fprintf(stderr, "No args to an arged function. points_primet");
+ return INT_MIN;
+ }
+ pari_ulong *primes = (pari_ulong *)args->args;
+ size_t nprimes = args->nargs;
+
+ curve->points = points_new(nprimes);
+ curve->npoints = nprimes;
+
+ size_t npoints = 0;
+ while (npoints < nprimes) {
+ GEN rand = genrand(curve->curve);
+ GEN ord = ellorder(curve->curve, rand, NULL);
+
+ for (long i = 0; i < nprimes; ++i) {
+ if (curve->points[i] == NULL && dvdis(ord, primes[i])) {
+ GEN p = stoi(primes[i]);
+ GEN mul = divii(ord, p);
+ GEN point = ellmul(curve->curve, rand, mul);
+
+ curve->points[i] = point_new();
+ curve->points[i]->point = point;
+ curve->points[i]->order = p;
+ npoints++;
+ }
+ }
+ }
+
+ return 1;
+}
+
+int points_prime(curve_t *curve, config_t *config, arg_t *args) {
+ // TODO stack code!!!
GEN factors = Z_factor(curve->order);
GEN primes = gel(factors, 1);
long nprimes = glength(primes);
@@ -94,7 +155,7 @@ int points_prime(curve_t *curve, config_t *config, ...) {
// ord(rand) = ord
for (long i = 1; i <= nprimes; ++i) {
- if (dvdii(ord, gel(primes, i)) && curve->points[i - 1] == NULL) {
+ if (curve->points[i - 1] == NULL && dvdii(ord, gel(primes, i))) {
// primes[i] divides ord
// mul = ord/primes[i]
GEN mul = divii(ord, gel(primes, i));
@@ -112,7 +173,8 @@ int points_prime(curve_t *curve, config_t *config, ...) {
return 1;
}
-int points_generators(curve_t *curve, config_t *config, ...) {
+int points_generators(curve_t *curve, config_t *config, arg_t *args) {
+ // TODO stack code!!!
GEN generators = ellff_get_gens(curve->curve);
long len = glength(generators);
curve->points = points_new((size_t)len);
@@ -126,4 +188,4 @@ int points_generators(curve_t *curve, config_t *config, ...) {
}
return 1;
-} \ No newline at end of file
+}
diff --git a/src/math/point.h b/src/math/point.h
index bd7d2dd..fe9aeb4 100644
--- a/src/math/point.h
+++ b/src/math/point.h
@@ -54,24 +54,49 @@ point_t **points_copy(point_t **src, point_t **dest, size_t num);
void points_free(point_t ***point);
/**
+ *
+ * @param points
+ * @param npoints
+ */
+void points_free_deep(point_t ***points, size_t npoints);
+
+/**
+ * GENERATOR(gen_t)
+ *
+ * @param curve
+ * @param config
+ * @param args unused
+ * @return state diff
+ */
+int point_random(curve_t *curve, config_t *config, arg_t *args);
+
+/**
* GENERATOR(gen_t)
*
* @param curve
* @param config
- * @param ... unused
+ * @param args size_t number of points to generate
* @return state diff
*/
-int point_random(curve_t *curve, config_t *config, ...);
+int points_random(curve_t *curve, config_t *config, arg_t *args);
/**
* GENERATOR(gen_t)
+ * Generates prime order points using trial division.
+ * The supplied arg is of format:
+ *
+ * pari_ulong *args->args primes
+ * size_t args->nargs length of primes
+ *
+ * Assumes the primes divide curve order, thus that points with all
+ * prime orders specified exist.
*
* @param curve
* @param config
- * @param ... size_t number of points to generate
+ * @param args
* @return state diff
*/
-int points_random(curve_t *curve, config_t *config, ...);
+int points_primet(curve_t *curve, config_t *config, arg_t *args);
/**
* GENERATOR(gen_t)
@@ -82,10 +107,10 @@ int points_random(curve_t *curve, config_t *config, ...);
*
* @param curve
* @param config
- * @param ...
+ * @param args
* @return state diff
*/
-int points_prime(curve_t *curve, config_t *config, ...);
+int points_prime(curve_t *curve, config_t *config, arg_t *args);
/**
* GENERATOR(gen_t)
@@ -94,9 +119,9 @@ int points_prime(curve_t *curve, config_t *config, ...);
*
* @param curve
* @param config
- * @param ... unused
+ * @param args unused
* @return state diff
*/
-int points_generators(curve_t *curve, config_t *config, ...);
+int points_generators(curve_t *curve, config_t *config, arg_t *args);
#endif // ECGEN_POINT_H
diff --git a/src/math/random.c b/src/math/random.c
index 44bdb27..94197fe 100644
--- a/src/math/random.c
+++ b/src/math/random.c
@@ -2,6 +2,7 @@
* ecgen, tool for generating Elliptic curve domain parameters
* Copyright (C) 2017 J08nY
*/
+#define _POSIX_C_SOURCE 200809L
#include "random.h"
#include <time.h>
@@ -57,4 +58,4 @@ GEN random_int(long bits) {
gel(range, 2) = powis(gen_2, bits);
return gerepilecopy(ltop, genrand(range));
-} \ No newline at end of file
+}
diff --git a/src/math/types.c b/src/math/types.c
index 958de7f..bf1bb5d 100644
--- a/src/math/types.c
+++ b/src/math/types.c
@@ -4,4 +4,4 @@
*/
#include "types.h"
-int gen_skip(curve_t *curve, config_t *config, ...) { return 1; }
+int gen_skip(curve_t *curve, config_t *config, arg_t *args) { return 1; }
diff --git a/src/math/types.h b/src/math/types.h
index 7124573..575f583 100644
--- a/src/math/types.h
+++ b/src/math/types.h
@@ -40,8 +40,13 @@ enum curve_offset {
OFFSET_END
};
-typedef int (*gen_t)(curve_t *, config_t *, ...);
+typedef struct arg_t {
+ void *args;
+ size_t nargs;
+} arg_t;
-int gen_skip(curve_t *curve, config_t *config, ...);
+typedef int (*gen_t)(curve_t *, config_t *, arg_t *args);
+
+int gen_skip(curve_t *curve, config_t *config, arg_t *args);
#endif // ECGEN_TYPES_H