Let us walk on the 3-isogeny graph
Loading...
Searching...
No Matches
validate.c
Go to the documentation of this file.
1
#include <string.h>
2
#include <assert.h>
3
4
#include "
../CTIDH/ctidh.h
"
5
#include "
primes.h
"
6
#include "
mont.h
"
7
#include "
elligator.h
"
8
// #include "fp2.h"
9
10
#ifdef ENABLE_CT_TESTING
11
#include <valgrind/memcheck.h>
12
#endif
13
14
// static void fp2_print(fp2 a){
15
// printf("0x%016lX,", A[i]);
16
17
// fp_print(a.re);
18
// fp_print(a.im);
19
// }
20
21
// wombat validate by checking full order point
22
bool
validate
(
public_key
const
*in){
23
// #if !defined(_M1_) && !defined(_M2_) && !defined(_M3_) && !defined(_M4_) && !defined(_M5_)
24
// printf("\nNOT using radical 3-isogenies.\n\n");
25
// #else
26
// printf("\nUsing 2^%ld radical 3-isogenies.\n\n", batch_start[0] - 1);
27
// #endif
28
proj
A, A24;
29
fp_copy
(A.x, in->
A
);
30
fp_copy
(A.z,
fp_1
);
31
xA24
(&A24, &A);
32
33
proj
Pp, Pm;
34
35
#ifdef ENABLE_CT_TESTING
36
memset(&Pp, 0,
sizeof
(
proj
));
37
memset(&Pp.
z
, 0,
sizeof
(
proj
));
38
VALGRIND_MAKE_MEM_DEFINED(&Pp.
z
,
sizeof
(
fp
));
39
VALGRIND_MAKE_MEM_DEFINED(&Pp,
sizeof
(
proj
));
40
VALGRIND_MAKE_MEM_DEFINED(&A24,
sizeof
(
proj
));
41
#endif
42
43
fp
seed;
44
fp_set(seed, in->
seed
);
45
fp_enc
(seed, seed);
46
elligator_seeded
(&Pp, &Pm, &A24, (
const
fp
*)seed);
47
48
49
for
(int64_t
j
= 0;
j
< two_cofactor;
j
++)
50
{
51
xDBL
(&Pp, &Pp, &A24, 0);
52
}
53
// clear ells replaced by radical 3-isogenies
54
for
(int16_t
j
= 0;
j
<
batch_start
[0];
j
++)
55
{
56
xMUL_dac
(&Pp, &A24, 0, &Pp,
primes_dac
[
j
],
primes_daclen
[
j
],
primes_daclen
[
j
]);
57
}
58
// remove ells and check that we do not reach the point at infinity
59
for
(
int
i
= primes_num-1;
i
>
batch_start
[0];
i
--)
60
{
61
xMUL_dac
(&Pp, &A24, 0, &Pp,
primes_dac
[
i
],
primes_daclen
[
i
],
primes_daclen
[
i
]);
62
if
(fp_iszero(Pp.
z
))
63
return
false
;
64
}
65
66
// after removing the last ell, now we should have the point at infinity
67
xMUL_dac
(&Pp, &A24, 0, &Pp,
primes_dac
[
batch_start
[0]],
primes_daclen
[
batch_start
[0]],
primes_daclen
[
batch_start
[0]]);
68
return
fp_iszero(Pp.
z
);
69
}
70
71
75
76
// For computing [(p + 1) / l_i]P, i:=0, ..., (N - 1)
77
void
cofactor_multiples
(
proj
P[],
proj
const
A,
size_t
lower,
size_t
upper)
78
{
79
assert
(lower < upper);
80
if
(upper - lower == 1)
81
return
;
82
83
int
i
;
84
size_t
mid = lower + (upper - lower + 1) / 2;
85
86
// proj_copy(P[mid], (const fp*)P[lower]);
87
fp_copy
(P[mid].x, P[lower].x);
88
fp_copy
(P[mid].z, P[lower].z);
89
90
for
(
i
= lower;
i
< (int)mid;
i
++)
91
xMUL_dac
(&P[mid], &A, 1, &P[mid],
primes_dac
[
i
],
primes_daclen
[
i
],
primes_daclen
[
i
]);
92
// xmul(P[mid], i, (const fp*)P[mid], A);
93
94
for
(
i
= (
int
)mid;
i
< (int)upper;
i
++)
95
xMUL_dac
(&P[lower], &A, 1, &P[lower],
primes_dac
[
i
],
primes_daclen
[
i
],
primes_daclen
[
i
]);
96
// xmul(P[lower], i, (const fp*)P[lower], A);
97
98
cofactor_multiples
(P, A, lower, mid);
99
cofactor_multiples
(P, A, mid, upper);
100
}
101
102
103
// #if defined(P511) || defined(P512) || defined(P2047m1l226) || defined(P4095m27l262)
104
105
// // output: true if key is valid
106
// // output: false if key is invalid
107
// bool validate(public_key const *in)
108
// {
109
110
// fp x;
111
112
// int number_of_primes = primes_num;
113
// proj P[primes_num] = {0};
114
115
// proj A;
116
// // A = (a : 1)
117
// fp_copy(A.x, in->A);
118
// fp_set1(A.z);
119
120
// // Coding curve coefficients as (A' + 2C : 4C)
121
// fp_add(A.z, A.z, A.z); // 2C
122
// fp_add(A.x, A.x, A.z); // A' + 2C
123
// fp_add(A.z, A.z, A.z); // 4C
124
125
// int i;
126
// uint64_t bits;
127
128
// do
129
// {
130
// bits = 0;
131
// // P = (x : 1)
132
// fp_random(x);
133
// fp_copy(P[0].x, x);
134
// fp_set1(P[0].z);
135
136
// // Multiplying by the cofactor
137
// for (int64_t j = 0; j < two_cofactor; j++)
138
// {
139
// xDBL(&P[0], &P[0], &A, 1);
140
// }
141
142
// // At this step, P[0] is expected to be a torsion-([p + 1]/[2^e]) point
143
// cofactor_multiples(P, A, 0, number_of_primes);
144
// for (i = number_of_primes - 1; i >= 0; i--)
145
// {
146
// // we only gain information if [(p+1)/l] P is non-zero
147
// if (fp_iszero(P[i].z) != 1)
148
// {
149
// // xmul(P[i], i, (const fp *)P[i], (const fp *)A);
150
// // printf("prime[i] = %lld\n", primes[i]);
151
// xMUL_dac(&P[i], &A, 1, &P[i], primes_dac[i], primes_daclen[i], primes_daclen[i]);
152
153
// // P does not have order dividing p + 1?
154
// if (fp_iszero(P[i].z) != 1)
155
// return false;
156
157
// // If bits > UPPER_BOUND, hence definitely supersingular
158
// bits += primes_daclen[i];
159
// if (bits > UPPER_BOUND)
160
// return true;
161
// };
162
// };
163
164
// } while (1);
165
// }
166
167
// #else
168
169
// bool validate(public_key const *in)
170
// {
171
// proj P;
172
// proj A;
173
// #ifndef CTIDH
174
// int number_of_primes = N;
175
// #else
176
// int number_of_primes = primes_num;
177
// #endif
178
// int ord = 0;
179
180
// fp_copy(A.x, in->A);
181
// fp_set1(A.z);
182
183
// // Coding curve coefficients as (A' + 2C : 4C)
184
// fp_add(A.z, A.z, A.z); // 2C
185
// fp_add(A.x, A.x, A.z); // A' + 2C
186
// fp_add(A.z, A.z, A.z); // 4C
187
188
// //fp_copy(P.x, p_minus_2);
189
// fp_set1(P.x);
190
// fp_add(P.x, P.x, P.x); //x = -2
191
// fp_set1(P.z);
192
193
// // at this point, P is the point (2, -) on E_A
194
// // this point should have enough 2-torsion!
195
196
// //xmul_dac or xMUL as long as it kills all ell_i
197
// //@sopmac: does this work?
198
// // for any reviewer reading this carefully: a highly optimized version should perform
199
// // a Montgomery ladder using X0 = 2 of length prod ell_i here
200
// for (int i = 0; i < (int) number_of_primes; i++)
201
// xMUL_dac(&P, &A, 1, &P, primes_dac[i], primes_daclen[i], primes_daclen[i]);
202
203
// //we kill of all ell_i, so P at this point should just
204
// //be a point of order 2^z. We check z by doing doublings until the point is infinity
205
// // as long as z is large enough (probabilisitically always true for our primes)
206
// // this verifies supersingularity, by verifying a point of order 2^z > 4 sqrt(p)
207
208
// //@sopmac: are we sure this is the right amount of doubling
209
// // and not one too many?
210
// while (fp_iszero(P.z) == 0 && ord < two_cofactor)
211
// {
212
// xDBL(&P, &P, &A, 1);
213
// ord++;
214
// }
215
216
// // now if P is inf we not that the 2-torsion of P was ord
217
// if (fp_iszero(P.z) == 1 && ord > (NUMBER_OF_WORDS*64)/2 + 1)
218
// {
219
// return true;
220
// }
221
222
// return false;
223
224
// }
225
226
// #endif
ctidh.h
validate
#define validate
Definition
ctidh.h:53
cofactor_multiples
#define cofactor_multiples
Definition
ctidh.h:55
elligator.h
elligator_seeded
#define elligator_seeded
Definition
elligator.h:8
fp
uint64_t fp[NUMBER_OF_WORDS]
Definition
fp-gmp.h:22
fp_1
#define fp_1
Definition
fp-gmp.h:48
fp_enc
#define fp_enc
Definition
fp-gmp.h:55
fp_copy
#define fp_copy
Definition
fp-gmp.h:79
assert
assert(var1 eq var2)
mont.h
xA24
#define xA24
Definition
mont.h:17
xMUL_dac
#define xMUL_dac
Definition
mont.h:21
xDBL
#define xDBL
Definition
mont.h:18
i
for i
Definition
prime_search.m:10
j
for j
Definition
prime_search.m:12
primes.h
primes_dac
#define primes_dac
Definition
primes.h:52
batch_start
#define batch_start
Definition
primes.h:55
primes_daclen
#define primes_daclen
Definition
primes.h:53
proj
Definition
proj.h:18
proj::z
fp z
Definition
proj.h:20
public_key
Definition
ctidh.h:39
public_key::seed
uint64_t seed
Definition
ctidh.h:41
public_key::A
fp A
Definition
ctidh.h:40
E:
pqc-engineering-ssec-23
dCTIDH
src
common
validate.c
Generated by
1.14.0