Add a relatively simple mostly-const-fn bigint math implementation
[dnssec-prover] / fuzz / src / bigint_math.rs
1 // This file is Copyright its original authors, visible in version control
2 // history.
3 //
4 // This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
5 // or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
7 // You may not use this file except in accordance with one or both of these
8 // licenses.
9
10 #![cfg_attr(feature = "libfuzzer_fuzz", no_main)]
11
12 #[cfg(not(fuzzing))]
13 compile_error!("Fuzz targets need cfg=fuzzing");
14
15 extern crate dnssec_prover;
16 use dnssec_prover::crypto::bigint::fuzz_math;
17
18 #[cfg(feature = "afl")]
19 #[macro_use] extern crate afl;
20 #[cfg(feature = "afl")]
21 fn main() {
22         fuzz!(|data| {
23                 fuzz_math(data);
24         });
25 }
26
27 #[cfg(feature = "honggfuzz")]
28 #[macro_use] extern crate honggfuzz;
29 #[cfg(feature = "honggfuzz")]
30 fn main() {
31         loop {
32                 fuzz!(|data| {
33                         fuzz_math(data);
34                 });
35         }
36 }
37
38 #[cfg(feature = "libfuzzer_fuzz")]
39 #[macro_use] extern crate libfuzzer_sys;
40 #[cfg(feature = "libfuzzer_fuzz")]
41 fuzz_target!(|data: &[u8]| {
42         fuzz_math(data);
43 });
44
45 #[cfg(feature = "stdin_fuzz")]
46 fn main() {
47         use std::io::Read;
48
49         let mut data = Vec::with_capacity(8192);
50         std::io::stdin().read_to_end(&mut data).unwrap();
51         fuzz_math(&data);
52 }
53
54 #[test]
55 fn run_test_cases() {
56         use std::fs;
57         use std::io::Read;
58
59         if let Ok(tests) = fs::read_dir("test_cases/bigint_math") {
60                 for test in tests {
61                         let mut data: Vec<u8> = Vec::new();
62                         let path = test.unwrap().path();
63                         fs::File::open(&path).unwrap().read_to_end(&mut data).unwrap();
64
65                         fuzz_math(&data);
66                 }
67         }
68 }