upstream: https://github.com/mirage/mirage-crypto
at main 33 lines 768 B view raw
1(** [Uncommon] is a [Common], now with less name clashes. *) 2 3let kasprintf k fmt = Fmt.kstr k fmt 4let invalid_arg fmt = kasprintf invalid_arg ("Crypto: " ^^ fmt) 5 6let ( // ) x y = 7 if y < 1 then raise Division_by_zero 8 else if x > 0 then 1 + ((x - 1) / y) 9 else 0 10[@@inline] 11 12let imin (a : int) b = if a < b then a else b 13let imax (a : int) b = if a < b then b else a 14 15type 'a iter = ('a -> unit) -> unit 16 17let iter2 a b f = 18 f a; 19 f b 20 21let iter3 a b c f = 22 f a; 23 f b; 24 f c 25 26let unsafe_xor_into src ~src_off dst ~dst_off n = 27 Native.xor_into_bytes src src_off dst dst_off n 28 29let xor a b = 30 assert (String.length a = String.length b); 31 let b' = Bytes.of_string b in 32 unsafe_xor_into a ~src_off:0 b' ~dst_off:0 (Bytes.length b'); 33 Bytes.unsafe_to_string b'