upstream: https://github.com/mirage/mirage-crypto
at main 87 lines 2.6 kB view raw
1module AES = struct 2 external enc : string -> int -> bytes -> int -> string -> int -> int -> unit 3 = "mc_aes_enc_bc" "mc_aes_enc" 4 [@@noalloc] 5 6 external dec : string -> int -> bytes -> int -> string -> int -> int -> unit 7 = "mc_aes_dec_bc" "mc_aes_dec" 8 [@@noalloc] 9 10 external derive_e : string -> bytes -> int -> unit = "mc_aes_derive_e_key" 11 [@@noalloc] 12 13 external derive_d : string -> bytes -> int -> string option -> unit 14 = "mc_aes_derive_d_key" 15 [@@noalloc] 16 17 external rk_s : int -> int = "mc_aes_rk_size" [@@noalloc] 18 external mode : unit -> int = "mc_aes_mode" [@@noalloc] 19end 20 21module DES = struct 22 external ddes : string -> int -> bytes -> int -> int -> string -> unit 23 = "mc_des_ddes_bc" "mc_des_ddes" 24 [@@noalloc] 25 26 external des3key : bytes -> int -> bytes -> unit = "mc_des_des3key" 27 [@@noalloc] 28 29 external k_s : unit -> int = "mc_des_key_size" [@@noalloc] 30end 31 32module Chacha = struct 33 external round : int -> bytes -> bytes -> int -> unit = "mc_chacha_round" 34 [@@noalloc] 35end 36 37module Poly1305 = struct 38 external init : bytes -> string -> unit = "mc_poly1305_init" [@@noalloc] 39 40 external update : bytes -> string -> int -> int -> unit = "mc_poly1305_update" 41 [@@noalloc] 42 43 external finalize : bytes -> bytes -> int -> unit = "mc_poly1305_finalize" 44 [@@noalloc] 45 46 external ctx_size : unit -> int = "mc_poly1305_ctx_size" [@@noalloc] 47 external mac_size : unit -> int = "mc_poly1305_mac_size" [@@noalloc] 48end 49 50module GHASH = struct 51 external keysize : unit -> int = "mc_ghash_key_size" [@@noalloc] 52 external keyinit : string -> bytes -> unit = "mc_ghash_init_key" [@@noalloc] 53 54 external ghash : string -> bytes -> string -> int -> int -> unit = "mc_ghash" 55 [@@noalloc] 56 57 external mode : unit -> int = "mc_ghash_mode" [@@noalloc] 58end 59 60(* XXX TODO 61 * Unsolved: bounds-checked XORs are slowing things down considerably... *) 62external xor_into_bytes : string -> int -> bytes -> int -> int -> unit 63 = "mc_xor_into_bytes" 64[@@noalloc] 65 66external count8be : ctr:bytes -> bytes -> off:int -> blocks:int -> unit 67 = "mc_count_8_be" 68[@@noalloc] 69 70external count16be : ctr:bytes -> bytes -> off:int -> blocks:int -> unit 71 = "mc_count_16_be" 72[@@noalloc] 73 74external count16be4 : ctr:bytes -> bytes -> off:int -> blocks:int -> unit 75 = "mc_count_16_be_4" 76[@@noalloc] 77 78external misc_mode : unit -> int = "mc_misc_mode" [@@noalloc] 79 80external _detect_cpu_features : unit -> unit = "mc_detect_cpu_features" 81[@@noalloc] 82 83external _detect_entropy : unit -> unit = "mc_entropy_detect" 84 85let () = 86 _detect_cpu_features (); 87 _detect_entropy ()