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

Require OCaml 4.13 and remove local overrides

+39 -84
+1 -1
.github/workflows/test.yml
··· 9 9 strategy: 10 10 fail-fast: false 11 11 matrix: 12 - ocaml-version: ["4.14.2", "4.13.1", "4.12.1"] 12 + ocaml-version: ["4.14.2", "4.13.1"] 13 13 operating-system: [macos-latest, ubuntu-latest] 14 14 15 15 runs-on: ${{ matrix.operating-system }}
+1 -1
.github/workflows/windows.yml
··· 9 9 strategy: 10 10 fail-fast: false 11 11 matrix: 12 - ocaml-version: ["4.14.2", "4.13.1", "4.12.1"] 12 + ocaml-version: ["4.14.2", "4.13.1"] 13 13 operating-system: [windows-latest] 14 14 15 15 runs-on: ${{ matrix.operating-system }}
+6 -10
ec/mirage_crypto_ec.ml
··· 28 28 29 29 exception Message_too_long 30 30 31 - let string_get_uint8 buf idx = 32 - (* TODO: use String.get_uint8 when mirage-crypto-ec requires OCaml >= 4.13 *) 33 - Bytes.get_uint8 (Bytes.unsafe_of_string buf) idx 34 - 35 31 let bit_at buf i = 36 32 let byte_num = i / 8 in 37 33 let bit_num = i mod 8 in 38 - let byte = string_get_uint8 buf byte_num in 34 + let byte = String.get_uint8 buf byte_num in 39 35 byte land (1 lsl bit_num) <> 0 40 36 41 37 module type Dh = sig ··· 320 316 if compress then 321 317 let out = Bytes.create (P.byte_length + 1) in 322 318 let ident = 323 - 2 + (string_get_uint8 buf ((P.byte_length * 2) - 1)) land 1 319 + 2 + (String.get_uint8 buf ((P.byte_length * 2) - 1)) land 1 324 320 in 325 321 Bytes.unsafe_blit_string buf 1 out 1 P.byte_length; 326 322 Bytes.set_uint8 out 0 ident; ··· 389 385 let y' = Fe.from_montgomery y' in 390 386 let y_struct2 = Fe.to_octets y' in (* number must not be in montgomery domain*) 391 387 let y_struct2 = rev_string y_struct2 in 392 - let ident = string_get_uint8 pk 0 in 388 + let ident = String.get_uint8 pk 0 in 393 389 let signY = 394 - 2 + (string_get_uint8 y_struct (P.byte_length - 2)) land 1 390 + 2 + (String.get_uint8 y_struct (P.byte_length - 2)) land 1 395 391 in 396 392 let res = if Int.equal signY ident then y_struct else y_struct2 in 397 393 let out = Bytes.create ((P.byte_length * 2) + 1) in ··· 410 406 let y = String.sub buf (1 + len) len in 411 407 validate_finite_point ~x ~y 412 408 in 413 - match string_get_uint8 buf 0 with 409 + match String.get_uint8 buf 0 with 414 410 | 0x00 when String.length buf = 1 -> 415 411 Ok (at_infinity ()) 416 412 | 0x02 | 0x03 when String.length P.pident > 0 -> ··· 614 610 let first_byte_ok () = 615 611 match Param.first_byte_bits with 616 612 | None -> true 617 - | Some m -> (string_get_uint8 msg 0) land (0xFF land (lnot m)) = 0 613 + | Some m -> (String.get_uint8 msg 0) land (0xFF land (lnot m)) = 0 618 614 in 619 615 if l > bl || (l = bl && not (first_byte_ok ())) then 620 616 raise Message_too_long
+1 -1
mirage-crypto-ec.opam
··· 27 27 bug-reports: "https://github.com/mirage/mirage-crypto/issues" 28 28 depends: [ 29 29 "dune" {>= "2.7"} 30 - "ocaml" {>= "4.08.0"} 30 + "ocaml" {>= "4.13.0"} 31 31 "dune-configurator" 32 32 "eqaf" {>= "0.7"} 33 33 "mirage-crypto-rng" {=version}
+1 -1
mirage-crypto-pk.opam
··· 14 14 15 15 depends: [ 16 16 "conf-gmp-powm-sec" {build} 17 - "ocaml" {>= "4.08.0"} 17 + "ocaml" {>= "4.13.0"} 18 18 "dune" {>= "2.7"} 19 19 "ounit2" {with-test} 20 20 "randomconv" {with-test & >= "0.2.0"}
+1 -1
mirage-crypto-rng-async.opam
··· 13 13 ["dune" "runtest" "-p" name "-j" jobs] {with-test} ] 14 14 15 15 depends: [ 16 - "ocaml" {>= "4.08.0"} 16 + "ocaml" {>= "4.13.0"} 17 17 "dune" {>= "2.7"} 18 18 "dune-configurator" {>= "2.0.0"} 19 19 "async" {>= "v0.14"}
+1 -1
mirage-crypto-rng-lwt.opam
··· 13 13 ["dune" "runtest" "-p" name "-j" jobs] {with-test} ] 14 14 15 15 depends: [ 16 - "ocaml" {>= "4.08.0"} 16 + "ocaml" {>= "4.13.0"} 17 17 "dune" {>= "2.7"} 18 18 "duration" 19 19 "logs"
+1 -1
mirage-crypto-rng-mirage.opam
··· 13 13 ["dune" "runtest" "-p" name "-j" jobs] {with-test} ] 14 14 15 15 depends: [ 16 - "ocaml" {>= "4.08.0"} 16 + "ocaml" {>= "4.13.0"} 17 17 "dune" {>= "2.7"} 18 18 "mirage-crypto-rng" {=version} 19 19 "duration"
+1 -1
mirage-crypto-rng.opam
··· 13 13 ["dune" "runtest" "-p" name "-j" jobs] {with-test} ] 14 14 15 15 depends: [ 16 - "ocaml" {>= "4.12.0"} 16 + "ocaml" {>= "4.13.0"} 17 17 "dune" {>= "2.7"} 18 18 "dune-configurator" {>= "2.0.0"} 19 19 "duration"
+1 -1
mirage-crypto.opam
··· 13 13 ["dune" "runtest" "-p" name "-j" jobs] {with-test} ] 14 14 15 15 depends: [ 16 - "ocaml" {>= "4.09.0"} 16 + "ocaml" {>= "4.13.0"} 17 17 "dune" {>= "2.7"} 18 18 "dune-configurator" {>= "2.0.0"} 19 19 "ounit2" {with-test}
+10 -19
pk/rsa.ml
··· 197 197 let decrypt ?(crt_hardening=false) ?(mask=`Yes) ~key = 198 198 reformat (priv_bits key) (decrypt_z ~crt_hardening ~mask ~key) 199 199 200 - (* OCaml 4.13 *) 201 - let string_get_uint8 buf idx = 202 - Bytes.get_uint8 (Bytes.unsafe_of_string buf) idx 203 - 204 200 let bx00, bx01 = "\x00", "\x01" 205 201 206 202 module PKCS1 = struct ··· 214 210 let rec go nonce i j = 215 211 if i = n then Bytes.unsafe_to_string buf else 216 212 if j = k then go Mirage_crypto_rng.(generate ?g k) i 0 else 217 - match string_get_uint8 nonce j with 213 + match String.get_uint8 nonce j with 218 214 | b when f b -> Bytes.set_uint8 buf i b ; go nonce (succ i) (succ j) 219 215 | _ -> go nonce i (succ j) in 220 216 go Mirage_crypto_rng.(generate ?g k) 0 0 ··· 226 222 let unpad ~mark ~is_pad buf = 227 223 let f = not &. is_pad in 228 224 let i = ct_find_uint8 ~default:2 ~off:2 ~f buf in 229 - let c1 = string_get_uint8 buf 0 = 0x00 230 - and c2 = string_get_uint8 buf 1 = mark 231 - and c3 = string_get_uint8 buf i = 0x00 225 + let c1 = String.get_uint8 buf 0 = 0x00 226 + and c2 = String.get_uint8 buf 1 = mark 227 + and c3 = String.get_uint8 buf i = 0x00 232 228 and c4 = min_pad <= i - 2 in 233 229 if c1 && c2 && c3 && c4 then 234 230 Some (String.sub buf (i + 1) (String.length buf - i - 1)) ··· 264 260 let decrypt ?(crt_hardening = false) ?mask ~key msg = 265 261 unpadded unpad_02 (decrypt ~crt_hardening ?mask ~key) (priv_bits key) msg 266 262 267 - (* OCaml 4.13 contains starts_with *) 268 - let is_prefix asn msg = 269 - String.length msg >= String.length asn && 270 - String.equal asn (String.sub msg 0 (String.length asn)) 271 - 272 263 let asn_of_hash, detect = 273 264 let map = [ 274 265 `MD5, "\x30\x20\x30\x0c\x06\x08\x2a\x86\x48\x86\xf7\x0d\x02\x05\x05\x00\x04\x10" ; ··· 280 271 ] 281 272 in 282 273 (fun h -> List.assoc h map), 283 - (fun buf -> List.find_opt (fun (_, d) -> is_prefix d buf) map) 274 + (fun buf -> List.find_opt (fun (_, d) -> String.starts_with ~prefix:d buf) map) 284 275 285 276 let sign ?(crt_hardening = true) ?mask ~hash ~key msg = 286 277 let module H = (val Digestif.module_of_hash' (hash :> Digestif.hash')) in ··· 353 344 let db = Bytes.unsafe_to_string (MGF.mask ~seed:(Bytes.unsafe_to_string (MGF.mask ~seed:mdb ms)) mdb) in 354 345 let i = ct_find_uint8 ~default:0 ~off:hlen ~f:((<>) 0x00) db in 355 346 let c1 = Eqaf.equal (String.sub db 0 hlen) H.(digest_string label |> to_raw_string) 356 - and c2 = string_get_uint8 b0 0 = 0x00 357 - and c3 = string_get_uint8 db i = 0x01 in 347 + and c2 = String.get_uint8 b0 0 = 0x00 348 + and c3 = String.get_uint8 db i = 0x01 in 358 349 if c1 && c2 && c3 then Some (String.sub db (i + 1) (String.length db - i - 1)) else None 359 350 360 351 let encrypt ?g ?label ~key msg = ··· 402 393 let emsa_pss_verify slen emlen em msg = 403 394 let mdb = String.sub em 0 (String.length em - hlen - 1) 404 395 and h = String.sub em (String.length em - hlen - 1) hlen 405 - and bxx = string_get_uint8 em (String.length em - 1) 396 + and bxx = String.get_uint8 em (String.length em - 1) 406 397 in 407 398 let db = MGF.mask ~seed:h mdb in 408 399 Bytes.set_uint8 db 0 (Bytes.get_uint8 db 0 land b0mask emlen) ; ··· 410 401 let salt = String.sub db (String.length db - slen) slen in 411 402 let h' = digest ~salt:salt msg 412 403 and i = ct_find_uint8 ~default:0 ~f:((<>) 0x00) db in 413 - let c1 = lnot (b0mask emlen) land string_get_uint8 mdb 0 = 0x00 404 + let c1 = lnot (b0mask emlen) land String.get_uint8 mdb 0 = 0x00 414 405 and c2 = i = String.length em - hlen - slen - 2 415 - and c3 = string_get_uint8 db i = 0x01 406 + and c3 = String.get_uint8 db i = 0x01 416 407 and c4 = bxx = 0xbc 417 408 and c5 = Eqaf.equal h h' in 418 409 c1 && c2 && c3 && c4 && c5
+5 -18
pk/z_extra.ml
··· 2 2 3 3 let bit_bound z = Z.size z * 64 4 4 5 - (* revise once OCaml 4.13 is the lower bound *) 6 - let string_get_int64_be buf idx = 7 - Bytes.get_int64_be (Bytes.unsafe_of_string buf) idx 8 - 9 - let string_get_int32_be buf idx = 10 - Bytes.get_int32_be (Bytes.unsafe_of_string buf) idx 11 - 12 - let string_get_uint16_be buf idx = 13 - Bytes.get_uint16_be (Bytes.unsafe_of_string buf) idx 14 - 15 - let string_get_uint8 buf idx = 16 - Bytes.get_uint8 (Bytes.unsafe_of_string buf) idx 17 - 18 5 let of_octets_be ?bits buf = 19 6 let rec loop acc i = function 20 7 | b when b >= 64 -> 21 - let x = string_get_int64_be buf i in 8 + let x = String.get_int64_be buf i in 22 9 let x = Z.of_int64_unsigned Int64.(shift_right_logical x 8) in 23 10 loop Z.(x + acc lsl 56) (i + 7) (b - 56) 24 11 | b when b >= 32 -> 25 - let x = string_get_int32_be buf i in 12 + let x = String.get_int32_be buf i in 26 13 let x = Z.of_int32_unsigned Int32.(shift_right_logical x 8) in 27 14 loop Z.(x + acc lsl 24) (i + 3) (b - 24) 28 15 | b when b >= 16 -> 29 - let x = Z.of_int (string_get_uint16_be buf i) in 16 + let x = Z.of_int (String.get_uint16_be buf i) in 30 17 loop Z.(x + acc lsl 16) (i + 2) (b - 16) 31 18 | b when b >= 8 -> 32 - let x = Z.of_int (string_get_uint8 buf i) in 19 + let x = Z.of_int (String.get_uint8 buf i) in 33 20 loop Z.(x + acc lsl 8 ) (i + 1) (b - 8 ) 34 21 | b when b > 0 -> 35 - let x = string_get_uint8 buf i and b' = 8 - b in 22 + let x = String.get_uint8 buf i and b' = 8 - b in 36 23 Z.(of_int x asr b' + acc lsl b) 37 24 | _ -> acc in 38 25 loop Z.zero 0 @@ match bits with
+2 -9
src/cipher_block.ml
··· 89 89 module C64be = struct 90 90 type ctr = int64 91 91 let size = 8 92 - (* Until OCaml 4.13 is lower bound*) 93 - let of_octets cs = Bytes.get_int64_be (Bytes.unsafe_of_string cs) 0 92 + let of_octets cs = String.get_int64_be cs 0 94 93 let add = Int64.add 95 94 let unsafe_count_into t buf ~blocks = 96 95 let tmp = Bytes.create 8 in ··· 277 276 Bytes.set_int64_be cs 8 b; 278 277 Bytes.unsafe_to_string cs 279 278 280 - (* OCaml 4.13 *) 281 - let string_get_int64 s idx = 282 - Bytes.get_int64_be (Bytes.unsafe_of_string s) idx 283 - let string_get_int32 s idx = 284 - Bytes.get_int32_be (Bytes.unsafe_of_string s) idx 285 - 286 279 let counter ~hkey nonce = match String.length nonce with 287 280 | 0 -> invalid_arg "GCM: invalid nonce of length 0" 288 281 | 12 -> 289 - let (w1, w2) = string_get_int64 nonce 0, string_get_int32 nonce 8 in 282 + let (w1, w2) = String.get_int64_be nonce 0, String.get_int32_be nonce 8 in 290 283 (w1, Int64.(shift_left (of_int32 w2) 32 |> add 1L)) 291 284 | _ -> 292 285 CTR.ctr_of_octets @@
+2 -2
src/cipher_stream.ml
··· 21 21 let rec loop j = function 22 22 | 256 -> () 23 23 | i -> 24 - let x = string_get_uint8 buf (i mod len) in 24 + let x = String.get_uint8 buf (i mod len) in 25 25 let si = s.(i) in 26 26 let j = (j + si + x) land 0xff in 27 27 let sj = s.(j) in ··· 43 43 let sj = s.(j) in 44 44 s.(i) <- sj ; s.(j) <- si ; 45 45 let k = s.((si + sj) land 0xff) in 46 - Bytes.set_uint8 res n (k lxor string_get_uint8 buf n); 46 + Bytes.set_uint8 res n (k lxor String.get_uint8 buf n); 47 47 mix i j (succ n) 48 48 in 49 49 let key' = mix i j 0 in
-4
src/uncommon.ml
··· 25 25 let b' = Bytes.of_string b in 26 26 xor_into a ~src_off:0 b' ~dst_off:0 (Bytes.length b'); 27 27 Bytes.unsafe_to_string b' 28 - 29 - (* revise once OCaml 4.13 is the lower bound *) 30 - let string_get_uint8 buf idx = 31 - Bytes.get_uint8 (Bytes.unsafe_of_string buf) idx
+5 -13
tests/test_ec_wycheproof.ml
··· 4 4 5 5 let ( let* ) = Result.bind 6 6 7 - let concat_map f l = 8 - (* adapt once OCaml 4.10 is lower bound *) 9 - List.map f l |> List.concat 10 - 11 - let string_get_uint8 d off = 12 - (* adapt once OCaml 4.13 is lower bound *) 13 - Bytes.get_uint8 (Bytes.unsafe_of_string d) off 14 - 15 7 let hex = Alcotest.testable Wycheproof.pp_hex Wycheproof.equal_hex 16 8 17 9 module Asn = struct ··· 155 147 let groups : ecdh_test_group list = 156 148 List.map ecdh_test_group_exn data.testGroups 157 149 in 158 - concat_map (fun (group : ecdh_test_group) -> 159 - concat_map (to_ecdh_tests group.curve) group.tests) 150 + List.concat_map (fun (group : ecdh_test_group) -> 151 + List.concat_map (to_ecdh_tests group.curve) group.tests) 160 152 groups 161 153 162 154 let make_ecdsa_test curve key hash (tst : dsa_test) = ··· 219 211 let groups : ecdsa_test_group list = 220 212 List.map ecdsa_test_group_exn data.testGroups 221 213 in 222 - concat_map to_ecdsa_tests groups 214 + List.concat_map to_ecdsa_tests groups 223 215 224 216 let to_x25519_test (x : ecdh_test) = 225 217 let name = Printf.sprintf "%d - %s" x.tcId x.comment ··· 262 254 let groups : ecdh_test_group list = 263 255 List.map ecdh_test_group_exn data.testGroups 264 256 in 265 - concat_map (fun (group : ecdh_test_group) -> 257 + List.concat_map (fun (group : ecdh_test_group) -> 266 258 List.map to_x25519_test group.tests) 267 259 groups 268 260 ··· 297 289 let groups : eddsa_test_group list = 298 290 List.map eddsa_test_group_exn data.testGroups 299 291 in 300 - concat_map (fun (group : eddsa_test_group) -> 292 + List.concat_map (fun (group : eddsa_test_group) -> 301 293 let keys = to_ed25519_keys group.key in 302 294 List.map (to_ed25519_test keys) group.tests) 303 295 groups