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): resolve E331 redundant function prefixes in ocaml-crypto

- make_key -> pad in fuzz_crypto.ml (key would shadow local variables)
- make_ecdh_test -> ecdh_test in test_ec_wycheproof.ml
- make_ecdsa_test -> ecdsa_test in test_ec_wycheproof.ml
- get_result -> result in wycheproof.ml

+21 -21
+12 -12
fuzz/fuzz_crypto.ml
··· 14 14 let aes_block_size = 16 15 15 16 16 (* Generate a padded key of valid size *) 17 - let make_key size input = 17 + let pad size input = 18 18 if String.length input >= size then String.sub input 0 size 19 19 else input ^ String.make (size - String.length input) '\x00' 20 20 ··· 22 22 let test_aes_ecb_roundtrip key_input plaintext = 23 23 List.iter 24 24 (fun key_size -> 25 - let key_str = make_key key_size key_input in 25 + let key_str = pad key_size key_input in 26 26 let key = Crypto.AES.ECB.of_secret key_str in 27 27 (* Pad plaintext to block size *) 28 28 let pt_len = String.length plaintext in ··· 43 43 let test_aes_cbc_roundtrip key_input iv_input plaintext = 44 44 List.iter 45 45 (fun key_size -> 46 - let key_str = make_key key_size key_input in 46 + let key_str = pad key_size key_input in 47 47 let key = Crypto.AES.CBC.of_secret key_str in 48 - let iv = make_key aes_block_size iv_input in 48 + let iv = pad aes_block_size iv_input in 49 49 (* Pad plaintext to block size *) 50 50 let pt_len = String.length plaintext in 51 51 let padded_len = ··· 67 67 else 68 68 List.iter 69 69 (fun key_size -> 70 - let key_str = make_key key_size key_input in 70 + let key_str = pad key_size key_input in 71 71 let key = Crypto.AES.CTR.of_secret key_str in 72 - let ctr_str = make_key aes_block_size ctr_input in 72 + let ctr_str = pad aes_block_size ctr_input in 73 73 let ctr = Crypto.AES.CTR.ctr_of_octets ctr_str in 74 74 let ciphertext = Crypto.AES.CTR.encrypt ~key ~ctr plaintext in 75 75 let decrypted = Crypto.AES.CTR.decrypt ~key ~ctr ciphertext in ··· 80 80 let test_aes_gcm_roundtrip key_input nonce_input plaintext = 81 81 List.iter 82 82 (fun key_size -> 83 - let key_str = make_key key_size key_input in 83 + let key_str = pad key_size key_input in 84 84 let key = Crypto.AES.GCM.of_secret key_str in 85 85 (* GCM nonce should be 12 bytes for optimal performance *) 86 - let nonce = make_key 12 nonce_input in 86 + let nonce = pad 12 nonce_input in 87 87 let adata = "" in 88 88 let result = 89 89 Crypto.AES.GCM.authenticate_encrypt ~key ~nonce ~adata plaintext ··· 100 100 else 101 101 List.iter 102 102 (fun key_size -> 103 - let key_str = make_key key_size key_input in 103 + let key_str = pad key_size key_input in 104 104 let key = Crypto.AES.CCM16.of_secret key_str in 105 105 (* CCM nonce should be 7-13 bytes; use 12 *) 106 - let nonce = make_key 12 nonce_input in 106 + let nonce = pad 12 nonce_input in 107 107 let adata = "" in 108 108 let result = 109 109 Crypto.AES.CCM16.authenticate_encrypt ~key ~nonce ~adata plaintext ··· 119 119 (* Test ChaCha20-Poly1305 roundtrip *) 120 120 let test_chacha20_poly1305_roundtrip key_input nonce_input plaintext = 121 121 (* ChaCha20 key is 32 bytes, nonce is 12 bytes *) 122 - let key_str = make_key 32 key_input in 122 + let key_str = pad 32 key_input in 123 123 let key = Crypto.Chacha20.of_secret key_str in 124 - let nonce = make_key 12 nonce_input in 124 + let nonce = pad 12 nonce_input in 125 125 let adata = "" in 126 126 let result = 127 127 Crypto.Chacha20.authenticate_encrypt ~key ~nonce ~adata plaintext
+4 -4
tests/test_ec_wycheproof.ml
··· 109 109 110 110 type strategy = Test of test | Invalid_test of invalid_test | Skip 111 111 112 - let make_ecdh_test curve (test : ecdh_test) = 112 + let ecdh_test curve (test : ecdh_test) = 113 113 let ignored_flags = [ "UnnamedCurve" ] in 114 114 let curve_compression_test curve = 115 115 let curves = [ "secp256r1"; "secp384r1"; "secp521r1" ] in ··· 131 131 132 132 let to_ecdh_tests curve (x : ecdh_test) = 133 133 let name = Printf.sprintf "%d - %s" x.tc_id x.comment in 134 - match make_ecdh_test curve x with 134 + match ecdh_test curve x with 135 135 | Ok (Test t) -> [ (name, `Quick, interpret_test ~tc_id:x.tc_id curve t) ] 136 136 | Ok (Invalid_test t) -> [ (name, `Quick, interpret_invalid_test curve t) ] 137 137 | Ok Skip -> [] ··· 147 147 List.concat_map (to_ecdh_tests group.curve) group.tests) 148 148 groups 149 149 150 - let make_ecdsa_test curve key hash (tst : dsa_test) = 150 + let ecdsa_test curve key hash (tst : dsa_test) = 151 151 let name = Printf.sprintf "%d - %s" tst.tc_id tst.comment in 152 152 let size = len curve in 153 153 let msg = ··· 197 197 (name, `Quick, f) 198 198 199 199 let to_ecdsa_tests (x : ecdsa_test_group) = 200 - List.map (make_ecdsa_test x.key.curve x.key.uncompressed x.sha) x.tests 200 + List.map (ecdsa_test x.key.curve x.key.uncompressed x.sha) x.tests 201 201 202 202 let ecdsa_tests file = 203 203 let data = load_file_exn file in
+5 -5
tests/wycheproof/wycheproof.ml
··· 367 367 t.test_groups) 368 368 |> Jsont.Object.skip_unknown |> Jsont.Object.finish 369 369 370 - let get_result = function Ok x -> x | Error s -> failwith s 370 + let result = function Ok x -> x | Error s -> failwith s 371 371 372 372 let load_file_exn path = 373 373 let content = In_channel.with_open_bin path In_channel.input_all in 374 - Jsont_bytesrw.decode_string test_file_jsont content |> get_result 374 + Jsont_bytesrw.decode_string test_file_jsont content |> result 375 375 376 376 let ecdh_test_group_exn json = 377 377 match Jsont_bytesrw.encode_string Jsont.json json with 378 378 | Error _ -> failwith "ecdh_test_group_exn: encode failed" 379 - | Ok s -> Jsont_bytesrw.decode_string ecdh_test_group_jsont s |> get_result 379 + | Ok s -> Jsont_bytesrw.decode_string ecdh_test_group_jsont s |> result 380 380 381 381 let ecdsa_test_group_exn json = 382 382 match Jsont_bytesrw.encode_string Jsont.json json with 383 383 | Error _ -> failwith "ecdsa_test_group_exn: encode failed" 384 - | Ok s -> Jsont_bytesrw.decode_string ecdsa_test_group_jsont s |> get_result 384 + | Ok s -> Jsont_bytesrw.decode_string ecdsa_test_group_jsont s |> result 385 385 386 386 let eddsa_test_group_exn json = 387 387 match Jsont_bytesrw.encode_string Jsont.json json with 388 388 | Error _ -> failwith "eddsa_test_group_exn: encode failed" 389 - | Ok s -> Jsont_bytesrw.decode_string eddsa_test_group_jsont s |> get_result 389 + | Ok s -> Jsont_bytesrw.decode_string eddsa_test_group_jsont s |> result