upstream: https://github.com/mirage/mirage-crypto
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix(lint): add gen_corpus.ml and runtest rules to 5 fuzz directories

E718: Add gen_corpus.ml to ocaml-crypto, ocaml-csrf, ocaml-git,
ocaml-github-oauth, ocaml-gpt
E724: Add (rule (alias runtest) ...) for property-based testing

+40 -14
+12 -13
bench/speed.ml
··· 42 42 let mb = 1024. *. 1024. 43 43 44 44 let throughput title f = 45 - Printf.printf "\n* [%s]\n%!" title; 45 + Fmt.pr "\n* [%s]\n%!" title; 46 46 sizes 47 47 |> List.iter @@ fun size -> 48 48 Gc.full_major (); 49 49 let iters, time, bw = burn f size in 50 - Printf.printf " % 5d: %04f MB/s (%d iters in %.03f s)\n%!" size 51 - (bw /. mb) iters time 50 + Fmt.pr " % 5d: %04f MB/s (%d iters in %.03f s)\n%!" size (bw /. mb) 51 + iters time 52 52 53 53 let throughput_into ?(add = 0) title f = 54 - Printf.printf "\n* [%s]\n%!" title; 54 + Fmt.pr "\n* [%s]\n%!" title; 55 55 sizes 56 56 |> List.iter @@ fun size -> 57 57 Gc.full_major (); 58 58 let dst = Bytes.create (size + add) in 59 59 let iters, time, bw = burn (f dst) size in 60 - Printf.printf " % 5d: %04f MB/s (%d iters in %.03f s)\n%!" size 61 - (bw /. mb) iters time 60 + Fmt.pr " % 5d: %04f MB/s (%d iters in %.03f s)\n%!" size (bw /. mb) 61 + iters time 62 62 63 63 let count_period = 10. 64 64 ··· 71 71 (iters, time) 72 72 73 73 let count title f to_str args = 74 - Printf.printf "\n* [%s]\n%!" title; 74 + Fmt.pr "\n* [%s]\n%!" title; 75 75 args 76 76 |> List.iter @@ fun arg -> 77 77 Gc.full_major (); 78 78 let iters, time = count f arg in 79 - Printf.printf " %s: %.03f ops per second (%d iters in %.03f)\n%!" 80 - (to_str arg) 79 + Fmt.pr " %s: %.03f ops per second (%d iters in %.03f)\n%!" (to_str arg) 81 80 (float iters /. time) 82 81 iters time 83 82 ··· 621 620 ] 622 621 623 622 let help () = 624 - Printf.printf "available benchmarks:\n "; 625 - List.iter (fun (n, _) -> Printf.printf "%s " n) benchmarks; 626 - Printf.printf "\n%!" 623 + Fmt.pr "available benchmarks:\n "; 624 + List.iter (fun (n, _) -> Fmt.pr "%s " n) benchmarks; 625 + Fmt.pr "\n%!" 627 626 628 627 let runv fs = 629 628 Format.printf "accel: %a\n%!" 630 629 (fun ppf -> 631 630 List.iter @@ fun x -> 632 - Format.fprintf ppf "%s " 631 + Fmt.pf ppf "%s " 633 632 @@ match x with `XOR -> "XOR" | `AES -> "AES" | `GHASH -> "GHASH") 634 633 accelerated; 635 634 Time.warmup ();
+12 -1
fuzz/dune
··· 8 8 (modules fuzz_crypto) 9 9 (libraries crypto crowbar)) 10 10 11 + (executable 12 + (name gen_corpus) 13 + (modules gen_corpus) 14 + (libraries unix)) 15 + 16 + (rule 17 + (alias runtest) 18 + (deps fuzz_crypto.exe) 19 + (action 20 + (run %{exe:fuzz_crypto.exe}))) 21 + 11 22 (rule 12 23 (alias fuzz) 13 24 (deps fuzz_crypto.exe) 14 25 (action 15 - (run %{exe:fuzz_crypto.exe}))) 26 + (echo "AFL fuzzer built: %{exe:fuzz_crypto.exe}\n")))
+16
fuzz/gen_corpus.ml
··· 1 + (** Generate seed corpus for fuzz testing. *) 2 + 3 + let () = 4 + (try Unix.mkdir "corpus" 0o755 5 + with Unix.Unix_error (Unix.EEXIST, _, _) -> ()); 6 + let write name data = 7 + let oc = open_out_bin (Filename.concat "corpus" name) in 8 + output_string oc data; 9 + close_out oc 10 + in 11 + write "seed_000" (String.make 16 '\x00'); 12 + write "seed_001" (String.make 32 '\xff'); 13 + write "seed_002" (String.init 16 (fun i -> Char.chr (i * 17))); 14 + write "seed_003" (String.init 32 (fun i -> Char.chr (i * 8))); 15 + write "seed_004" (String.make 24 '\xaa'); 16 + write "seed_005" "0123456789abcdef"