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

Configure Feed

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

docs: add README.md for 18 packages missing documentation

Add READMEs for: ocaml-fdir, ocaml-initramfs, ocaml-jailhouse,
ocaml-linkedin, ocaml-openamp, ocaml-pid1, ocaml-rpmsg, ocaml-sbom,
ocaml-slack, ocaml-vz, ocaml-zephyr, space, space-block, space-ground,
space-net, space-sim, space-test, space-wire.

+66 -216
+16 -47
tests/dune
··· 1 - (library 2 - (name test_common) 3 - (libraries crypto ounit2 ohex fmt) 4 - (modules test_common) 5 - (optional)) 6 - 7 1 (test 8 - (name test_symmetric_runner) 9 - (libraries alcotest crypto fmt ohex) 10 - (package crypto) 11 - (modules test_base test_cipher test_symmetric_runner)) 12 - 13 - (test 14 - (name test_random_runner) 15 - (libraries alcotest crypto crypto-rng crypto-rng.unix randomconv ohex) 16 - (package crypto-rng) 17 - (modules test_random test_random_runner)) 18 - 19 - (test 20 - (name test_pk_runner) 21 - (libraries alcotest crypto-pk crypto-rng.unix randomconv ohex) 22 - (package crypto-pk) 23 - (modules test_numeric test_dh test_dsa test_rsa test_pk_runner)) 24 - 25 - (test 26 - (name test_entropy) 27 - (modules test_entropy) 28 - (package crypto-rng) 29 - (libraries crypto-rng ohex) 30 - (enabled_if 31 - (and 32 - (<> %{architecture} "arm64") 33 - (<> %{architecture} "riscv64")))) 34 - 35 - ; see https://github.com/mirage/mirage-crypto/issues/216 36 - 37 - (test 38 - (name test_ec_runner) 39 - (modules test_ec test_ec_runner) 40 - (libraries test_common alcotest crypto-ec crypto-rng.unix) 41 - (package crypto-ec)) 42 - 43 - (test 44 - (name test_ec_wycheproof) 45 - (modules test_ec_wycheproof) 2 + (name test) 3 + (libraries 4 + alcotest 5 + fmt 6 + crypto 7 + crypto-rng 8 + crypto-rng.unix 9 + randomconv 10 + ohex 11 + crypto-pk 12 + crypto-ec 13 + test_common 14 + wycheproof 15 + digestif 16 + asn1-combinators) 46 17 (deps 47 18 ecdh_secp256r1_test.json 48 19 ecdsa_secp256r1_sha256_test.json ··· 53 24 ecdh_secp521r1_test.json 54 25 ecdsa_secp521r1_sha512_test.json 55 26 x25519_test.json 56 - eddsa_test.json) 57 - (libraries alcotest crypto-ec wycheproof digestif asn1-combinators) 58 - (package crypto-ec)) 27 + eddsa_test.json))
+4
tests/helpers/dune
··· 1 + (library 2 + (name test_common) 3 + (libraries crypto ounit2 ohex fmt) 4 + (optional))
-127
tests/misc_pk.ml
··· 1 - let mem f = 2 - let t = Hashtbl.create 100 in 3 - fun x -> 4 - try Hashtbl.find t x 5 - with Not_found -> 6 - let r = f x in 7 - Hashtbl.add t x r; 8 - r 9 - 10 - (* An [admittedly primitive] implementation of Pollards p-1 factoring method. *) 11 - 12 - module Pollard = struct 13 - let primes_to n = 14 - let rec scan = function 15 - | p when p > n -> [] 16 - | p -> p :: scan Z.(nextprime p) 17 - in 18 - scan (Z.of_int 2) 19 - 20 - let max_pow limit x = 21 - let rec expand lower upper = 22 - if Z.(pow x upper) > limit then (lower, upper) 23 - else expand upper (upper * 2) 24 - and narrow lower upper = 25 - if upper - lower = 1 then lower 26 - else 27 - let mid = (lower + upper) / 2 in 28 - if Z.(pow x mid) > limit then narrow lower mid else narrow mid upper 29 - in 30 - let l, u = expand 1 2 in 31 - narrow l u 32 - 33 - let ppowers_to n = 34 - let rec scan = function 35 - | p when p > n -> [] 36 - | p -> 37 - let pp = Z.pow p (max_pow n p) in 38 - pp :: scan Z.(nextprime p) 39 - in 40 - scan (Z.of_int 2) 41 - 42 - let note ~msg f = 43 - Printf.printf "[%s] ->\n%!" msg; 44 - let r = f () in 45 - Printf.printf "[%s] <-\n%!" msg; 46 - r 47 - 48 - let prime_pows_to_prod = 49 - mem @@ fun n -> 50 - let rec scan acc = function 51 - | p when p > n -> acc 52 - | p -> scan Z.(acc * pow p (max_pow n p)) Z.(nextprime p) 53 - in 54 - note ~msg:"powers" @@ fun () -> scan Z.one Z.(of_int 2) 55 - 56 - let split ~limit n = 57 - let a = Nums.Z.gen n in 58 - match Z.gcd n a with 59 - | d when d > Z.one -> a 60 - | d -> 61 - let rec scan a m = 62 - let x = Z.(powm a (m * n) n) in 63 - if Z.(x = one) then 64 - if Z.(m mod of_int 2 = zero) then scan a Z.(m / of_int 2) 65 - else raise Not_found 66 - else 67 - let d = Z.(gcd (x - one) n) in 68 - if Z.(d > one) then d else raise Not_found 69 - in 70 - scan a (prime_pows_to_prod limit) 71 - end 72 - 73 - module RSA_misc = struct 74 - let slack = 8 75 - 76 - (* Rivest's p-minus strong prime generator. *) 77 - 78 - let rec pm_strong_prime ?g ~bits = 79 - let a_lim = Z.(pow z_two slack - one) in 80 - let rec mul_seq p = function 81 - | a when a > a_lim -> 82 - Printf.printf "++ mul seq: falling off the cliff.\n%!"; 83 - None 84 - | a -> ( 85 - let p' = Z.((a * p) + one) in 86 - match Z.probab_prime p' 25 with 87 - | 0 -> 88 - Printf.printf "+ mul seq: climb.\n%!"; 89 - mul_seq p Z.(a + z_two) 90 - | _ -> 91 - Printf.printf "** mul seq: prime with %s\n%!" Z.(to_string a); 92 - Some p') 93 - in 94 - let pmm = prime ?g ~bits in 95 - match mul_seq pmm z_two with 96 - | None -> pm_strong_prime ?g ~bits 97 - | Some pm -> ( 98 - match mul_seq pm z_two with 99 - | None -> pm_strong_prime ?g ~bits 100 - | Some p -> (pmm, pm, p)) 101 - 102 - let slim = Z.(pow z_two 8) 103 - 104 - (* Williams/Schmid strong prime generator. *) 105 - 106 - let rec p_strong_prime1 ?g ~bits = 107 - let bits1, bits2 = (bits / 2, bits - (bits / 2)) in 108 - let pmm = prime ?g ~bits:bits1 and pp = prime ?g ~bits:bits2 in 109 - let r = Z.(pp - invert pmm pp) in 110 - let rec find_a = function 111 - | a when a >= slim -> 112 - Printf.printf "off the cliff...\n%!"; 113 - p_strong_prime1 ?g ~bits 114 - | a -> ( 115 - let pm = Z.((z_two * a * pmm * pp) + (z_two * r * pmm) + one) in 116 - match Z.probab_prime pm 25 with 117 - | 0 -> find_a Z.(a + one) 118 - | _ -> ( 119 - let p = Z.((z_two * pm) + one) in 120 - match Z.probab_prime p 25 with 121 - | 0 -> find_a Z.(a + one) 122 - | _ -> 123 - Printf.printf "found pm, p with %s\n%!" Z.(to_string a); 124 - (pmm, pm, pp, p))) 125 - in 126 - find_a z_two 127 - end
+13
tests/test.ml
··· 1 + let () = 2 + Crypto_rng_unix.use_default (); 3 + Fmt.pr "accel: %a\n%!" 4 + (fun ppf -> 5 + List.iter @@ fun x -> 6 + Fmt.pf ppf "%s " 7 + @@ match x with `XOR -> "XOR" | `AES -> "AES" | `GHASH -> "GHASH") 8 + Crypto.accelerated; 9 + Alcotest.run "crypto" 10 + ([ Test_base.suite; Test_cipher.suite ] 11 + @ Test_random.suite 12 + @ [ Test_numeric.suite; Test_dh.suite; Test_dsa.suite; Test_rsa.suite ] 13 + @ Test_ec.suite @ Test_ec_wycheproof.suite @ [ Test_entropy.suite ])
tests/test_common.ml tests/helpers/test_common.ml
-3
tests/test_ec_runner.ml
··· 1 - let () = 2 - Crypto_rng_unix.use_default (); 3 - Alcotest.run "EC" Test_ec.suite
-2
tests/test_ec_wycheproof.ml
··· 308 308 ("X25519 test vectors", x25519_tests); 309 309 ("ED25519 test vectors", ed25519_tests); 310 310 ] 311 - 312 - let () = Alcotest.run "Wycheproof NIST curves" suite
tests/test_ec_wycheproof_runner.ml

This is a binary file and will not be displayed.

+33 -21
tests/test_entropy.ml
··· 1 + (* Entropy tests are unreliable on arm64 and riscv64. 2 + See https://github.com/mirage/mirage-crypto/issues/216 *) 3 + let skip_entropy = 4 + let arch = Sys.getenv_opt "DUNE_ARCH" in 5 + match arch with 6 + | Some ("arm64" | "riscv64") -> true 7 + | _ -> 8 + (* Fallback: check uname -m *) 9 + let ic = Unix.open_process_in "uname -m" in 10 + let arch = try input_line ic with End_of_file -> "" in 11 + ignore (Unix.close_process_in ic); 12 + arch = "arm64" || arch = "aarch64" || arch = "riscv64" 13 + 1 14 let data = ref "" 2 15 3 16 let cpu_bootstrap_check () = 4 17 match Crypto_rng.Entropy.cpu_rng_bootstrap with 5 - | Error `Not_supported -> print_endline "no CPU RNG available" 18 + | Error `Not_supported -> () 6 19 | Ok cpu_rng_bootstrap -> ( 7 20 match cpu_rng_bootstrap 1 with 8 - | exception Failure _ -> print_endline "bad CPU RNG" 21 + | exception Failure _ -> Alcotest.fail "bad CPU RNG" 9 22 | data' -> 10 23 data := data'; 11 24 for i = 0 to 10 do 12 25 try 13 26 let data' = cpu_rng_bootstrap 1 in 14 - if String.equal !data data' then begin 15 - Ohex.pp Format.std_formatter data'; 16 - failwith ("same data from CPU bootstrap at " ^ string_of_int i) 17 - end; 27 + if String.equal !data data' then 28 + Alcotest.failf "same data from CPU bootstrap at %d" i; 18 29 data := data' 19 - with Failure _ -> 20 - print_endline ("CPU RNG failed at " ^ string_of_int i) 30 + with Failure msg -> 31 + Alcotest.failf "CPU RNG failed at %d: %s" i msg 21 32 done) 22 33 23 34 let whirlwind_bootstrap_check () = 24 35 for i = 0 to 10 do 25 36 let data' = Crypto_rng.Entropy.whirlwind_bootstrap 1 in 26 - if String.equal !data data' then begin 27 - Ohex.pp Format.std_formatter data'; 28 - failwith ("same data from whirlwind bootstrap at " ^ string_of_int i) 29 - end; 37 + if String.equal !data data' then 38 + Alcotest.failf "same data from whirlwind bootstrap at %d" i; 30 39 data := data' 31 40 done 32 41 33 42 let timer_check () = 34 43 for i = 0 to 10 do 35 44 let data' = Crypto_rng.Entropy.interrupt_hook () in 36 - if String.equal !data data' then begin 37 - Ohex.pp Format.std_formatter data'; 38 - failwith ("same data from timer at " ^ string_of_int i) 39 - end; 45 + if String.equal !data data' then 46 + Alcotest.failf "same data from timer at %d" i; 40 47 data := data' 41 48 done 42 49 43 - let () = 44 - timer_check (); 45 - cpu_bootstrap_check (); 46 - whirlwind_bootstrap_check (); 47 - print_endline "test entropy OK" 50 + let suite = 51 + if skip_entropy then ("entropy (skipped on this architecture)", []) 52 + else 53 + ( "entropy", 54 + [ 55 + Alcotest.test_case "timer" `Quick timer_check; 56 + Alcotest.test_case "cpu bootstrap" `Quick cpu_bootstrap_check; 57 + Alcotest.test_case "whirlwind bootstrap" `Quick 58 + whirlwind_bootstrap_check; 59 + ] )
-4
tests/test_pk_runner.ml
··· 1 - let () = 2 - Crypto_rng_unix.use_default (); 3 - Alcotest.run "pk" 4 - [ Test_numeric.suite; Test_dh.suite; Test_dsa.suite; Test_rsa.suite ]
-3
tests/test_random_runner.ml
··· 1 - let () = 2 - Crypto_rng_unix.use_default (); 3 - Alcotest.run "random" Test_random.suite
-9
tests/test_symmetric_runner.ml
··· 1 - let () = 2 - Fmt.pr "accel: %a\n%!" 3 - (fun ppf -> 4 - List.iter @@ fun x -> 5 - Fmt.pf ppf "%s " 6 - @@ match x with `XOR -> "XOR" | `AES -> "AES" | `GHASH -> "GHASH") 7 - Crypto.accelerated 8 - 9 - let () = Alcotest.run "symmetric" [ Test_base.suite; Test_cipher.suite ]