diff options
| author | J08nY | 2017-08-30 19:59:00 +0200 |
|---|---|---|
| committer | J08nY | 2017-08-30 19:59:00 +0200 |
| commit | 27241c94ef0a1752128c31a62fcfc89b3ee89b33 (patch) | |
| tree | 28184872d0d7cdf8faf2a5be302efce1eefdcea1 | |
| parent | 5856d4d9c66b361c613b85fd187e9e989c270129 (diff) | |
| download | ecgen-27241c94ef0a1752128c31a62fcfc89b3ee89b33.tar.gz ecgen-27241c94ef0a1752128c31a62fcfc89b3ee89b33.tar.zst ecgen-27241c94ef0a1752128c31a62fcfc89b3ee89b33.zip | |
| -rw-r--r-- | src/cm/cm.c | 2 | ||||
| -rw-r--r-- | src/exhaustive/anomalous.c | 6 | ||||
| -rw-r--r-- | src/exhaustive/exhaustive.c | 2 | ||||
| -rw-r--r-- | src/gen/field.c | 8 | ||||
| -rw-r--r-- | src/gen/order.c | 3 | ||||
| -rw-r--r-- | src/gen/point.c | 4 | ||||
| -rw-r--r-- | src/gen/seed.c | 3 | ||||
| -rw-r--r-- | src/io/input.c | 4 | ||||
| -rw-r--r-- | src/io/output.c | 49 | ||||
| -rw-r--r-- | src/io/output.h | 5 | ||||
| -rw-r--r-- | test/src/io/test_input.c | 1 |
11 files changed, 51 insertions, 36 deletions
diff --git a/src/cm/cm.c b/src/cm/cm.c index 027f761..cc0f832 100644 --- a/src/cm/cm.c +++ b/src/cm/cm.c @@ -9,7 +9,7 @@ int cm_do(config_t *cfg) { debug_log_start("Starting Complex Multiplication method"); - fprintf(stderr, "This is *NOT IMPLEMENTED* currently.\n"); + fprintf(err, "This is *NOT IMPLEMENTED* currently.\n"); GEN D = stoi(71); form_t **forms; diff --git a/src/exhaustive/anomalous.c b/src/exhaustive/anomalous.c index 7edab5e..eeda573 100644 --- a/src/exhaustive/anomalous.c +++ b/src/exhaustive/anomalous.c @@ -3,6 +3,7 @@ * Copyright (C) 2017 J08nY */ #include "anomalous.h" +#include "io/output.h" #include "util/memory.h" static disc_t **disc_table; @@ -89,7 +90,7 @@ static GEN anomalous_c(size_t i, GEN p) { GENERATOR(anomalous_gen_field) { if (!args) { - fprintf(stderr, "No args to an arged function. anomalous_field\n"); + fprintf(err, "No args to an arged function. anomalous_field\n"); return INT_MIN; } size_t i = *(size_t *)args->args; @@ -108,8 +109,7 @@ GENERATOR(anomalous_gen_field) { GENERATOR(anomalous_gen_equation) { if (!args) { - fprintf(stderr, - "No args to an arged function. anomalous_gen_equation\n"); + fprintf(err, "No args to an arged function. anomalous_gen_equation\n"); return INT_MIN; } size_t i = *(size_t *)args->args; diff --git a/src/exhaustive/exhaustive.c b/src/exhaustive/exhaustive.c index 35c09d8..6b77f3a 100644 --- a/src/exhaustive/exhaustive.c +++ b/src/exhaustive/exhaustive.c @@ -176,7 +176,7 @@ int exhaustive_gen_retry(curve_t *curve, const config_t *cfg, if (diff <= 0) { if (diff == INT_MIN || state + diff < 0) { - fprintf(stderr, "Error generating a curve. state = %i\n", + fprintf(err, "Error generating a curve. state = %i\n", state); return 0; } diff --git a/src/gen/field.c b/src/gen/field.c index 8bf2bf0..482bcc5 100644 --- a/src/gen/field.c +++ b/src/gen/field.c @@ -4,6 +4,7 @@ */ #include "field.h" #include "io/input.h" +#include "io/output.h" #include "math/poly.h" static GEN field_primer(unsigned long bits) { return random_prime(bits); } @@ -12,8 +13,7 @@ static GEN field_binaryr(unsigned long bits) { if (poly_exists(bits)) { return poly_find_gen(bits); } else { - fprintf(stderr, - "Unable to find a suitable binary field. Use an explicit one."); + fprintf(err, "Unable to find a suitable binary field. Use an explicit one."); exit(1); } } @@ -67,7 +67,7 @@ GENERATOR(field_gen_input) { } if (isintzero(e1) && isintzero(e2) && isintzero(e3)) { - fprintf(stderr, "At least one exponent must be nonzero.\n"); + fprintf(err, "At least one exponent must be nonzero.\n"); avma = ltop; return 0; } @@ -81,7 +81,7 @@ GENERATOR(field_gen_input) { GEN poly = gmul(gtopolyrev(v, -1), gmodulss(1, 2)); if (!isirreducible(poly)) { - fprintf(stderr, "Polynomial is reducible.\n"); + fprintf(err, "Polynomial is reducible.\n"); avma = ltop; return 0; } diff --git a/src/gen/order.c b/src/gen/order.c index 6ecd7d6..891c95b 100644 --- a/src/gen/order.c +++ b/src/gen/order.c @@ -4,6 +4,7 @@ */ #include "order.h" #include "io/input.h" +#include "io/output.h" GENERATOR(order_gen_input) { pari_sp ltop = avma; @@ -43,7 +44,7 @@ GENERATOR(order_gen_sea) { GENERATOR(order_gen_smallfact) { if (!args) { - fprintf(stderr, "No args to an arged function. order_gen_smallfact\n"); + fprintf(err, "No args to an arged function. order_gen_smallfact\n"); return INT_MIN; } diff --git a/src/gen/point.c b/src/gen/point.c index 2a5a464..11561fb 100644 --- a/src/gen/point.c +++ b/src/gen/point.c @@ -104,7 +104,7 @@ GENERATOR(point_gen_random) { GENERATOR(points_gen_random) { if (!args) { - fprintf(stderr, "No args to an arged function. points_gen_random\n"); + fprintf(err, "No args to an arged function. points_gen_random\n"); return INT_MIN; } @@ -161,7 +161,7 @@ static int points_from_orders(curve_t *curve, GEN orders) { GENERATOR(points_gen_trial) { if (!args) { - fprintf(stderr, "No args to an arged function. points_gen_trial\n"); + fprintf(err, "No args to an arged function. points_gen_trial\n"); return INT_MIN; } diff --git a/src/gen/seed.c b/src/gen/seed.c index e131879..505493a 100644 --- a/src/gen/seed.c +++ b/src/gen/seed.c @@ -4,6 +4,7 @@ */ #include "seed.h" +#include "io/output.h" #include "util/memory.h" seed_t *seed_new(void) { return try_calloc(sizeof(seed_t)); } @@ -91,7 +92,7 @@ GENERATOR(seed_gen_input) { GEN str = input_string("seed:"); const char *cstr = GSTR(str); if (strlen(cstr) < 20) { - fprintf(stderr, "SEED must be at least 160 bits(20 characters).\n"); + fprintf(err, "SEED must be at least 160 bits(20 characters).\n"); avma = ltop; return 0; } diff --git a/src/io/input.c b/src/io/input.c index 9ab921a..2c0398a 100644 --- a/src/io/input.c +++ b/src/io/input.c @@ -50,7 +50,7 @@ static GEN input_i(const char *prompt, unsigned long bits) { if (cmpii(in, size) <= 0) { return gerepileupto(ltop, in); } else { - fprintf(stderr, "Number too big(> %ld bits).\n", bits); + fprintf(err, "Number too big(> %ld bits).\n", bits); return gen_m1; } } @@ -63,7 +63,7 @@ GEN input_prime(const char *prompt, unsigned long bits) { if (isprime(read)) { return read; } else { - fprintf(stderr, "Number is not prime. Prime required.\n"); + fprintf(err, "Number is not prime. Prime required.\n"); return gen_m1; } } diff --git a/src/io/output.c b/src/io/output.c index f3c50e0..2d05bec 100644 --- a/src/io/output.c +++ b/src/io/output.c @@ -9,6 +9,7 @@ #include "util/memory.h" FILE *out; +FILE *err; FILE *verbose; char *output_malloc(const char *what) { @@ -28,23 +29,23 @@ char *output_scsv(curve_t *curve, const config_t *cfg) { switch (cfg->field) { case FIELD_PRIME: params[OFFSET_FIELD] = - pari_sprintf("%P0#*x", cfg->hex_digits, curve->field); + pari_sprintf("%P0#*x", cfg->hex_digits, curve->field); break; case FIELD_BINARY: { GEN field = field_params(curve->field); params[OFFSET_FIELD] = - pari_sprintf("%P#x,%P#x,%P#x,%P#x", gel(field, 1), - gel(field, 2), gel(field, 3), gel(field, 4)); + pari_sprintf("%P#x,%P#x,%P#x,%P#x", gel(field, 1), + gel(field, 2), gel(field, 3), gel(field, 4)); break; } } if (curve->a) params[OFFSET_A] = - pari_sprintf("%P0#*x", cfg->hex_digits, field_elementi(curve->a)); + pari_sprintf("%P0#*x", cfg->hex_digits, field_elementi(curve->a)); if (curve->b) params[OFFSET_B] = - pari_sprintf("%P0#*x", cfg->hex_digits, field_elementi(curve->b)); + pari_sprintf("%P0#*x", cfg->hex_digits, field_elementi(curve->b)); if (curve->generators) { char *gens[curve->ngens]; @@ -54,8 +55,8 @@ char *output_scsv(curve_t *curve, const config_t *cfg) { GEN x = field_elementi(gel(generator->point, 1)); GEN y = field_elementi(gel(generator->point, 2)); gens[i] = pari_sprintf("%P0#*x,%P0#*x,%P#x,%P#x", cfg->hex_digits, - x, cfg->hex_digits, y, generator->order, - generator->cofactor); + x, cfg->hex_digits, y, generator->order, + generator->cofactor); len += strlen(gens[i]); } size_t lenn = sizeof(char) * (len + curve->ngens); @@ -69,7 +70,7 @@ char *output_scsv(curve_t *curve, const config_t *cfg) { if (curve->order) params[OFFSET_ORDER] = - pari_sprintf("%P0#*x", cfg->hex_digits, curve->order); + pari_sprintf("%P0#*x", cfg->hex_digits, curve->order); if (curve->points) { char *points[curve->npoints]; @@ -79,7 +80,7 @@ char *output_scsv(curve_t *curve, const config_t *cfg) { GEN x = field_elementi(gel(point->point, 1)); GEN y = field_elementi(gel(point->point, 2)); points[i] = pari_sprintf("%P0#*x,%P0#*x,%P#x", cfg->hex_digits, x, - cfg->hex_digits, y, point->order); + cfg->hex_digits, y, point->order); len += strlen(points[i]); } size_t lenn = sizeof(char) * (len + curve->npoints); @@ -149,8 +150,7 @@ static JSON_Value *output_jjson(curve_t *curve, const config_t *cfg) { pari_free(e3); break; } - default: - fprintf(stderr, "Error, field has unknown amount of elements.\n"); + default: fprintf(err, "Error, field has unknown amount of elements.\n"); exit(1); } @@ -172,13 +172,13 @@ static JSON_Value *output_jjson(curve_t *curve, const config_t *cfg) { JSON_Object *point_object = json_value_get_object(point_value); char *x = pari_sprintf( - "%P0#*x", cfg->hex_digits, - field_elementi(gel(curve->generators[i]->point, 1))); + "%P0#*x", cfg->hex_digits, + field_elementi(gel(curve->generators[i]->point, 1))); json_object_set_string(point_object, "x", x); pari_free(x); char *y = pari_sprintf( - "%P0#*x", cfg->hex_digits, - field_elementi(gel(curve->generators[i]->point, 2))); + "%P0#*x", cfg->hex_digits, + field_elementi(gel(curve->generators[i]->point, 2))); json_object_set_string(point_object, "y", y); pari_free(y); char *p_order = pari_sprintf("%P#x", curve->generators[i]->order); @@ -186,7 +186,7 @@ static JSON_Value *output_jjson(curve_t *curve, const config_t *cfg) { pari_free(p_order); if (curve->generators[i]->cofactor) { char *cofactor = - pari_sprintf("%P#x", curve->generators[i]->cofactor); + pari_sprintf("%P#x", curve->generators[i]->cofactor); json_object_set_string(point_object, "cofactor", cofactor); pari_free(cofactor); } @@ -206,13 +206,13 @@ static JSON_Value *output_jjson(curve_t *curve, const config_t *cfg) { JSON_Object *point_object = json_value_get_object(point_value); char *x = - pari_sprintf("%P0#*x", cfg->hex_digits, - field_elementi(gel(curve->points[i]->point, 1))); + pari_sprintf("%P0#*x", cfg->hex_digits, + field_elementi(gel(curve->points[i]->point, 1))); json_object_set_string(point_object, "x", x); pari_free(x); char *y = - pari_sprintf("%P0#*x", cfg->hex_digits, - field_elementi(gel(curve->points[i]->point, 2))); + pari_sprintf("%P0#*x", cfg->hex_digits, + field_elementi(gel(curve->points[i]->point, 2))); json_object_set_string(point_object, "y", y); pari_free(y); char *p_order = pari_sprintf("%P#x", curve->points[i]->order); @@ -220,7 +220,7 @@ static JSON_Value *output_jjson(curve_t *curve, const config_t *cfg) { pari_free(p_order); if (curve->points[i]->cofactor) { char *cofactor = - pari_sprintf("%P#x", curve->points[i]->cofactor); + pari_sprintf("%P#x", curve->points[i]->cofactor); json_object_set_string(point_object, "cofactor", cofactor); pari_free(cofactor); } @@ -306,6 +306,10 @@ bool output_init(const config_t *cfg) { out = stdout; } setvbuf(out, NULL, _IONBF, 0); + + err = stderr; + setvbuf(err, NULL, _IONBF, 0); + if (cfg->verbose_log) { verbose = fopen(cfg->verbose_log, "w"); if (!verbose) { @@ -340,4 +344,7 @@ void output_quit(void) { if (out != NULL && out != stdout) { fclose(out); } + if (err != NULL && err != stdout) { + fclose(err); + } } diff --git a/src/io/output.h b/src/io/output.h index 05c00e3..586f4e8 100644 --- a/src/io/output.h +++ b/src/io/output.h @@ -208,6 +208,11 @@ void output_o_end(const config_t *cfg); extern FILE *out; /** + * @brief + */ +extern FILE *err; + +/** * @brief Configured verbose output FILE*. */ extern FILE *verbose; diff --git a/test/src/io/test_input.c b/test/src/io/test_input.c index 6e7064f..30bbcb1 100644 --- a/test/src/io/test_input.c +++ b/test/src/io/test_input.c @@ -25,6 +25,7 @@ void input_setup() { write_in = fdopen(in_fd[1], "w"); setlinebuf(write_in); in = fdopen(in_fd[0], "r"); + err = fopen("/dev/null", "w"); } void input_teardown() { |
