/src/cryptofuzz/modules/openssl/bn_ops.h
Line | Count | Source (jump to first uncovered line) |
1 | | #pragma once |
2 | | |
3 | | #include <cryptofuzz/components.h> |
4 | | #include <cryptofuzz/operations.h> |
5 | | #include <openssl/bn.h> |
6 | | #include <openssl/asn1.h> |
7 | | #if defined(CRYPTOFUZZ_BORINGSSL) |
8 | | #include <openssl/mem.h> |
9 | | #endif |
10 | | #include <array> |
11 | | |
12 | | namespace cryptofuzz { |
13 | | namespace module { |
14 | | namespace OpenSSL_bignum { |
15 | | |
16 | | class Bignum { |
17 | | private: |
18 | | BIGNUM* bn = nullptr; |
19 | | Datasource& ds; |
20 | | bool locked = false; |
21 | | bool noFree = false; |
22 | | public: |
23 | | Bignum(Datasource& ds) : |
24 | | ds(ds) |
25 | 61.1k | { } |
26 | | |
27 | 100k | ~Bignum() { |
28 | 100k | if ( noFree == false ) { |
29 | 96.7k | BN_free(bn); |
30 | 96.7k | } |
31 | 100k | } |
32 | | |
33 | 5.09k | void Lock(void) { |
34 | 5.09k | locked = true; |
35 | 5.09k | } |
36 | | |
37 | 3.66k | void DisableFree(void) { |
38 | 3.66k | noFree = true; |
39 | 3.66k | } |
40 | | |
41 | 3.66k | void ReleaseOwnership(void) { |
42 | 3.66k | Lock(); |
43 | 3.66k | DisableFree(); |
44 | 3.66k | } |
45 | | |
46 | 51.8k | bool New(void) { |
47 | 51.8k | CF_ASSERT(locked == false, "Cannot renew locked Bignum"); |
48 | | |
49 | 51.8k | BN_free(bn); |
50 | 51.8k | bn = BN_new(); |
51 | | |
52 | 51.8k | return bn != nullptr; |
53 | 51.8k | } |
54 | | |
55 | 55 | bool Set(Bignum& other) { |
56 | 55 | bool ret = false; |
57 | | |
58 | 55 | CF_CHECK_NE(BN_copy(bn, other.GetPtr()), NULL); |
59 | | |
60 | 55 | ret = true; |
61 | 55 | end: |
62 | 55 | return ret; |
63 | 55 | } |
64 | | |
65 | 49.4k | bool Set(const std::string s) { |
66 | 49.4k | CF_ASSERT(locked == false, "Cannot set locked Bignum"); |
67 | | |
68 | 49.4k | bool ret = false; |
69 | | |
70 | 49.4k | CF_CHECK_NE(BN_dec2bn(&bn, s.c_str()), 0); |
71 | | |
72 | 49.4k | ret = true; |
73 | 49.4k | end: |
74 | 49.4k | return ret; |
75 | 49.4k | } |
76 | | |
77 | 447 | std::optional<uint64_t> AsUint64(void) const { |
78 | 447 | std::optional<uint64_t> ret = std::nullopt; |
79 | | |
80 | 447 | uint8_t which = 0; try { which = ds.Get<uint8_t>(); } catch ( ... ) { } |
81 | | |
82 | 447 | switch ( which ) { |
83 | 331 | case 0: |
84 | 331 | #if !defined(CRYPTOFUZZ_OPENSSL_102) && !defined(CRYPTOFUZZ_OPENSSL_098) |
85 | 331 | { |
86 | | /* BN_bn2binpad is not supported by OpenSSL 1.0.2 and 0.9.8 */ |
87 | | |
88 | 331 | uint64_t v; |
89 | | |
90 | 331 | CF_CHECK_NE(BN_is_negative(bn), 1); |
91 | | |
92 | 319 | CF_CHECK_LTE(BN_num_bytes(bn), (int)sizeof(uint64_t)); |
93 | 283 | CF_CHECK_NE(BN_bn2binpad(bn, (unsigned char*)&v, sizeof(v)), -1); |
94 | | |
95 | 283 | #if !(defined __s390x__) |
96 | | /* Manual reversing is required because |
97 | | * BN_bn2lebinpad is not supported by BoringSSL. |
98 | | * |
99 | | * Reversal is ommitted for s390x as it is a big-endian |
100 | | * architecture. |
101 | | */ |
102 | 283 | v = |
103 | 283 | ((v & 0xFF00000000000000) >> 56) | |
104 | 283 | ((v & 0x00FF000000000000) >> 40) | |
105 | 283 | ((v & 0x0000FF0000000000) >> 24) | |
106 | 283 | ((v & 0x000000FF00000000) >> 8) | |
107 | 283 | ((v & 0x00000000FF000000) << 8) | |
108 | 283 | ((v & 0x0000000000FF0000) << 24) | |
109 | 283 | ((v & 0x000000000000FF00) << 40) | |
110 | 283 | ((v & 0x00000000000000FF) << 56); |
111 | 283 | #endif |
112 | | |
113 | 283 | ret = v; |
114 | 283 | } |
115 | 0 | #endif |
116 | 0 | break; |
117 | 9 | case 1: |
118 | | #if !defined(CRYPTOFUZZ_LIBRESSL) && !defined(CRYPTOFUZZ_BORINGSSL) && !defined(CRYPTOFUZZ_OPENSSL_102) && !defined(CRYPTOFUZZ_OPENSSL_098) |
119 | | { |
120 | | ASN1_INTEGER* asn1 = nullptr; |
121 | | uint64_t v; |
122 | | |
123 | | CF_CHECK_NE( (asn1 = BN_to_ASN1_INTEGER(bn, nullptr)), nullptr); |
124 | | const auto r = ASN1_INTEGER_get_uint64(&v, asn1); |
125 | | ASN1_INTEGER_free(asn1); |
126 | | CF_CHECK_EQ(r, 1); |
127 | | |
128 | | ret = v; |
129 | | } |
130 | | #endif |
131 | 9 | break; |
132 | 107 | default: |
133 | 107 | break; |
134 | | |
135 | 447 | } |
136 | | |
137 | | /* Silence compiler */ |
138 | 399 | goto end; |
139 | 447 | end: |
140 | 447 | return ret; |
141 | 447 | } |
142 | | |
143 | 200 | std::optional<int> AsInt(void) const { |
144 | 200 | CF_NORET(util::HintBignumInt()); |
145 | | |
146 | 200 | std::optional<int> ret = std::nullopt; |
147 | 200 | const auto u64 = AsUint64(); |
148 | | |
149 | 200 | CF_CHECK_NE(u64, std::nullopt); |
150 | 168 | CF_CHECK_LTE(*u64, 2147483647); |
151 | | |
152 | 166 | ret = *u64; |
153 | 200 | end: |
154 | 200 | return ret; |
155 | 166 | } |
156 | | |
157 | 247 | std::optional<BN_ULONG> AsBN_ULONG(void) const { |
158 | 247 | std::optional<BN_ULONG> ret; |
159 | 247 | std::optional<uint64_t> v64; |
160 | | |
161 | | /* Convert bn[1] to uint64_t if possible */ |
162 | 247 | CF_CHECK_NE(v64 = AsUint64(), std::nullopt); |
163 | | |
164 | | /* Try to convert the uint64_t to BN_ULONG */ |
165 | 115 | BN_ULONG vul; |
166 | 115 | CF_CHECK_EQ(vul = *v64, *v64); |
167 | | |
168 | 115 | ret = vul; |
169 | 247 | end: |
170 | 247 | return ret; |
171 | 115 | } |
172 | | |
173 | 0 | void SetUint32(const uint32_t v) { |
174 | 0 | /* Gnarly but it works for now */ |
175 | 0 |
|
176 | 0 | char s[1024]; |
177 | 0 | if ( sprintf(s, "%u", v) < 0 ) { |
178 | 0 | abort(); |
179 | 0 | } |
180 | 0 |
|
181 | 0 | if ( Set(s) == false ) { |
182 | 0 | abort(); |
183 | 0 | } |
184 | 0 | } |
185 | | |
186 | 0 | bool SetWord(const BN_ULONG v) { |
187 | 0 | bool ret = false; |
188 | |
|
189 | 0 | CF_CHECK_EQ(BN_set_word(bn, v), 1); |
190 | 0 | ret = true; |
191 | |
|
192 | 0 | end: |
193 | 0 | return ret; |
194 | 0 | } |
195 | | |
196 | 35.3k | BIGNUM* GetDestPtr(const bool allowDup = true) { |
197 | 35.3k | if ( locked == false ) { |
198 | 31.9k | try { |
199 | 31.9k | { |
200 | 31.9k | const bool changeConstness = ds.Get<bool>(); |
201 | 31.9k | if ( changeConstness == true ) { |
202 | 3.99k | #if !defined(CRYPTOFUZZ_BORINGSSL) |
203 | 3.99k | const bool constness = ds.Get<bool>(); |
204 | | |
205 | 3.99k | if ( constness == true ) { |
206 | 2.01k | /* noret */ BN_set_flags(bn, BN_FLG_CONSTTIME); |
207 | 2.01k | } else { |
208 | 1.98k | /* noret */ BN_set_flags(bn, 0); |
209 | 1.98k | } |
210 | 3.99k | #endif |
211 | 3.99k | } |
212 | 31.9k | } |
213 | | |
214 | 31.9k | { |
215 | 31.9k | if ( allowDup == true ) { |
216 | 8.39k | const bool dup = ds.Get<bool>(); |
217 | | |
218 | 8.39k | if ( dup == true ) { |
219 | 3.98k | BIGNUM* tmp = BN_dup(bn); |
220 | 3.98k | if ( tmp != nullptr ) { |
221 | 3.98k | BN_free(bn); |
222 | 3.98k | bn = tmp; |
223 | 3.98k | } |
224 | 3.98k | } |
225 | 8.39k | } |
226 | 31.9k | } |
227 | | |
228 | 31.9k | { |
229 | 31.9k | if ( allowDup == true ) { |
230 | 7.90k | const bool asn1Convert = ds.Get<bool>(); |
231 | | |
232 | 7.90k | if ( asn1Convert == true ) { |
233 | 3.71k | ASN1_INTEGER* asn1 = BN_to_ASN1_INTEGER(bn, nullptr); |
234 | | |
235 | 3.71k | if ( asn1 != nullptr ) { |
236 | 3.71k | BIGNUM* tmp = ASN1_INTEGER_to_BN(asn1, nullptr); |
237 | | |
238 | 3.71k | if ( tmp != nullptr ) { |
239 | 3.71k | BN_free(bn); |
240 | 3.71k | bn = tmp; |
241 | 3.71k | } |
242 | | |
243 | 3.71k | ASN1_INTEGER_free(asn1); |
244 | 3.71k | } |
245 | 3.71k | } |
246 | 7.90k | } |
247 | 31.9k | } |
248 | | |
249 | 31.9k | { |
250 | 31.9k | if ( allowDup == true ) { |
251 | 7.63k | const bool asn1Convert = ds.Get<bool>(); |
252 | | |
253 | 7.63k | if ( asn1Convert == true ) { |
254 | 3.49k | ASN1_ENUMERATED* asn1 = BN_to_ASN1_ENUMERATED(bn, nullptr); |
255 | | |
256 | 3.49k | if ( asn1 != nullptr ) { |
257 | 3.49k | BIGNUM* tmp = ASN1_ENUMERATED_to_BN(asn1, nullptr); |
258 | | |
259 | 3.49k | if ( tmp != nullptr ) { |
260 | 3.49k | BN_free(bn); |
261 | 3.49k | bn = tmp; |
262 | 3.49k | } |
263 | | |
264 | 3.49k | ASN1_ENUMERATED_free(asn1); |
265 | 3.49k | } |
266 | 3.49k | } |
267 | 7.63k | } |
268 | 31.9k | } |
269 | | |
270 | 31.9k | { |
271 | 31.9k | if ( allowDup == true ) { |
272 | 7.44k | const bool mpiConvert = ds.Get<bool>(); |
273 | | |
274 | 7.44k | if ( mpiConvert == true ) { |
275 | 3.77k | const auto size = BN_bn2mpi(bn, nullptr); |
276 | 3.77k | uint8_t* p = util::malloc(size); |
277 | 3.77k | const auto size2 = BN_bn2mpi(bn, p); |
278 | 3.77k | CF_ASSERT(size == size2, "BN_bn2mpi size discrepancy"); |
279 | 3.77k | BIGNUM* newbn = BN_new(); |
280 | 3.77k | CF_ASSERT(BN_mpi2bn(p, size, newbn) != nullptr, "BN_mpi2bn failed"); |
281 | 3.77k | CF_ASSERT(BN_copy(bn, newbn) != nullptr, "BN_copy failed"); |
282 | 3.77k | BN_free(newbn); |
283 | 3.77k | util::free(p); |
284 | 3.77k | } |
285 | 7.44k | } |
286 | | |
287 | 31.9k | if ( allowDup == true ) { |
288 | 7.25k | const bool binConvert = ds.Get<bool>(); |
289 | | |
290 | 7.25k | if ( binConvert == true && BN_is_negative(bn) == 0 ) { |
291 | 3.09k | const auto size = BN_num_bytes(bn); |
292 | 3.09k | uint8_t* p = util::malloc(size); |
293 | 3.09k | const auto size2 = BN_bn2bin(bn, p); |
294 | 3.09k | CF_ASSERT(size == size2, "BN_bn2bin size discrepancy"); |
295 | 3.09k | BIGNUM* newbn = BN_new(); |
296 | 3.09k | CF_ASSERT(BN_bin2bn(p, size, newbn) != nullptr, "BN_bin2bn failed"); |
297 | 3.09k | CF_ASSERT(BN_copy(bn, newbn) != nullptr, "BN_copy failed"); |
298 | 3.09k | BN_free(newbn); |
299 | 3.09k | util::free(p); |
300 | 3.09k | } |
301 | 7.25k | } |
302 | 31.9k | } |
303 | 31.9k | } catch ( ... ) { } |
304 | 31.9k | } |
305 | | |
306 | 35.3k | return bn; |
307 | 35.3k | } |
308 | | |
309 | 3.99k | BIGNUM* GetPtrConst(void) const { |
310 | 3.99k | return bn; |
311 | 3.99k | } |
312 | | |
313 | 26.2k | const BIGNUM* GetPtr(const bool allowDup = true) { |
314 | 26.2k | return GetDestPtr(allowDup); |
315 | 26.2k | } |
316 | | |
317 | 4.48k | std::optional<component::Bignum> ToComponentBignum(void) { |
318 | 4.48k | std::optional<component::Bignum> ret = std::nullopt; |
319 | | |
320 | 4.48k | char* str = nullptr; |
321 | | |
322 | 4.48k | bool hex = true; |
323 | 4.48k | try { hex = ds.Get<bool>(); } catch ( fuzzing::datasource::Datasource::OutOfData& ) { } |
324 | | |
325 | 4.48k | if ( hex == true ) { |
326 | 3.98k | CF_CHECK_NE(str = BN_bn2hex(GetPtr()), nullptr); |
327 | 3.98k | ret = { util::HexToDec(str) }; |
328 | 3.98k | } else { |
329 | 498 | CF_CHECK_NE(str = BN_bn2dec(GetPtr()), nullptr); |
330 | 498 | ret = { std::string(str) }; |
331 | 498 | } |
332 | 4.48k | end: |
333 | 4.48k | OPENSSL_free(str); |
334 | | |
335 | 4.48k | return ret; |
336 | 4.48k | } |
337 | | |
338 | 0 | std::optional<std::string> ToString(void) { |
339 | 0 | std::optional<std::string> ret = std::nullopt; |
340 | 0 |
|
341 | 0 | char* str = nullptr; |
342 | 0 |
|
343 | 0 | CF_CHECK_NE(str = BN_bn2dec(GetPtr()), nullptr); |
344 | 0 | ret = { std::string(str) }; |
345 | 0 | end: |
346 | 0 | OPENSSL_free(str); |
347 | 0 |
|
348 | 0 | return ret; |
349 | 0 | } |
350 | | |
351 | 9.81k | void Randomize(void) { |
352 | 9.81k | std::vector<uint8_t> data; |
353 | 9.81k | try { |
354 | 9.81k | data = ds.GetData(0, 1, 1024); |
355 | 9.81k | } catch ( fuzzing::datasource::Datasource::OutOfData& ) { } |
356 | | |
357 | 9.81k | if ( !data.empty() ) { |
358 | 641 | /* ignore return value */ BN_bin2bn(data.data(), data.size(), bn); |
359 | 641 | } |
360 | 9.81k | } |
361 | | |
362 | 1.59k | inline bool operator==(const Bignum& rhs) const { |
363 | 1.59k | return BN_cmp(GetPtrConst(), rhs.GetPtrConst()) == 0; |
364 | 1.59k | } |
365 | | }; |
366 | | |
367 | | class BignumCluster { |
368 | | private: |
369 | | Datasource& ds; |
370 | | std::array<Bignum, 4> bn; |
371 | | std::optional<size_t> res_index = std::nullopt; |
372 | | public: |
373 | | BignumCluster(Datasource& ds, Bignum bn0, Bignum bn1, Bignum bn2, Bignum bn3) : |
374 | | ds(ds), |
375 | | bn({bn0, bn1, bn2, bn3}) |
376 | 9.81k | { } |
377 | | |
378 | 14.5k | Bignum& operator[](const size_t index) { |
379 | 14.5k | CF_ASSERT(index < bn.size(), "Accessing bignum with illegal index"); |
380 | | |
381 | 14.5k | try { |
382 | | /* Rewire? */ |
383 | 14.5k | if ( ds.Get<bool>() == true ) { |
384 | | /* Pick a random bignum */ |
385 | 1.67k | const size_t newIndex = ds.Get<uint8_t>() % 4; |
386 | | |
387 | | /* Same value? */ |
388 | 1.67k | if ( bn[newIndex] == bn[index] ) { |
389 | | /* Then return reference to other bignum */ |
390 | | |
391 | 514 | if ( newIndex != index ) { |
392 | 62 | bn[newIndex].Lock(); |
393 | 62 | } |
394 | | |
395 | 514 | return bn[newIndex]; |
396 | 514 | } |
397 | | |
398 | | /* Fall through */ |
399 | 1.67k | } |
400 | 14.5k | } catch ( fuzzing::datasource::Datasource::OutOfData& ) { } |
401 | | |
402 | 14.0k | return bn[index]; |
403 | 14.5k | } |
404 | | |
405 | 85 | Bignum& Get(const size_t index) { |
406 | 85 | CF_ASSERT(index < bn.size(), "Accessing bignum with illegal index"); |
407 | | |
408 | 85 | return bn[index]; |
409 | 85 | } |
410 | | |
411 | 85 | BIGNUM* GetDestPtr(const size_t index) { |
412 | 85 | return Get(index).GetDestPtr(); |
413 | 85 | } |
414 | | |
415 | 39.2k | bool New(const size_t index) { |
416 | 39.2k | CF_ASSERT(index < bn.size(), "Accessing bignum with illegal index"); |
417 | | |
418 | 39.2k | return bn[index].New(); |
419 | 39.2k | } |
420 | | |
421 | 39.2k | bool Set(const size_t index, const std::string s) { |
422 | 39.2k | CF_ASSERT(index < bn.size(), "Accessing bignum with illegal index"); |
423 | | |
424 | 39.2k | return bn[index].Set(s); |
425 | 39.2k | } |
426 | | |
427 | 1.37k | BIGNUM* GetResPtr(void) { |
428 | 1.37k | CF_ASSERT(res_index == std::nullopt, "Reusing result pointer"); |
429 | | |
430 | 1.37k | res_index = 0; |
431 | | |
432 | 1.37k | try { res_index = ds.Get<uint8_t>() % 4; } |
433 | 1.37k | catch ( fuzzing::datasource::Datasource::OutOfData& ) { } |
434 | | |
435 | 1.37k | bn[*res_index].Lock(); |
436 | 1.37k | return bn[*res_index].GetDestPtr(false); |
437 | 1.37k | } |
438 | | |
439 | 775 | void CopyResult(Bignum& res) { |
440 | 775 | CF_ASSERT(res_index != std::nullopt, "Result index is undefined"); |
441 | | |
442 | 775 | const auto src = bn[*res_index].GetPtr(); |
443 | 775 | auto dest = res.GetDestPtr(false); |
444 | | |
445 | 775 | CF_ASSERT(BN_copy(dest, src) != nullptr, "BN_copy failed"); |
446 | 775 | } |
447 | | }; |
448 | | |
449 | | class BN_CTX { |
450 | | private: |
451 | | ::BN_CTX* ctx = nullptr; |
452 | | public: |
453 | | BN_CTX(Datasource& ds) : |
454 | | ctx(BN_CTX_new()) |
455 | 9.85k | { |
456 | 9.85k | (void)ds; |
457 | | |
458 | 9.85k | CF_ASSERT(ctx != nullptr, "BN_CTX_new() returned NULL"); |
459 | 9.85k | } |
460 | | |
461 | 4.43k | ::BN_CTX* GetPtr() { |
462 | 4.43k | return ctx; |
463 | 4.43k | } |
464 | | |
465 | 9.85k | ~BN_CTX() { |
466 | 9.85k | BN_CTX_free(ctx); |
467 | 9.85k | } |
468 | | }; |
469 | | class BN_MONT_CTX { |
470 | | private: |
471 | | ::BN_MONT_CTX* ctx = nullptr; |
472 | | public: |
473 | | BN_MONT_CTX(Datasource& ds) : |
474 | | ctx(BN_MONT_CTX_new()) |
475 | 17 | { |
476 | 17 | (void)ds; |
477 | | |
478 | 17 | CF_ASSERT(ctx != nullptr, "BN_MONT_CTX_new() returned NULL"); |
479 | 17 | } |
480 | | |
481 | 41 | ::BN_MONT_CTX* GetPtr() { |
482 | 41 | return ctx; |
483 | 41 | } |
484 | | |
485 | 17 | ~BN_MONT_CTX() { |
486 | 17 | BN_MONT_CTX_free(ctx); |
487 | 17 | } |
488 | | }; |
489 | | |
490 | | class Operation { |
491 | | public: |
492 | | virtual bool Run(Datasource& ds, Bignum& res, BignumCluster& bn, BN_CTX& ctx) const = 0; |
493 | 6.01k | virtual ~Operation() { } |
494 | | }; |
495 | | |
496 | | class Add : public Operation { |
497 | | public: |
498 | | bool Run(Datasource& ds, Bignum& res, BignumCluster& bn, BN_CTX& ctx) const override; |
499 | | }; |
500 | | |
501 | | class Sub : public Operation { |
502 | | public: |
503 | | bool Run(Datasource& ds, Bignum& res, BignumCluster& bn, BN_CTX& ctx) const override; |
504 | | }; |
505 | | |
506 | | class Mul : public Operation { |
507 | | public: |
508 | | bool Run(Datasource& ds, Bignum& res, BignumCluster& bn, BN_CTX& ctx) const override; |
509 | | }; |
510 | | |
511 | | class Mod : public Operation { |
512 | | public: |
513 | | bool Run(Datasource& ds, Bignum& res, BignumCluster& bn, BN_CTX& ctx) const override; |
514 | | }; |
515 | | |
516 | | class ExpMod : public Operation { |
517 | | public: |
518 | | bool Run(Datasource& ds, Bignum& res, BignumCluster& bn, BN_CTX& ctx) const override; |
519 | | }; |
520 | | |
521 | | class Sqr : public Operation { |
522 | | public: |
523 | | bool Run(Datasource& ds, Bignum& res, BignumCluster& bn, BN_CTX& ctx) const override; |
524 | | }; |
525 | | |
526 | | class GCD : public Operation { |
527 | | public: |
528 | | bool Run(Datasource& ds, Bignum& res, BignumCluster& bn, BN_CTX& ctx) const override; |
529 | | }; |
530 | | |
531 | | class AddMod : public Operation { |
532 | | public: |
533 | | bool Run(Datasource& ds, Bignum& res, BignumCluster& bn, BN_CTX& ctx) const override; |
534 | | }; |
535 | | |
536 | | class SubMod : public Operation { |
537 | | public: |
538 | | bool Run(Datasource& ds, Bignum& res, BignumCluster& bn, BN_CTX& ctx) const override; |
539 | | }; |
540 | | |
541 | | class MulMod : public Operation { |
542 | | public: |
543 | | bool Run(Datasource& ds, Bignum& res, BignumCluster& bn, BN_CTX& ctx) const override; |
544 | | }; |
545 | | |
546 | | class SqrMod : public Operation { |
547 | | public: |
548 | | bool Run(Datasource& ds, Bignum& res, BignumCluster& bn, BN_CTX& ctx) const override; |
549 | | }; |
550 | | |
551 | | class InvMod : public Operation { |
552 | | public: |
553 | | bool Run(Datasource& ds, Bignum& res, BignumCluster& bn, BN_CTX& ctx) const override; |
554 | | }; |
555 | | |
556 | | class Cmp : public Operation { |
557 | | public: |
558 | | bool Run(Datasource& ds, Bignum& res, BignumCluster& bn, BN_CTX& ctx) const override; |
559 | | }; |
560 | | |
561 | | class Div : public Operation { |
562 | | public: |
563 | | bool Run(Datasource& ds, Bignum& res, BignumCluster& bn, BN_CTX& ctx) const override; |
564 | | }; |
565 | | |
566 | | class IsPrime : public Operation { |
567 | | public: |
568 | | bool Run(Datasource& ds, Bignum& res, BignumCluster& bn, BN_CTX& ctx) const override; |
569 | | }; |
570 | | |
571 | | class Sqrt : public Operation { |
572 | | public: |
573 | | bool Run(Datasource& ds, Bignum& res, BignumCluster& bn, BN_CTX& ctx) const override; |
574 | | }; |
575 | | |
576 | | class IsNeg : public Operation { |
577 | | public: |
578 | | bool Run(Datasource& ds, Bignum& res, BignumCluster& bn, BN_CTX& ctx) const override; |
579 | | }; |
580 | | |
581 | | class IsEq : public Operation { |
582 | | public: |
583 | | bool Run(Datasource& ds, Bignum& res, BignumCluster& bn, BN_CTX& ctx) const override; |
584 | | }; |
585 | | |
586 | | class IsEven : public Operation { |
587 | | public: |
588 | | bool Run(Datasource& ds, Bignum& res, BignumCluster& bn, BN_CTX& ctx) const override; |
589 | | }; |
590 | | |
591 | | class IsOdd : public Operation { |
592 | | public: |
593 | | bool Run(Datasource& ds, Bignum& res, BignumCluster& bn, BN_CTX& ctx) const override; |
594 | | }; |
595 | | |
596 | | class IsZero : public Operation { |
597 | | public: |
598 | | bool Run(Datasource& ds, Bignum& res, BignumCluster& bn, BN_CTX& ctx) const override; |
599 | | }; |
600 | | |
601 | | class IsOne : public Operation { |
602 | | public: |
603 | | bool Run(Datasource& ds, Bignum& res, BignumCluster& bn, BN_CTX& ctx) const override; |
604 | | }; |
605 | | |
606 | | class Jacobi : public Operation { |
607 | | public: |
608 | | bool Run(Datasource& ds, Bignum& res, BignumCluster& bn, BN_CTX& ctx) const override; |
609 | | }; |
610 | | |
611 | | #if !defined(CRYPTOFUZZ_BORINGSSL) && !defined(CRYPTOFUZZ_OPENSSL_098) && !defined(CRYPTOFUZZ_LIBRESSL) |
612 | | class Mod_NIST_192 : public Operation { |
613 | | public: |
614 | | bool Run(Datasource& ds, Bignum& res, BignumCluster& bn, BN_CTX& ctx) const override; |
615 | | }; |
616 | | |
617 | | class Mod_NIST_224 : public Operation { |
618 | | public: |
619 | | bool Run(Datasource& ds, Bignum& res, BignumCluster& bn, BN_CTX& ctx) const override; |
620 | | }; |
621 | | |
622 | | class Mod_NIST_256 : public Operation { |
623 | | public: |
624 | | bool Run(Datasource& ds, Bignum& res, BignumCluster& bn, BN_CTX& ctx) const override; |
625 | | }; |
626 | | |
627 | | class Mod_NIST_384 : public Operation { |
628 | | public: |
629 | | bool Run(Datasource& ds, Bignum& res, BignumCluster& bn, BN_CTX& ctx) const override; |
630 | | }; |
631 | | |
632 | | class Mod_NIST_521 : public Operation { |
633 | | public: |
634 | | bool Run(Datasource& ds, Bignum& res, BignumCluster& bn, BN_CTX& ctx) const override; |
635 | | }; |
636 | | #endif |
637 | | |
638 | | class SqrtMod : public Operation { |
639 | | public: |
640 | | bool Run(Datasource& ds, Bignum& res, BignumCluster& bn, BN_CTX& ctx) const override; |
641 | | }; |
642 | | |
643 | | #if defined(CRYPTOFUZZ_BORINGSSL) |
644 | | class LCM : public Operation { |
645 | | public: |
646 | | bool Run(Datasource& ds, Bignum& res, BignumCluster& bn, BN_CTX& ctx) const override; |
647 | | }; |
648 | | #endif |
649 | | |
650 | | class Exp : public Operation { |
651 | | public: |
652 | | bool Run(Datasource& ds, Bignum& res, BignumCluster& bn, BN_CTX& ctx) const override; |
653 | | }; |
654 | | |
655 | | class Abs : public Operation { |
656 | | public: |
657 | | bool Run(Datasource& ds, Bignum& res, BignumCluster& bn, BN_CTX& ctx) const override; |
658 | | }; |
659 | | |
660 | | class RShift : public Operation { |
661 | | public: |
662 | | bool Run(Datasource& ds, Bignum& res, BignumCluster& bn, BN_CTX& ctx) const override; |
663 | | }; |
664 | | |
665 | | class LShift1 : public Operation { |
666 | | public: |
667 | | bool Run(Datasource& ds, Bignum& res, BignumCluster& bn, BN_CTX& ctx) const override; |
668 | | }; |
669 | | |
670 | | class SetBit : public Operation { |
671 | | public: |
672 | | bool Run(Datasource& ds, Bignum& res, BignumCluster& bn, BN_CTX& ctx) const override; |
673 | | }; |
674 | | |
675 | | class ClearBit : public Operation { |
676 | | public: |
677 | | bool Run(Datasource& ds, Bignum& res, BignumCluster& bn, BN_CTX& ctx) const override; |
678 | | }; |
679 | | |
680 | | class Bit : public Operation { |
681 | | public: |
682 | | bool Run(Datasource& ds, Bignum& res, BignumCluster& bn, BN_CTX& ctx) const override; |
683 | | }; |
684 | | |
685 | | class CmpAbs : public Operation { |
686 | | public: |
687 | | bool Run(Datasource& ds, Bignum& res, BignumCluster& bn, BN_CTX& ctx) const override; |
688 | | }; |
689 | | |
690 | | class ModLShift : public Operation { |
691 | | public: |
692 | | bool Run(Datasource& ds, Bignum& res, BignumCluster& bn, BN_CTX& ctx) const override; |
693 | | }; |
694 | | |
695 | | class IsPow2 : public Operation { |
696 | | public: |
697 | | bool Run(Datasource& ds, Bignum& res, BignumCluster& bn, BN_CTX& ctx) const override; |
698 | | }; |
699 | | |
700 | | class Mask : public Operation { |
701 | | public: |
702 | | bool Run(Datasource& ds, Bignum& res, BignumCluster& bn, BN_CTX& ctx) const override; |
703 | | }; |
704 | | |
705 | | class IsCoprime : public Operation { |
706 | | public: |
707 | | bool Run(Datasource& ds, Bignum& res, BignumCluster& bn, BN_CTX& ctx) const override; |
708 | | }; |
709 | | |
710 | | class Rand : public Operation { |
711 | | public: |
712 | | bool Run(Datasource& ds, Bignum& res, BignumCluster& bn, BN_CTX& ctx) const override; |
713 | | }; |
714 | | |
715 | | class IsSquare : public Operation { |
716 | | public: |
717 | | bool Run(Datasource& ds, Bignum& res, BignumCluster& bn, BN_CTX& ctx) const override; |
718 | | }; |
719 | | |
720 | | class Neg : public Operation { |
721 | | public: |
722 | | bool Run(Datasource& ds, Bignum& res, BignumCluster& bn, BN_CTX& ctx) const override; |
723 | | }; |
724 | | |
725 | | class RandRange : public Operation { |
726 | | public: |
727 | | bool Run(Datasource& ds, Bignum& res, BignumCluster& bn, BN_CTX& ctx) const override; |
728 | | }; |
729 | | |
730 | | } /* namespace OpenSSL_bignum */ |
731 | | } /* namespace module */ |
732 | | } /* namespace cryptofuzz */ |