aboutsummaryrefslogtreecommitdiff
path: root/src/exhaustive
diff options
context:
space:
mode:
authorJ08nY2017-05-19 18:00:00 +0200
committerJ08nY2017-05-19 18:00:00 +0200
commit132a768b5718cef1ff621380f2dcf21cd0553404 (patch)
tree77acc82153e0d0b73351258feaa504ce0d3bbd74 /src/exhaustive
parentbaa18605f6b9e6c6627d118a9ffc6c1c683ac12d (diff)
downloadecgen-132a768b5718cef1ff621380f2dcf21cd0553404.tar.gz
ecgen-132a768b5718cef1ff621380f2dcf21cd0553404.tar.zst
ecgen-132a768b5718cef1ff621380f2dcf21cd0553404.zip
Add debug logging with time, refactor allocation
Diffstat (limited to 'src/exhaustive')
-rw-r--r--src/exhaustive/anomalous.c18
-rw-r--r--src/exhaustive/exhaustive.c12
-rw-r--r--src/exhaustive/seed.c19
3 files changed, 15 insertions, 34 deletions
diff --git a/src/exhaustive/anomalous.c b/src/exhaustive/anomalous.c
index 93adf7d..44f8780 100644
--- a/src/exhaustive/anomalous.c
+++ b/src/exhaustive/anomalous.c
@@ -2,27 +2,15 @@
* ecgen, tool for generating Elliptic curve domain parameters
* Copyright (C) 2017 J08nY
*/
-/**
- * @file anomalous.c
- */
#include "anomalous.h"
-#include <io/config.h>
-#include <math/types.h>
+#include "util/memory.h"
static disc_t **disc_table;
void anomalous_init() {
- disc_table = pari_malloc(sizeof(disc_t *) * 5);
- if (!disc_table) {
- perror("Couldn't malloc.");
- exit(1);
- }
+ disc_table = try_calloc(sizeof(disc_t *) * 5);
for (int i = 0; i < 5; ++i) {
- disc_table[i] = pari_malloc(sizeof(disc_t));
- if (!disc_table[i]) {
- perror("Couldn't malloc.");
- exit(1);
- }
+ disc_table[i] = try_calloc(sizeof(disc_t));
}
/*
diff --git a/src/exhaustive/exhaustive.c b/src/exhaustive/exhaustive.c
index 55d2212..f361a13 100644
--- a/src/exhaustive/exhaustive.c
+++ b/src/exhaustive/exhaustive.c
@@ -3,7 +3,6 @@
* Copyright (C) 2017 J08nY
*/
#include "exhaustive.h"
-#include <math/types.h>
#include "anomalous.h"
#include "io/output.h"
#include "math/curve.h"
@@ -13,6 +12,7 @@
#include "math/order.h"
#include "math/point.h"
#include "seed.h"
+#include "util/memory.h"
static void exhaustive_ginit(gen_t *generators, const config_t *cfg) {
if (cfg->from_seed) {
@@ -93,13 +93,13 @@ static void exhaustive_ainit(arg_t **argss, const config_t *cfg) {
if (cfg->anomalous) {
arg_t *field_arg = arg_new();
arg_t *eq_arg = arg_new();
- size_t *i = pari_malloc(sizeof(size_t));
+ size_t *i = try_calloc(sizeof(size_t));
*i = 3;
field_arg->args = i;
field_arg->nargs = 1;
eq_arg->args = i;
eq_arg->nargs = 1;
- eq_arg->mallocd = i;
+ eq_arg->allocd = i;
argss[OFFSET_FIELD] = field_arg;
argss[OFFSET_B] = eq_arg;
}
@@ -222,7 +222,7 @@ static void exhaustive_quit(arg_t *argss[]) {
}
int exhaustive_do(config_t *cfg) {
- debug("# Starting Exhaustive method\n");
+ debug_log_start("Starting Exhaustive method");
gen_t generators[OFFSET_END] = {NULL};
arg_t *argss[OFFSET_END] = {NULL};
@@ -234,12 +234,15 @@ int exhaustive_do(config_t *cfg) {
output_o_begin(cfg);
for (unsigned long i = 0; i < cfg->count; ++i) {
+ debug_log_start("Generating new curve");
curve_t *curve = curve_new();
if (!exhaustive_gen(curve, cfg, generators, argss, unrolls, OFFSET_SEED,
OFFSET_END)) {
curve_free(&curve);
return 1;
}
+ debug_log_end("Generated new curve");
+
output_o(curve, cfg);
if (i != cfg->count - 1) {
output_o_separator(cfg);
@@ -249,5 +252,6 @@ int exhaustive_do(config_t *cfg) {
output_o_end(cfg);
exhaustive_quit(argss);
+ debug_log_end("Finished Exhaustive method");
return 0;
}
diff --git a/src/exhaustive/seed.c b/src/exhaustive/seed.c
index d35fc05..44663c8 100644
--- a/src/exhaustive/seed.c
+++ b/src/exhaustive/seed.c
@@ -2,18 +2,11 @@
* ecgen, tool for generating Elliptic curve domain parameters
* Copyright (C) 2017 J08nY
*/
+
#include "seed.h"
-#include "io/input.h"
+#include "util/memory.h"
-seed_t *seed_new(void) {
- seed_t *seed = pari_malloc(sizeof(seed_t));
- if (!seed) {
- perror("Couldn't malloc.");
- exit(1);
- }
- memset(seed, 0, sizeof(seed_t));
- return seed;
-}
+seed_t *seed_new(void) { return try_calloc(sizeof(seed_t)); }
seed_t *seed_copy(const seed_t *src, seed_t *dest) {
if (src->seed) dest->seed = gcopy(src->seed);
@@ -67,11 +60,7 @@ char *seed_itos(GEN seed) {
long len = glength(bits);
long bytes = (len / 8) + (len % 8 == 0 ? 0 : 1);
- char *result = pari_malloc((size_t)bytes);
- if (!result) {
- perror("Couldn't malloc.");
- exit(1);
- }
+ char *result = try_malloc((size_t)bytes);
for (long i = 0; i < len; ++i) {
// TODO