aboutsummaryrefslogtreecommitdiff
path: root/src/invalid
diff options
context:
space:
mode:
authorJ08nY2017-05-07 18:06:53 +0200
committerJ08nY2017-05-07 18:06:53 +0200
commit2c6bfa342ac85cd1ec5265b217d7cb33afd91e69 (patch)
tree0b3c371c7c033b713f5c8f57e774b4f56b97e41e /src/invalid
parent2fe84534d7cfa5a2aebd8877222871b54e7c80c5 (diff)
downloadecgen-2c6bfa342ac85cd1ec5265b217d7cb33afd91e69.tar.gz
ecgen-2c6bfa342ac85cd1ec5265b217d7cb33afd91e69.tar.zst
ecgen-2c6bfa342ac85cd1ec5265b217d7cb33afd91e69.zip
Fixed unrolls / unique generator curve generaton
- Also added some tests to catch some regressions like this early - Fixed double free in gens, also some funky stuff with gunclone and obj_free in curve_free
Diffstat (limited to 'src/invalid')
-rw-r--r--src/invalid/invalid.c15
-rw-r--r--src/invalid/invalid_thread.c21
2 files changed, 24 insertions, 12 deletions
diff --git a/src/invalid/invalid.c b/src/invalid/invalid.c
index 18224e8..122bf4f 100644
--- a/src/invalid/invalid.c
+++ b/src/invalid/invalid.c
@@ -5,7 +5,6 @@
#include "invalid.h"
#include "exhaustive/exhaustive.h"
#include "invalid_thread.h"
-#include "io/config.h"
#include "io/output.h"
#include "math/curve.h"
#include "math/equation.h"
@@ -31,6 +30,7 @@ static void invalid_original_ginit(gen_t *generators, const config_t *cfg) {
}
static void invalid_invalid_ginit(gen_t *generators, const config_t *cfg) {
+ generators[OFFSET_SEED] = &gen_skip;
generators[OFFSET_FIELD] = &gen_skip;
generators[OFFSET_A] = &gen_skip;
generators[OFFSET_B] = &b_random;
@@ -121,6 +121,14 @@ static size_t invalid_curves(curve_t *curve, config_t *cfg, pari_ulong *primes,
}
if (total > 0) {
+ if (!exhaustive_gen_retry(invalid, cfg, invalid_gen, NULL, unrolls,
+ OFFSET_GENERATORS, OFFSET_POINTS, 1)) {
+ curve_unroll(invalid, cfg, avma,
+ btop); // necessary to free the ellinit
+ avma = btop;
+ continue;
+ }
+
// only pass small primes that divide the curve order and those
// where we dont have a curve yet.
// this is passed to points_trial which uses trial division to find
@@ -142,7 +150,7 @@ static size_t invalid_curves(curve_t *curve, config_t *cfg, pari_ulong *primes,
// generate prime order points, this is expensive (order needs to be
// factorised, so only do it if we want the curve)
exhaustive_gen(invalid, cfg, invalid_gen, invalid_argss, unrolls,
- OFFSET_GENERATORS, OFFSET_END);
+ OFFSET_POINTS, OFFSET_END);
size_t count = 0;
for (size_t i = nprimes; i-- > 0;) {
@@ -184,7 +192,8 @@ static size_t invalid_curves(curve_t *curve, config_t *cfg, pari_ulong *primes,
// primes from range divided order. Thus remove it
// like it never existed.
- obj_free(invalid->curve); // necessary to free the ellinit
+ curve_unroll(invalid, cfg, avma,
+ btop); // necessary to free the ellinit
avma = btop;
}
}
diff --git a/src/invalid/invalid_thread.c b/src/invalid/invalid_thread.c
index 1539714..66aca66 100644
--- a/src/invalid/invalid_thread.c
+++ b/src/invalid/invalid_thread.c
@@ -30,8 +30,12 @@ void *invalid_thread(void *arg) {
ndivides++;
}
}
+
debug("ndivides = %lu\n", ndivides);
- if (ndivides > 0) {
+ if (ndivides > 0 &&
+ exhaustive_gen_retry(invalid, thread->cfg, thread->gens,
+ invalid_argss, thread->unrolls,
+ OFFSET_GENERATORS, OFFSET_POINTS, 1)) {
pthread_mutex_lock(thread->mutex_state);
size_t nfree = 0;
// can be up to ndivides, but also lower...
@@ -52,8 +56,8 @@ void *invalid_thread(void *arg) {
arg_t prime_divisors = {primes, nprimes};
invalid_argss[OFFSET_POINTS] = &prime_divisors;
exhaustive_gen(invalid, thread->cfg, thread->gens,
- invalid_argss, thread->unrolls,
- OFFSET_GENERATORS, OFFSET_END);
+ invalid_argss, thread->unrolls, OFFSET_POINTS,
+ OFFSET_END);
pthread_mutex_lock(thread->mutex_state);
size_t count = 0;
@@ -76,14 +80,13 @@ void *invalid_thread(void *arg) {
invalid = curve_new();
invalid->field = gcopy(thread->original_curve->field);
invalid->a = gcopy(thread->original_curve->a);
- } else {
- curve_unroll(invalid, thread->cfg, avma, btop);
- avma = btop;
+ continue;
}
- } else {
- curve_unroll(invalid, thread->cfg, avma, btop);
- avma = btop;
}
+
+ // We were unsuccessful for some reasol, unroll
+ curve_unroll(invalid, thread->cfg, avma, btop);
+ avma = btop;
}
curve_free(&invalid);