1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
/*
* ecgen, tool for generating Elliptic curve domain parameters
* Copyright (C) 2017-2018 J08nY
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*/
/**
* @file ecgen.c
* @author J08nY <johny@neuromancer.sk>
* @version 0.7.7
* @copyright GPL v2.0
*/
#include <pari/pari.h>
#include "cm/cm.h"
#include "exhaustive/exhaustive.h"
#include "invalid/invalid.h"
#include "io/input.h"
#include "io/output.h"
#include "util/timeout.h"
#ifdef GIT_COMMIT
#define GIT_VERSION "(git " GIT_COMMIT ")"
#else
#define GIT_VERSION ""
#endif
const char *argp_program_version =
"ecgen 0.7.7" GIT_VERSION
"\n"
"Compiled with: " PARIVERSION
"\n\n"
"Copyright (C) 2017-2018,2021,2024 J08nY\n"
"License GPLv2: GNU GPL version 2 (or later) "
"<http://gnu.org/licenses/gpl.html>\n"
"This is free software: you are free to change and redistribute it.\n"
"There is NO WARRANTY, to the extent permitted by law.";
const char *argp_program_bug_address = "<johny+ecgen@neuromancer.sk>";
static struct argp argp = {cli_options, cli_parse, cli_args_doc,
cli_doc, 0, cli_filter};
bool init(void) {
// init PARI, 1GB stack, 1M primes
pari_init(cfg->memory, 1000000);
// init PARI PRNG
if (!random_init()) return false;
// init the signal handlers, etc. for timeout handling
if (!timeout_init()) return false;
// set datadir if specified
if (cfg->datadir) {
default0("datadir", cfg->datadir);
}
#ifdef PARI_DEBUG
default0("debug", "2");
#endif
// init the modular polynomial db from seadata
pari_sp ltop = avma;
pari_CATCH(e_FILE) {
fprintf(
stderr,
"seadata not found, this will probably take quite some time.\n");
}
pari_TRY { ellmodulareqn(2, -1, -1); }
pari_ENDCATCH avma = ltop;
// Fix the mysterious isprime bug.
isprime(stoi(1));
// open outfile
if (!output_init()) return false;
// open infile
if (!input_init()) return false;
return true;
}
int quit(int status) {
pari_close();
timeout_quit();
output_quit();
input_quit();
return status;
}
/**
* @mainpage
*/
int main(int argc, char *argv[]) {
memset(cfg, 0, sizeof(config_t));
if (!cli_init()) {
return quit(EXIT_FAILURE);
}
argp_parse(&argp, argc, argv, 0, 0, cfg);
cli_quit();
if (!init()) {
return quit(EXIT_FAILURE);
}
int status;
GET(method);
if (cfg->method == METHOD_CM || cfg->method == METHOD_ANOMALOUS ||
cfg->method == METHOD_SUPERSINGULAR) {
status = cm_do();
} else if (cfg->method == METHOD_INVALID) {
status = invalid_do();
} else {
status = exhaustive_do();
}
return quit(status);
}
|