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

Configure Feed

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

fix(crypto): add E405 value docs and apply dune fmt

Add documentation for all undocumented public values in native.mli and
test .mli files. Apply dune fmt formatting (camelCase to snake_case in
wycheproof and test files).

+173 -101
+5 -5
ec/crypto_ec.ml
··· 408 408 (* number must not be in montgomery domain*) 409 409 let y_struct2 = rev_string y_struct2 in 410 410 let ident = String.get_uint8 pk 0 in 411 - let signY = 2 + (String.get_uint8 y_struct (P.byte_length - 1) land 1) in 412 - let res = if Int.equal signY ident then y_struct else y_struct2 in 411 + let sign_y = 2 + (String.get_uint8 y_struct (P.byte_length - 1) land 1) in 412 + let res = if Int.equal sign_y ident then y_struct else y_struct2 in 413 413 let out = Bytes.create ((P.byte_length * 2) + 1) in 414 414 Bytes.set out 0 '\004'; 415 415 Bytes.unsafe_blit_string pk 1 out 1 P.byte_length; ··· 703 703 let q = S.scalar_mult_base d in 704 704 (d, q) 705 705 706 - let x_of_finite_point_mod_n p = 706 + let x_of_point_mod_n p = 707 707 match P.to_affine_raw p with 708 708 | None -> None 709 709 | Some (x, _) -> ··· 730 730 (* if no k is provided, this cannot happen since K_gen_*.gen already preserves the Scalar invariants *) 731 731 in 732 732 let point = S.scalar_mult_base ksc in 733 - match x_of_finite_point_mod_n point with 733 + match x_of_point_mod_n point with 734 734 | None -> again () 735 735 | Some r -> 736 736 let r_mon = F.from_be_octets r in ··· 767 767 with 768 768 | Ok u1, Ok u2 -> 769 769 let point = P.add (S.scalar_mult_base u1) (S.scalar_mult u2 key) in 770 - begin match x_of_finite_point_mod_n point with 770 + begin match x_of_point_mod_n point with 771 771 | None -> false (* point is infinity *) 772 772 | Some r' -> String.equal r r' 773 773 end
+2 -2
pk/dsa.mli
··· 56 56 (** [sign_z ~key z] signs the integer [z], returning [(r, s)]. *) 57 57 58 58 val verify_z : key:pub -> Z.t * Z.t -> Z.t -> bool 59 - (** [verify_z ~key (r, s) z] verifies signature [(r, s)] against [z]. *) 59 + (** [verify_z ~key sig z] verifies signature [sig] against [z]. *) 60 60 61 61 val sign : ?mask:mask -> ?k:Z.t -> key:priv -> string -> string * string 62 62 (** [sign ~key msg] signs the octet string [msg]. *) 63 63 64 64 val verify : key:pub -> string * string -> string -> bool 65 - (** [verify ~key (r, s) msg] verifies the signature against [msg]. *) 65 + (** [verify ~key sig msg] verifies [sig] against [msg]. *) 66 66 67 67 val massage : key:pub -> string -> string 68 68 (** [massage ~key msg] truncates [msg] to the byte length of [key.q]. *)
+52 -9
src/native.mli
··· 8 8 external enc : string -> int -> bytes -> int -> string -> int -> int -> unit 9 9 = "mc_aes_enc_bc" "mc_aes_enc" 10 10 [@@noalloc] 11 + (** [enc src src_off dst dst_off rk rk_off blocks] encrypts [blocks] AES 12 + blocks from [src] into [dst] using round keys [rk]. *) 11 13 12 14 external dec : string -> int -> bytes -> int -> string -> int -> int -> unit 13 15 = "mc_aes_dec_bc" "mc_aes_dec" 14 16 [@@noalloc] 17 + (** [dec src src_off dst dst_off rk rk_off blocks] decrypts [blocks] AES 18 + blocks from [src] into [dst] using round keys [rk]. *) 15 19 16 20 external derive_e : string -> bytes -> int -> unit = "mc_aes_derive_e_key" 17 21 [@@noalloc] 22 + (** [derive_e key rk rounds] derives the encryption round-key schedule from 23 + [key] into [rk]. *) 18 24 19 25 external derive_d : string -> bytes -> int -> string option -> unit 20 26 = "mc_aes_derive_d_key" 21 27 [@@noalloc] 28 + (** [derive_d key rk rounds ekey] derives the decryption round-key schedule. 29 + If [ekey] is provided, it is used as a precomputed encryption schedule. *) 22 30 23 - external rk_s : int -> int = "mc_aes_rk_size" [@@noalloc] 24 - external mode : unit -> int = "mc_aes_mode" [@@noalloc] 31 + external rk_s : int -> int = "mc_aes_rk_size" 32 + [@@noalloc] 33 + (** [rk_s rounds] is the round-key buffer size in bytes for [rounds] rounds. 34 + *) 35 + 36 + external mode : unit -> int = "mc_aes_mode" 37 + [@@noalloc] 38 + (** [mode ()] detects the AES implementation: [0] for generic, [1] for AES-NI. 39 + *) 25 40 end 26 41 27 42 (** Triple DES block cipher. *) ··· 29 44 external ddes : string -> int -> bytes -> int -> int -> string -> unit 30 45 = "mc_des_ddes_bc" "mc_des_ddes" 31 46 [@@noalloc] 47 + (** [ddes src src_off dst dst_off blocks ks] encrypts or decrypts [blocks] DES 48 + blocks using key schedule [ks]. *) 32 49 33 50 external des3key : bytes -> int -> bytes -> unit = "mc_des_des3key" 34 51 [@@noalloc] 52 + (** [des3key key mode ks] derives a Triple-DES key schedule from [key] into 53 + [ks]. [mode] selects encryption or decryption. *) 35 54 36 - external k_s : unit -> int = "mc_des_key_size" [@@noalloc] 55 + external k_s : unit -> int = "mc_des_key_size" 56 + [@@noalloc] 57 + (** [k_s ()] is the key-schedule buffer size in bytes. *) 37 58 end 38 59 39 60 (** ChaCha20 stream cipher. *) 40 61 module Chacha : sig 41 62 external round : int -> bytes -> bytes -> int -> unit = "mc_chacha_round" 42 63 [@@noalloc] 64 + (** [round count state dst off] performs [count] ChaCha20 rounds on [state], 65 + writing output into [dst] at offset [off]. *) 43 66 end 44 67 45 68 (** Poly1305 message authentication. *) 46 69 module Poly1305 : sig 47 - external init : bytes -> string -> unit = "mc_poly1305_init" [@@noalloc] 70 + external init : bytes -> string -> unit = "mc_poly1305_init" 71 + [@@noalloc] 72 + (** [init ctx key] initialises the Poly1305 context [ctx] with [key]. *) 48 73 49 74 external update : bytes -> string -> int -> int -> unit = "mc_poly1305_update" 50 75 [@@noalloc] 76 + (** [update ctx data off len] feeds [len] bytes from [data] at [off] into 77 + [ctx]. *) 51 78 52 79 external finalize : bytes -> bytes -> int -> unit = "mc_poly1305_finalize" 53 80 [@@noalloc] 81 + (** [finalize ctx mac off] writes the final MAC tag into [mac] at [off]. *) 54 82 55 - external ctx_size : unit -> int = "mc_poly1305_ctx_size" [@@noalloc] 56 - external mac_size : unit -> int = "mc_poly1305_mac_size" [@@noalloc] 83 + external ctx_size : unit -> int = "mc_poly1305_ctx_size" 84 + [@@noalloc] 85 + (** [ctx_size ()] is the Poly1305 context size in bytes. *) 86 + 87 + external mac_size : unit -> int = "mc_poly1305_mac_size" 88 + [@@noalloc] 89 + (** [mac_size ()] is the MAC tag size in bytes (16). *) 57 90 end 58 91 59 92 (** GHASH universal hash for GCM. *) 60 93 module GHASH : sig 61 - external keysize : unit -> int = "mc_ghash_key_size" [@@noalloc] 62 - external keyinit : string -> bytes -> unit = "mc_ghash_init_key" [@@noalloc] 94 + external keysize : unit -> int = "mc_ghash_key_size" 95 + [@@noalloc] 96 + (** [keysize ()] is the GHASH key buffer size in bytes. *) 97 + 98 + external keyinit : string -> bytes -> unit = "mc_ghash_init_key" 99 + [@@noalloc] 100 + (** [keyinit key buf] derives the GHASH subkey into [buf]. *) 63 101 64 102 external ghash : string -> bytes -> string -> int -> int -> unit = "mc_ghash" 65 103 [@@noalloc] 104 + (** [ghash key hash data off len] updates [hash] with [len] bytes from [data] 105 + at [off] using the GHASH [key]. *) 66 106 67 - external mode : unit -> int = "mc_ghash_mode" [@@noalloc] 107 + external mode : unit -> int = "mc_ghash_mode" 108 + [@@noalloc] 109 + (** [mode ()] detects the GHASH implementation: [0] for generic, [1] for 110 + PCLMULQDQ. *) 68 111 end 69 112 70 113 external xor_into_bytes : string -> int -> bytes -> int -> int -> unit
+3
tests/test_base.mli
··· 1 + (** Base encoding and utility tests. *) 2 + 1 3 val suite : string * unit Alcotest.test_case list 4 + (** [suite] is the Alcotest test suite for base encoding operations. *)
+3
tests/test_cipher.mli
··· 1 + (** Symmetric cipher tests. *) 2 + 1 3 val suite : string * unit Alcotest.test_case list 4 + (** [suite] is the Alcotest test suite for symmetric ciphers. *)
+3
tests/test_dh.mli
··· 1 + (** Diffie-Hellman key exchange tests. *) 2 + 1 3 val suite : string * unit Alcotest.test_case list 4 + (** [suite] is the Alcotest test suite for Diffie-Hellman operations. *)
+3
tests/test_dsa.mli
··· 1 + (** DSA signature tests. *) 2 + 1 3 val suite : string * unit Alcotest.test_case list 4 + (** [suite] is the Alcotest test suite for DSA signature operations. *)
+15 -13
tests/test_ec_wycheproof.ml
··· 87 87 end 88 88 | _ -> assert false) 89 89 90 - let interpret_test ~tcId curve { public_key; raw_private_key; expected } () = 90 + let interpret_test ~tc_id curve { public_key; raw_private_key; expected } () = 91 91 match perform_key_exchange curve ~public_key ~raw_private_key with 92 92 | Ok got -> Alcotest.check hex __LOC__ expected got 93 93 | Error err -> 94 - Printf.ksprintf (fun s -> Alcotest.fail s) "While parsing %d: %s" tcId err 94 + Printf.ksprintf 95 + (fun s -> Alcotest.fail s) 96 + "While parsing %d: %s" tc_id err 95 97 96 98 type invalid_test = { public : string; private_ : string } 97 99 ··· 111 113 let ignored_flags = [ "UnnamedCurve" ] in 112 114 let curve_compression_test curve = 113 115 let curves = [ "secp256r1"; "secp384r1"; "secp521r1" ] in 114 - test.tcId = 2 && List.exists (fun x -> String.equal x curve) curves 116 + test.tc_id = 2 && List.exists (fun x -> String.equal x curve) curves 115 117 in 116 118 match test.result with 117 119 | _ when has_ignored_flag test ~ignored_flags -> Ok Skip ··· 128 130 Ok (Test { public_key; raw_private_key; expected = test.shared }) 129 131 130 132 let to_ecdh_tests curve (x : ecdh_test) = 131 - let name = Printf.sprintf "%d - %s" x.tcId x.comment in 133 + let name = Printf.sprintf "%d - %s" x.tc_id x.comment in 132 134 match make_ecdh_test curve x with 133 - | Ok (Test t) -> [ (name, `Quick, interpret_test ~tcId:x.tcId curve t) ] 135 + | Ok (Test t) -> [ (name, `Quick, interpret_test ~tc_id:x.tc_id curve t) ] 134 136 | Ok (Invalid_test t) -> [ (name, `Quick, interpret_invalid_test curve t) ] 135 137 | Ok Skip -> [] 136 - | Error e -> Printf.ksprintf failwith "While parsing %d: %s" x.tcId e 138 + | Error e -> Printf.ksprintf failwith "While parsing %d: %s" x.tc_id e 137 139 138 140 let ecdh_tests file = 139 141 let data = load_file_exn file in 140 142 let groups : ecdh_test_group list = 141 - List.map ecdh_test_group_exn data.testGroups 143 + List.map ecdh_test_group_exn data.test_groups 142 144 in 143 145 List.concat_map 144 146 (fun (group : ecdh_test_group) -> ··· 146 148 groups 147 149 148 150 let make_ecdsa_test curve key hash (tst : dsa_test) = 149 - let name = Printf.sprintf "%d - %s" tst.tcId tst.comment in 151 + let name = Printf.sprintf "%d - %s" tst.tc_id tst.comment in 150 152 let size = len curve in 151 153 let msg = 152 154 let dgst = ··· 200 202 let ecdsa_tests file = 201 203 let data = load_file_exn file in 202 204 let groups : ecdsa_test_group list = 203 - List.map ecdsa_test_group_exn data.testGroups 205 + List.map ecdsa_test_group_exn data.test_groups 204 206 in 205 207 List.concat_map to_ecdsa_tests groups 206 208 207 209 let to_x25519_test (x : ecdh_test) = 208 - let name = Printf.sprintf "%d - %s" x.tcId x.comment 210 + let name = Printf.sprintf "%d - %s" x.tc_id x.comment 209 211 and priv = 210 212 match X25519.secret_of_octets x.private_ with 211 213 | Ok (p, _) -> p ··· 243 245 let x25519_tests = 244 246 let data = load_file_exn "x25519_test.json" in 245 247 let groups : ecdh_test_group list = 246 - List.map ecdh_test_group_exn data.testGroups 248 + List.map ecdh_test_group_exn data.test_groups 247 249 in 248 250 List.concat_map 249 251 (fun (group : ecdh_test_group) -> List.map to_x25519_test group.tests) 250 252 groups 251 253 252 254 let to_ed25519_test (priv, pub) (x : dsa_test) = 253 - let name = Printf.sprintf "%d - %s" x.tcId x.comment in 255 + let name = Printf.sprintf "%d - %s" x.tc_id x.comment in 254 256 match x.result with 255 257 | Invalid -> 256 258 let f () = ··· 280 282 let ed25519_tests = 281 283 let data = load_file_exn "eddsa_test.json" in 282 284 let groups : eddsa_test_group list = 283 - List.map eddsa_test_group_exn data.testGroups 285 + List.map eddsa_test_group_exn data.test_groups 284 286 in 285 287 List.concat_map 286 288 (fun (group : eddsa_test_group) ->
+3
tests/test_numeric.mli
··· 1 + (** Numeric and big-integer utility tests. *) 2 + 1 3 val suite : string * unit Alcotest.test_case list 4 + (** [suite] is the Alcotest test suite for numeric utilities. *)
+4 -4
tests/test_rsa.ml
··· 43 43 (* expected since there's no multiplicative inverse of e with p and q (e is not coprime to q-1) *) 44 44 | Ok _ -> Alcotest.fail "expected an error") 45 45 46 - let rsa_priv_of_primes_regression_62 = 46 + let priv_of_primes_regr_62 = 47 47 Alcotest.test_case "priv_of_primes regression #62" `Quick (fun () -> 48 48 (* reported in https://github.com/mirage/mirage-crypto/issues/62 *) 49 49 let e = Z.of_string "65537" ··· 63 63 | Ok priv -> 64 64 if not (Z.equal d priv.Rsa.d) then Alcotest.fail "d is not equal") 65 65 66 - let rsa_priv_of_primes_regression_openssl = 66 + let priv_of_primes_regr_openssl = 67 67 Alcotest.test_case "priv_of_primes regression openssl" `Quick (fun () -> 68 68 let e = Z.of_string "65537" 69 69 and d = ··· 400 400 (* RSA-regression *) 401 401 [ 402 402 rsa_priv_of_primes_regression; 403 - rsa_priv_of_primes_regression_62; 404 - rsa_priv_of_primes_regression_openssl; 403 + priv_of_primes_regr_62; 404 + priv_of_primes_regr_openssl; 405 405 ]; 406 406 ] )
+3
tests/test_rsa.mli
··· 1 + (** RSA encryption and signature tests. *) 2 + 1 3 val suite : string * unit Alcotest.test_case list 4 + (** [suite] is the Alcotest test suite for RSA operations. *)
+66 -57
tests/wycheproof/wycheproof.ml
··· 81 81 Jsont.string 82 82 83 83 type ecdh_test = { 84 - tcId : int; 84 + tc_id : int; 85 85 comment : string; 86 86 curve : json option; 87 87 public : hex; ··· 93 93 94 94 let pp_ecdh_test fmt t = 95 95 Format.fprintf fmt 96 - "{ tcId = %d; comment = %S; curve = %a; public = %a; private_ = %a; shared \ 97 - = %a; result = %a; flags = [%s] }" 98 - t.tcId t.comment 96 + "{ tc_id = %d; comment = %S; curve = %a; public = %a; private_ = %a; \ 97 + shared = %a; result = %a; flags = [%s] }" 98 + t.tc_id t.comment 99 99 (Format.pp_print_option pp_json) 100 100 t.curve pp_hex t.public pp_hex t.private_ pp_hex t.shared pp_test_result 101 101 t.result ··· 105 105 106 106 let ecdh_test_jsont = 107 107 Jsont.Object.map ~kind:"ecdh_test" 108 - (fun tcId comment curve public private_ shared result flags -> 108 + (fun tc_id comment curve public private_ shared result flags -> 109 109 { 110 - tcId; 110 + tc_id; 111 111 comment; 112 112 curve; 113 113 public; ··· 116 116 result; 117 117 flags = Option.value ~default:[] flags; 118 118 }) 119 - |> Jsont.Object.mem "tcId" Jsont.int ~enc:(fun t -> t.tcId) 119 + |> Jsont.Object.mem "tcId" Jsont.int ~enc:(fun t -> t.tc_id) 120 120 |> Jsont.Object.mem "comment" Jsont.string ~enc:(fun t -> t.comment) 121 121 |> Jsont.Object.opt_mem "curve" Jsont.json ~enc:(fun t -> t.curve) 122 122 |> Jsont.Object.mem "public" hex_jsont ~enc:(fun t -> t.public) ··· 162 162 163 163 type ecdsa_key = { 164 164 curve : string; 165 - keySize : int; 165 + key_size : int; 166 166 type_ : json; 167 167 uncompressed : hex; 168 168 wx : hex; ··· 171 171 172 172 let pp_ecdsa_key fmt t = 173 173 Format.fprintf fmt 174 - "{ curve = %S; keySize = %d; type_ = %a; uncompressed = %a; wx = %a; wy = \ 174 + "{ curve = %S; key_size = %d; type_ = %a; uncompressed = %a; wx = %a; wy = \ 175 175 %a }" 176 - t.curve t.keySize pp_json t.type_ pp_hex t.uncompressed pp_hex t.wx pp_hex 176 + t.curve t.key_size pp_json t.type_ pp_hex t.uncompressed pp_hex t.wx pp_hex 177 177 t.wy 178 178 179 179 let show_ecdsa_key t = Format.asprintf "%a" pp_ecdsa_key t 180 180 181 181 let ecdsa_key_jsont = 182 182 Jsont.Object.map ~kind:"ecdsa_key" 183 - (fun curve keySize type_ uncompressed wx wy -> 184 - { curve; keySize; type_; uncompressed; wx; wy }) 183 + (fun curve key_size type_ uncompressed wx wy -> 184 + { curve; key_size; type_; uncompressed; wx; wy }) 185 185 |> Jsont.Object.mem "curve" Jsont.string ~enc:(fun t -> t.curve) 186 - |> Jsont.Object.mem "keySize" Jsont.int ~enc:(fun t -> t.keySize) 186 + |> Jsont.Object.mem "keySize" Jsont.int ~enc:(fun t -> t.key_size) 187 187 |> Jsont.Object.mem "type" Jsont.json ~enc:(fun t -> t.type_) 188 188 |> Jsont.Object.mem "uncompressed" hex_jsont ~enc:(fun t -> t.uncompressed) 189 189 |> Jsont.Object.mem "wx" hex_jsont ~enc:(fun t -> t.wx) ··· 191 191 |> Jsont.Object.skip_unknown |> Jsont.Object.finish 192 192 193 193 type dsa_test = { 194 - tcId : int; 194 + tc_id : int; 195 195 comment : string; 196 196 msg : hex; 197 197 sig_ : hex; ··· 201 201 202 202 let pp_dsa_test fmt t = 203 203 Format.fprintf fmt 204 - "{ tcId = %d; comment = %S; msg = %a; sig_ = %a; result = %a; flags = [%s] \ 205 - }" 206 - t.tcId t.comment pp_hex t.msg pp_hex t.sig_ pp_test_result t.result 204 + "{ tc_id = %d; comment = %S; msg = %a; sig_ = %a; result = %a; flags = \ 205 + [%s] }" 206 + t.tc_id t.comment pp_hex t.msg pp_hex t.sig_ pp_test_result t.result 207 207 (String.concat "; " (List.map (fun s -> "\"" ^ s ^ "\"") t.flags)) 208 208 209 209 let show_dsa_test t = Format.asprintf "%a" pp_dsa_test t 210 210 211 211 let dsa_test_jsont = 212 - Jsont.Object.map ~kind:"dsa_test" (fun tcId comment msg sig_ result flags -> 212 + Jsont.Object.map ~kind:"dsa_test" (fun tc_id comment msg sig_ result flags -> 213 213 { 214 - tcId; 214 + tc_id; 215 215 comment; 216 216 msg; 217 217 sig_; 218 218 result; 219 219 flags = Option.value ~default:[] flags; 220 220 }) 221 - |> Jsont.Object.mem "tcId" Jsont.int ~enc:(fun t -> t.tcId) 221 + |> Jsont.Object.mem "tcId" Jsont.int ~enc:(fun t -> t.tc_id) 222 222 |> Jsont.Object.mem "comment" Jsont.string ~enc:(fun t -> t.comment) 223 223 |> Jsont.Object.mem "msg" hex_jsont ~enc:(fun t -> t.msg) 224 224 |> Jsont.Object.mem "sig" hex_jsont ~enc:(fun t -> t.sig_) ··· 229 229 230 230 type ecdsa_test_group = { 231 231 key : ecdsa_key; 232 - keyDer : string; 233 - keyPem : string; 232 + key_der : string; 233 + key_pem : string; 234 234 sha : string; 235 235 tests : dsa_test list; 236 236 type_ : json option; ··· 238 238 239 239 let pp_ecdsa_test_group fmt t = 240 240 Format.fprintf fmt 241 - "{ key = %a; keyDer = %S; keyPem = %S; sha = %S; tests = [%d tests]; type_ \ 242 - = %a }" 243 - pp_ecdsa_key t.key t.keyDer t.keyPem t.sha (List.length t.tests) 241 + "{ key = %a; key_der = %S; key_pem = %S; sha = %S; tests = [%d tests]; \ 242 + type_ = %a }" 243 + pp_ecdsa_key t.key t.key_der t.key_pem t.sha (List.length t.tests) 244 244 (Format.pp_print_option pp_json) 245 245 t.type_ 246 246 ··· 248 248 249 249 let ecdsa_test_group_jsont = 250 250 Jsont.Object.map ~kind:"ecdsa_test_group" 251 - (fun key keyDer keyPem sha tests type_ -> 252 - { key; keyDer; keyPem; sha; tests; type_ }) 251 + (fun key key_der key_pem sha tests type_ -> 252 + { key; key_der; key_pem; sha; tests; type_ }) 253 253 |> Jsont.Object.mem "key" ecdsa_key_jsont ~enc:(fun t -> t.key) 254 - |> Jsont.Object.mem "keyDer" Jsont.string ~enc:(fun t -> t.keyDer) 255 - |> Jsont.Object.mem "keyPem" Jsont.string ~enc:(fun t -> t.keyPem) 254 + |> Jsont.Object.mem "keyDer" Jsont.string ~enc:(fun t -> t.key_der) 255 + |> Jsont.Object.mem "keyPem" Jsont.string ~enc:(fun t -> t.key_pem) 256 256 |> Jsont.Object.mem "sha" Jsont.string ~enc:(fun t -> t.sha) 257 257 |> Jsont.Object.mem "tests" (Jsont.list dsa_test_jsont) ~enc:(fun t -> 258 258 t.tests) ··· 261 261 262 262 type eddsa_key = { 263 263 curve : string; 264 - keySize : int; 264 + key_size : int; 265 265 pk : hex; 266 266 sk : hex; 267 267 type_ : json; ··· 269 269 270 270 let pp_eddsa_key fmt t = 271 271 Format.fprintf fmt 272 - "{ curve = %S; keySize = %d; pk = %a; sk = %a; type_ = %a }" t.curve 273 - t.keySize pp_hex t.pk pp_hex t.sk pp_json t.type_ 272 + "{ curve = %S; key_size = %d; pk = %a; sk = %a; type_ = %a }" t.curve 273 + t.key_size pp_hex t.pk pp_hex t.sk pp_json t.type_ 274 274 275 275 let show_eddsa_key t = Format.asprintf "%a" pp_eddsa_key t 276 276 277 277 let eddsa_key_jsont = 278 - Jsont.Object.map ~kind:"eddsa_key" (fun curve keySize pk sk type_ -> 279 - { curve; keySize; pk; sk; type_ }) 278 + Jsont.Object.map ~kind:"eddsa_key" (fun curve key_size pk sk type_ -> 279 + { curve; key_size; pk; sk; type_ }) 280 280 |> Jsont.Object.mem "curve" Jsont.string ~enc:(fun t -> t.curve) 281 - |> Jsont.Object.mem "keySize" Jsont.int ~enc:(fun t -> t.keySize) 281 + |> Jsont.Object.mem "keySize" Jsont.int ~enc:(fun t -> t.key_size) 282 282 |> Jsont.Object.mem "pk" hex_jsont ~enc:(fun t -> t.pk) 283 283 |> Jsont.Object.mem "sk" hex_jsont ~enc:(fun t -> t.sk) 284 284 |> Jsont.Object.mem "type" Jsont.json ~enc:(fun t -> t.type_) ··· 287 287 type eddsa_test_group = { 288 288 jwk : json; 289 289 key : eddsa_key; 290 - keyDer : string; 291 - keyPem : string; 290 + key_der : string; 291 + key_pem : string; 292 292 type_ : json; 293 293 tests : dsa_test list; 294 294 } 295 295 296 296 let pp_eddsa_test_group fmt t = 297 297 Format.fprintf fmt 298 - "{ jwk = %a; key = %a; keyDer = %S; keyPem = %S; type_ = %a; tests = [%d \ 298 + "{ jwk = %a; key = %a; key_der = %S; key_pem = %S; type_ = %a; tests = [%d \ 299 299 tests] }" 300 - pp_json t.jwk pp_eddsa_key t.key t.keyDer t.keyPem pp_json t.type_ 300 + pp_json t.jwk pp_eddsa_key t.key t.key_der t.key_pem pp_json t.type_ 301 301 (List.length t.tests) 302 302 303 303 let show_eddsa_test_group t = Format.asprintf "%a" pp_eddsa_test_group t 304 304 305 305 let eddsa_test_group_jsont = 306 306 Jsont.Object.map ~kind:"eddsa_test_group" 307 - (fun jwk key keyDer keyPem type_ tests -> 308 - { jwk; key; keyDer; keyPem; type_; tests }) 307 + (fun jwk key key_der key_pem type_ tests -> 308 + { jwk; key; key_der; key_pem; type_; tests }) 309 309 |> Jsont.Object.mem "jwk" Jsont.json ~enc:(fun t -> t.jwk) 310 310 |> Jsont.Object.mem "key" eddsa_key_jsont ~enc:(fun t -> t.key) 311 - |> Jsont.Object.mem "keyDer" Jsont.string ~enc:(fun t -> t.keyDer) 312 - |> Jsont.Object.mem "keyPem" Jsont.string ~enc:(fun t -> t.keyPem) 311 + |> Jsont.Object.mem "keyDer" Jsont.string ~enc:(fun t -> t.key_der) 312 + |> Jsont.Object.mem "keyPem" Jsont.string ~enc:(fun t -> t.key_pem) 313 313 |> Jsont.Object.mem "type" Jsont.json ~enc:(fun t -> t.type_) 314 314 |> Jsont.Object.mem "tests" (Jsont.list dsa_test_jsont) ~enc:(fun t -> 315 315 t.tests) ··· 317 317 318 318 type test_file = { 319 319 algorithm : json; 320 - generatorVersion : json; 320 + generator_version : json; 321 321 header : json; 322 322 notes : json; 323 - numberOfTests : json; 323 + number_of_tests : json; 324 324 schema : json; 325 - testGroups : json list; 325 + test_groups : json list; 326 326 } 327 327 328 328 let pp_test_file fmt t = 329 329 Format.fprintf fmt 330 - "{ algorithm = %a; generatorVersion = %a; header = %a; notes = %a; \ 331 - numberOfTests = %a; schema = %a; testGroups = [%d groups] }" 332 - pp_json t.algorithm pp_json t.generatorVersion pp_json t.header pp_json 333 - t.notes pp_json t.numberOfTests pp_json t.schema (List.length t.testGroups) 330 + "{ algorithm = %a; generator_version = %a; header = %a; notes = %a; \ 331 + number_of_tests = %a; schema = %a; test_groups = [%d groups] }" 332 + pp_json t.algorithm pp_json t.generator_version pp_json t.header pp_json 333 + t.notes pp_json t.number_of_tests pp_json t.schema 334 + (List.length t.test_groups) 334 335 335 336 let show_test_file t = Format.asprintf "%a" pp_test_file t 336 337 337 338 let test_file_jsont = 338 339 Jsont.Object.map ~kind:"test_file" 339 340 (fun 340 - algorithm generatorVersion header notes numberOfTests schema testGroups -> 341 + algorithm 342 + generator_version 343 + header 344 + notes 345 + number_of_tests 346 + schema 347 + test_groups 348 + -> 341 349 { 342 350 algorithm; 343 - generatorVersion; 351 + generator_version; 344 352 header; 345 353 notes; 346 - numberOfTests; 354 + number_of_tests; 347 355 schema; 348 - testGroups; 356 + test_groups; 349 357 }) 350 358 |> Jsont.Object.mem "algorithm" Jsont.json ~enc:(fun t -> t.algorithm) 351 359 |> Jsont.Object.mem "generatorVersion" Jsont.json ~enc:(fun t -> 352 - t.generatorVersion) 360 + t.generator_version) 353 361 |> Jsont.Object.mem "header" Jsont.json ~enc:(fun t -> t.header) 354 362 |> Jsont.Object.mem "notes" Jsont.json ~enc:(fun t -> t.notes) 355 - |> Jsont.Object.mem "numberOfTests" Jsont.json ~enc:(fun t -> t.numberOfTests) 363 + |> Jsont.Object.mem "numberOfTests" Jsont.json ~enc:(fun t -> 364 + t.number_of_tests) 356 365 |> Jsont.Object.mem "schema" Jsont.json ~enc:(fun t -> t.schema) 357 366 |> Jsont.Object.mem "testGroups" (Jsont.list Jsont.json) ~enc:(fun t -> 358 - t.testGroups) 367 + t.test_groups) 359 368 |> Jsont.Object.skip_unknown |> Jsont.Object.finish 360 369 361 370 let get_result = function Ok x -> x | Error s -> failwith s
+11 -11
tests/wycheproof/wycheproof.mli
··· 21 21 (** [show_test_result r] returns a string representation of test result [r]. *) 22 22 23 23 type ecdh_test = { 24 - tcId : int; 24 + tc_id : int; 25 25 comment : string; 26 26 curve : json option; 27 27 public : hex; ··· 58 58 59 59 type ecdsa_key = { 60 60 curve : string; 61 - keySize : int; 61 + key_size : int; 62 62 type_ : json; 63 63 uncompressed : hex; 64 64 wx : hex; ··· 72 72 (** [show_ecdsa_key k] returns a string representation of ECDSA key [k]. *) 73 73 74 74 type dsa_test = { 75 - tcId : int; 75 + tc_id : int; 76 76 comment : string; 77 77 msg : hex; 78 78 sig_ : hex; ··· 88 88 89 89 type ecdsa_test_group = { 90 90 key : ecdsa_key; 91 - keyDer : string; 92 - keyPem : string; 91 + key_der : string; 92 + key_pem : string; 93 93 sha : string; 94 94 tests : dsa_test list; 95 95 type_ : json option; ··· 105 105 106 106 type eddsa_key = { 107 107 curve : string; 108 - keySize : int; 108 + key_size : int; 109 109 pk : hex; 110 110 sk : hex; 111 111 type_ : json; ··· 120 120 type eddsa_test_group = { 121 121 jwk : json; 122 122 key : eddsa_key; 123 - keyDer : string; 124 - keyPem : string; 123 + key_der : string; 124 + key_pem : string; 125 125 type_ : json; 126 126 tests : dsa_test list; 127 127 } ··· 136 136 137 137 type test_file = { 138 138 algorithm : json; 139 - generatorVersion : json; 139 + generator_version : json; 140 140 header : json; 141 141 notes : json; 142 - numberOfTests : json; 142 + number_of_tests : json; 143 143 schema : json; 144 - testGroups : json list; 144 + test_groups : json list; 145 145 } 146 146 147 147 val pp_test_file : Format.formatter -> test_file -> unit