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
|
/*
* ecgen, tool for generating Elliptic curve domain parameters
* Copyright (C) 2017 J08nY
*/
#include "equation.h"
#include "io/input.h"
int a_random(curve_t *curve, config_t *config, arg_t *args) {
curve->a = genrand(curve->field);
return 1;
}
int a_input(curve_t *curve, config_t *config, arg_t *args) {
pari_sp ltop = avma;
GEN inp = input_int("a:", config->bits);
if (gequalm1(inp)) {
avma = ltop;
return 0;
}
curve->a = gerepilecopy(ltop, inp);
// TODO change a to a field element here?. a t_INTMOD or a t_FFELT.
return 1;
}
static GEN a = NULL;
int a_once(curve_t *curve, config_t *config, arg_t *args) {
if (a) {
curve->a = gcopy(a);
return 1;
}
int inp = a_input(curve, config, args);
if (inp) {
a = gclone(curve->a);
} else {
return 0;
}
return 1;
}
int a_zero(curve_t *curve, config_t *config, arg_t *args) {
curve->a = gen_0;
return 1;
}
int a_one(curve_t *curve, config_t *config, arg_t *args) {
curve->a = gen_1;
return 1;
}
int a_seed(curve_t *curve, config_t *config, arg_t *args) {
// TODO implement
return INT_MIN;
}
int b_random(curve_t *curve, config_t *config, arg_t *args) {
curve->b = genrand(curve->field);
return 1;
}
int b_input(curve_t *curve, config_t *config, arg_t *args) {
pari_sp ltop = avma;
GEN inp = input_int("b:", config->bits);
if (gequalm1(inp)) {
avma = ltop;
return 0;
}
curve->b = gerepilecopy(ltop, inp);
// TODO change b to a field element here?. a t_INTMOD or a t_FFELT.
return 1;
}
static GEN b = NULL;
int b_once(curve_t *curve, config_t *config, arg_t *args) {
if (b) {
curve->b = gcopy(b);
return 1;
}
int inp = b_input(curve, config, args);
if (inp) {
b = gclone(curve->b);
} else {
return 0;
}
return 1;
}
int b_zero(curve_t *curve, config_t *config, arg_t *args) {
curve->b = gen_0;
return 1;
}
int b_one(curve_t *curve, config_t *config, arg_t *args) {
curve->b = gen_1;
return 1;
}
int b_seed(curve_t *curve, config_t *config, arg_t *args) {
// TODO implement
return INT_MIN;
}
|