aboutsummaryrefslogtreecommitdiff
path: root/src/math
diff options
context:
space:
mode:
authorJ08nY2017-04-10 23:47:46 +0200
committerJ08nY2017-04-10 23:56:03 +0200
commit2cf2eec873cb11f2f0767aac41da0f56dbd27cb9 (patch)
tree9b9a52548ccc7c9e54c500e4b587560ce18a017c /src/math
parentc1de68ff1e47dfbb1b85671e4fadcce1c49c8967 (diff)
downloadecgen-2cf2eec873cb11f2f0767aac41da0f56dbd27cb9.tar.gz
ecgen-2cf2eec873cb11f2f0767aac41da0f56dbd27cb9.tar.zst
ecgen-2cf2eec873cb11f2f0767aac41da0f56dbd27cb9.zip
Added unroll functions, to generalize going back in exhaustive generation
Diffstat (limited to 'src/math')
-rw-r--r--src/math/curve.c11
-rw-r--r--src/math/curve.h10
-rw-r--r--src/math/gens.c8
-rw-r--r--src/math/gens.h10
-rw-r--r--src/math/order.c4
-rw-r--r--src/math/point.c15
-rw-r--r--src/math/point.h11
-rw-r--r--src/math/types.c4
-rw-r--r--src/math/types.h16
9 files changed, 78 insertions, 11 deletions
diff --git a/src/math/curve.c b/src/math/curve.c
index ba21280..8e8e832 100644
--- a/src/math/curve.c
+++ b/src/math/curve.c
@@ -5,8 +5,8 @@
#include "curve.h"
#include "exhaustive/seed.h"
#include "field.h"
+#include "io/output.h"
#include "point.h"
-#include "types.h"
curve_t *curve_new(void) {
curve_t *curve = pari_malloc(sizeof(curve_t));
@@ -161,6 +161,15 @@ int curve_seed(curve_t *curve, const config_t *cfg, arg_t *args) {
}
}
+int curve_unroll(curve_t *curve, const config_t *cfg, pari_sp from,
+ pari_sp to) {
+ if (curve->curve) {
+ obj_free(curve->curve);
+ curve->curve = NULL;
+ }
+ return -1;
+}
+
GEN curve_params(const curve_t *curve) {
pari_sp ltop = avma;
diff --git a/src/math/curve.h b/src/math/curve.h
index 65dc4b7..d1aaf27 100644
--- a/src/math/curve.h
+++ b/src/math/curve.h
@@ -50,6 +50,16 @@ int curve_nonzero(curve_t *curve, const config_t *cfg, arg_t *args);
int curve_seed(curve_t *curve, const config_t *cfg, arg_t *args);
/**
+ *
+ * @param curve
+ * @param cfg
+ * @param from
+ * @param to
+ * @return
+ */
+int curve_unroll(curve_t *curve, const config_t *cfg, pari_sp from, pari_sp to);
+
+/**
* Serializes curve parameters into a t_VEC:
* - prime field:
* p,a,b,order,(point.x, point.y, point.order)*
diff --git a/src/math/gens.c b/src/math/gens.c
index f224386..ef47525 100644
--- a/src/math/gens.c
+++ b/src/math/gens.c
@@ -3,6 +3,7 @@
* Copyright (C) 2017 J08nY
*/
#include "gens.h"
+#include "io/output.h"
#include "point.h"
static int gens_put(curve_t *curve, GEN generators, long len) {
@@ -38,3 +39,10 @@ int gens_one(curve_t *curve, const config_t *cfg, arg_t *args) {
}
return gens_put(curve, generators, len);
}
+
+int gens_unroll(curve_t *curve, const config_t *cfg, pari_sp from, pari_sp to) {
+ if (curve->generators) {
+ points_free_deep(&curve->generators, curve->ngens);
+ }
+ return -1;
+}
diff --git a/src/math/gens.h b/src/math/gens.h
index 0160074..02bb3a9 100644
--- a/src/math/gens.h
+++ b/src/math/gens.h
@@ -29,4 +29,14 @@ int gens_any(curve_t *curve, const config_t *cfg, arg_t *args);
*/
int gens_one(curve_t *curve, const config_t *cfg, arg_t *args);
+/**
+ *
+ * @param curve
+ * @param cfg
+ * @param from
+ * @param to
+ * @return
+ */
+int gens_unroll(curve_t *curve, const config_t *cfg, pari_sp from, pari_sp to);
+
#endif // ECGEN_GENS_H
diff --git a/src/math/order.c b/src/math/order.c
index 17b7bca..7f90849 100644
--- a/src/math/order.c
+++ b/src/math/order.c
@@ -34,7 +34,7 @@ int order_smallfact(curve_t *curve, const config_t *cfg, arg_t *args) {
return -4;
} else {
curve->order = order;
- obj_insert_shallow(curve->curve, 1, curve->order);
+ obj_insert(curve->curve, 1, curve->order);
return 1;
}
}
@@ -47,7 +47,7 @@ int order_prime(curve_t *curve, const config_t *cfg, arg_t *args) {
return -4;
} else {
curve->order = order;
- obj_insert_shallow(curve->curve, 1, curve->order);
+ obj_insert(curve->curve, 1, curve->order);
return 1;
}
}
diff --git a/src/math/point.c b/src/math/point.c
index dc9cd4a..8b3dcef 100644
--- a/src/math/point.c
+++ b/src/math/point.c
@@ -3,7 +3,7 @@
* Copyright (C) 2017 J08nY
*/
#include "point.h"
-#include "types.h"
+#include "io/output.h"
point_t *point_new(void) {
point_t *point = pari_malloc(sizeof(point_t));
@@ -106,8 +106,6 @@ void points_free_deep(point_t ***points, size_t npoints) {
}
int point_random(curve_t *curve, const config_t *cfg, arg_t *args) {
- points_free_deep(&curve->points, curve->npoints);
-
point_t *p = point_new();
p->point = genrand(curve->curve);
p->order = ellorder(curve->curve, p->point, NULL);
@@ -123,7 +121,6 @@ int points_random(curve_t *curve, const config_t *cfg, arg_t *args) {
fprintf(stderr, "No args to an arged function. points_random");
return INT_MIN;
}
- points_free_deep(&curve->points, curve->npoints);
size_t npoints = *(size_t *)args->args;
@@ -160,7 +157,6 @@ int points_trial(curve_t *curve, const config_t *cfg, arg_t *args) {
fprintf(stderr, "No args to an arged function. points_trial");
return INT_MIN;
}
- points_free_deep(&curve->points, curve->npoints);
pari_ulong *primes = (pari_ulong *)args->args;
size_t nprimes = args->nargs;
@@ -195,7 +191,6 @@ int points_trial(curve_t *curve, const config_t *cfg, arg_t *args) {
int points_prime(curve_t *curve, const config_t *cfg, arg_t *args) {
// TODO stack code!!!
- points_free_deep(&curve->points, curve->npoints);
GEN factors = Z_factor(curve->order);
GEN primes = gel(factors, 1);
@@ -230,3 +225,11 @@ int points_prime(curve_t *curve, const config_t *cfg, arg_t *args) {
return 1;
}
+
+int points_unroll(curve_t *curve, const config_t *cfg, pari_sp from,
+ pari_sp to) {
+ if (curve->points) {
+ points_free_deep(&curve->points, curve->npoints);
+ }
+ return -1;
+}
diff --git a/src/math/point.h b/src/math/point.h
index 9eef8a4..ef6facf 100644
--- a/src/math/point.h
+++ b/src/math/point.h
@@ -159,4 +159,15 @@ int points_trial(curve_t *curve, const config_t *cfg, arg_t *args);
*/
int points_prime(curve_t *curve, const config_t *cfg, arg_t *args);
+/**
+ *
+ * @param curve
+ * @param cfg
+ * @param from
+ * @param to
+ * @return
+ */
+int points_unroll(curve_t *curve, const config_t *cfg, pari_sp from,
+ pari_sp to);
+
#endif // ECGEN_POINT_H
diff --git a/src/math/types.c b/src/math/types.c
index 49d8620..afd6542 100644
--- a/src/math/types.c
+++ b/src/math/types.c
@@ -5,3 +5,7 @@
#include "types.h"
int gen_skip(curve_t *curve, const config_t *cfg, arg_t *args) { return 1; }
+
+int unroll_skip(curve_t *curve, const config_t *cfg, pari_sp from, pari_sp to) {
+ return -1;
+}
diff --git a/src/math/types.h b/src/math/types.h
index 4dee9dd..3d2476a 100644
--- a/src/math/types.h
+++ b/src/math/types.h
@@ -46,14 +46,16 @@ typedef enum {
} offset_e;
typedef struct {
- void *args;
+ const void *args;
size_t nargs;
} arg_t;
typedef int (*gen_t)(curve_t *, const config_t *, arg_t *);
+typedef int (*unroll_t)(curve_t *, const config_t *, pari_sp, pari_sp);
+
/**
- * @brief
+ *
* @param curve
* @param config
* @param args
@@ -61,4 +63,14 @@ typedef int (*gen_t)(curve_t *, const config_t *, arg_t *);
*/
int gen_skip(curve_t *curve, const config_t *cfg, arg_t *args);
+/**
+ *
+ * @param curve
+ * @param cfg
+ * @param from
+ * @param to
+ * @return
+ */
+int unroll_skip(curve_t *curve, const config_t *cfg, pari_sp from, pari_sp to);
+
#endif // ECGEN_TYPES_H