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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
|
/* MIT License
*
* Copyright (c) 2016-2020 INRIA, CMU and Microsoft Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef __internal_Hacl_Bignum_H
#define __internal_Hacl_Bignum_H
#if defined(__cplusplus)
extern "C" {
#endif
#include <string.h>
#include "krml/internal/types.h"
#include "krml/lowstar_endianness.h"
#include "krml/internal/target.h"
#include "internal/Hacl_Krmllib.h"
#include "../Hacl_Bignum.h"
#include "lib_intrinsics.h"
void
Hacl_Bignum_Karatsuba_bn_karatsuba_mul_uint32(
uint32_t aLen,
uint32_t *a,
uint32_t *b,
uint32_t *tmp,
uint32_t *res);
void
Hacl_Bignum_Karatsuba_bn_karatsuba_mul_uint64(
uint32_t aLen,
uint64_t *a,
uint64_t *b,
uint64_t *tmp,
uint64_t *res);
void
Hacl_Bignum_Karatsuba_bn_karatsuba_sqr_uint32(
uint32_t aLen,
uint32_t *a,
uint32_t *tmp,
uint32_t *res);
void
Hacl_Bignum_Karatsuba_bn_karatsuba_sqr_uint64(
uint32_t aLen,
uint64_t *a,
uint64_t *tmp,
uint64_t *res);
void
Hacl_Bignum_bn_add_mod_n_u32(
uint32_t len1,
uint32_t *n,
uint32_t *a,
uint32_t *b,
uint32_t *res);
void
Hacl_Bignum_bn_add_mod_n_u64(
uint32_t len1,
uint64_t *n,
uint64_t *a,
uint64_t *b,
uint64_t *res);
void
Hacl_Bignum_bn_sub_mod_n_u32(
uint32_t len1,
uint32_t *n,
uint32_t *a,
uint32_t *b,
uint32_t *res);
void
Hacl_Bignum_bn_sub_mod_n_u64(
uint32_t len1,
uint64_t *n,
uint64_t *a,
uint64_t *b,
uint64_t *res);
uint32_t Hacl_Bignum_ModInvLimb_mod_inv_uint32(uint32_t n0);
uint64_t Hacl_Bignum_ModInvLimb_mod_inv_uint64(uint64_t n0);
uint32_t Hacl_Bignum_Montgomery_bn_check_modulus_u32(uint32_t len, uint32_t *n);
void
Hacl_Bignum_Montgomery_bn_precomp_r2_mod_n_u32(
uint32_t len,
uint32_t nBits,
uint32_t *n,
uint32_t *res);
void
Hacl_Bignum_Montgomery_bn_mont_reduction_u32(
uint32_t len,
uint32_t *n,
uint32_t nInv,
uint32_t *c,
uint32_t *res);
void
Hacl_Bignum_Montgomery_bn_to_mont_u32(
uint32_t len,
uint32_t *n,
uint32_t nInv,
uint32_t *r2,
uint32_t *a,
uint32_t *aM);
void
Hacl_Bignum_Montgomery_bn_from_mont_u32(
uint32_t len,
uint32_t *n,
uint32_t nInv_u64,
uint32_t *aM,
uint32_t *a);
void
Hacl_Bignum_Montgomery_bn_mont_mul_u32(
uint32_t len,
uint32_t *n,
uint32_t nInv_u64,
uint32_t *aM,
uint32_t *bM,
uint32_t *resM);
void
Hacl_Bignum_Montgomery_bn_mont_sqr_u32(
uint32_t len,
uint32_t *n,
uint32_t nInv_u64,
uint32_t *aM,
uint32_t *resM);
uint64_t Hacl_Bignum_Montgomery_bn_check_modulus_u64(uint32_t len, uint64_t *n);
void
Hacl_Bignum_Montgomery_bn_precomp_r2_mod_n_u64(
uint32_t len,
uint32_t nBits,
uint64_t *n,
uint64_t *res);
void
Hacl_Bignum_Montgomery_bn_mont_reduction_u64(
uint32_t len,
uint64_t *n,
uint64_t nInv,
uint64_t *c,
uint64_t *res);
void
Hacl_Bignum_Montgomery_bn_to_mont_u64(
uint32_t len,
uint64_t *n,
uint64_t nInv,
uint64_t *r2,
uint64_t *a,
uint64_t *aM);
void
Hacl_Bignum_Montgomery_bn_from_mont_u64(
uint32_t len,
uint64_t *n,
uint64_t nInv_u64,
uint64_t *aM,
uint64_t *a);
void
Hacl_Bignum_Montgomery_bn_mont_mul_u64(
uint32_t len,
uint64_t *n,
uint64_t nInv_u64,
uint64_t *aM,
uint64_t *bM,
uint64_t *resM);
void
Hacl_Bignum_Montgomery_bn_mont_sqr_u64(
uint32_t len,
uint64_t *n,
uint64_t nInv_u64,
uint64_t *aM,
uint64_t *resM);
uint32_t
Hacl_Bignum_Exponentiation_bn_check_mod_exp_u32(
uint32_t len,
uint32_t *n,
uint32_t *a,
uint32_t bBits,
uint32_t *b);
void
Hacl_Bignum_Exponentiation_bn_mod_exp_vartime_precomp_u32(
uint32_t len,
uint32_t *n,
uint32_t mu,
uint32_t *r2,
uint32_t *a,
uint32_t bBits,
uint32_t *b,
uint32_t *res);
void
Hacl_Bignum_Exponentiation_bn_mod_exp_consttime_precomp_u32(
uint32_t len,
uint32_t *n,
uint32_t mu,
uint32_t *r2,
uint32_t *a,
uint32_t bBits,
uint32_t *b,
uint32_t *res);
void
Hacl_Bignum_Exponentiation_bn_mod_exp_vartime_u32(
uint32_t len,
uint32_t nBits,
uint32_t *n,
uint32_t *a,
uint32_t bBits,
uint32_t *b,
uint32_t *res);
void
Hacl_Bignum_Exponentiation_bn_mod_exp_consttime_u32(
uint32_t len,
uint32_t nBits,
uint32_t *n,
uint32_t *a,
uint32_t bBits,
uint32_t *b,
uint32_t *res);
uint64_t
Hacl_Bignum_Exponentiation_bn_check_mod_exp_u64(
uint32_t len,
uint64_t *n,
uint64_t *a,
uint32_t bBits,
uint64_t *b);
void
Hacl_Bignum_Exponentiation_bn_mod_exp_vartime_precomp_u64(
uint32_t len,
uint64_t *n,
uint64_t mu,
uint64_t *r2,
uint64_t *a,
uint32_t bBits,
uint64_t *b,
uint64_t *res);
void
Hacl_Bignum_Exponentiation_bn_mod_exp_consttime_precomp_u64(
uint32_t len,
uint64_t *n,
uint64_t mu,
uint64_t *r2,
uint64_t *a,
uint32_t bBits,
uint64_t *b,
uint64_t *res);
void
Hacl_Bignum_Exponentiation_bn_mod_exp_vartime_u64(
uint32_t len,
uint32_t nBits,
uint64_t *n,
uint64_t *a,
uint32_t bBits,
uint64_t *b,
uint64_t *res);
void
Hacl_Bignum_Exponentiation_bn_mod_exp_consttime_u64(
uint32_t len,
uint32_t nBits,
uint64_t *n,
uint64_t *a,
uint32_t bBits,
uint64_t *b,
uint64_t *res);
#if defined(__cplusplus)
}
#endif
#define __internal_Hacl_Bignum_H_DEFINED
#endif
|