-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathnative.ml
More file actions
84 lines (67 loc) · 3.94 KB
/
native.ml
File metadata and controls
84 lines (67 loc) · 3.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
open Bigarray
let buffer = Array1.create char c_layout
type buffer = (char, int8_unsigned_elt, c_layout) Array1.t
(* Readability. *)
type off = int
type size = int
type secret = buffer
type key = buffer
type ctx = buffer
module AES = struct
external enc : buffer -> off -> buffer -> off -> key -> int -> size -> unit = "caml_nc_aes_enc_bc" "caml_nc_aes_enc" [@@noalloc]
external dec : buffer -> off -> buffer -> off -> key -> int -> size -> unit = "caml_nc_aes_dec_bc" "caml_nc_aes_dec" [@@noalloc]
external derive_e : secret -> off -> key -> int -> unit = "caml_nc_aes_derive_e_key" [@@noalloc]
external derive_d : secret -> off -> key -> int -> key option -> unit = "caml_nc_aes_derive_d_key" [@@noalloc]
external rk_s : int -> int = "caml_nc_aes_rk_size" [@@noalloc]
external mode : unit -> int = "caml_nc_aes_mode" [@@noalloc]
end
module DES = struct
external ddes : buffer -> off -> buffer -> off -> int -> unit = "caml_nc_des_ddes" [@@noalloc]
external des3key : secret -> off -> int -> unit = "caml_nc_des_des3key" [@@noalloc]
external cp3key : key -> unit = "caml_nc_des_cp3key" [@@noalloc]
external use3key : key -> unit = "caml_nc_des_use3key" [@@noalloc]
external k_s : unit -> int = "caml_nc_des_key_size" [@@noalloc]
end
module MD5 = struct
external init : ctx -> unit = "caml_nc_md5_init" [@@noalloc]
external update : ctx -> buffer -> off -> size -> unit = "caml_nc_md5_update" [@@noalloc]
external finalize : ctx -> buffer -> off -> unit = "caml_nc_md5_finalize" [@@noalloc]
external ctx_size : unit -> int = "caml_nc_md5_ctx_size" [@@noalloc]
end
module SHA1 = struct
external init : ctx -> unit = "caml_nc_sha1_init" [@@noalloc]
external update : ctx -> buffer -> off -> size -> unit = "caml_nc_sha1_update" [@@noalloc]
external finalize : ctx -> buffer -> off -> unit = "caml_nc_sha1_finalize" [@@noalloc]
external ctx_size : unit -> int = "caml_nc_sha1_ctx_size" [@@noalloc]
end
module SHA224 = struct
external init : ctx -> unit = "caml_nc_sha224_init" [@@noalloc]
external update : ctx -> buffer -> off -> size -> unit = "caml_nc_sha224_update" [@@noalloc]
external finalize : ctx -> buffer -> off -> unit = "caml_nc_sha224_finalize" [@@noalloc]
external ctx_size : unit -> int = "caml_nc_sha224_ctx_size" [@@noalloc]
end
module SHA256 = struct
external init : ctx -> unit = "caml_nc_sha256_init" [@@noalloc]
external update : ctx -> buffer -> off -> size -> unit = "caml_nc_sha256_update" [@@noalloc]
external finalize : ctx -> buffer -> off -> unit = "caml_nc_sha256_finalize" [@@noalloc]
external ctx_size : unit -> int = "caml_nc_sha256_ctx_size" [@@noalloc]
end
module SHA384 = struct
external init : ctx -> unit = "caml_nc_sha384_init" [@@noalloc]
external update : ctx -> buffer -> off -> size -> unit = "caml_nc_sha384_update" [@@noalloc]
external finalize : ctx -> buffer -> off -> unit = "caml_nc_sha384_finalize" [@@noalloc]
external ctx_size : unit -> int = "caml_nc_sha384_ctx_size" [@@noalloc]
end
module SHA512 = struct
external init : ctx -> unit = "caml_nc_sha512_init" [@@noalloc]
external update : ctx -> buffer -> off -> size -> unit = "caml_nc_sha512_update" [@@noalloc]
external finalize : ctx -> buffer -> off -> unit = "caml_nc_sha512_finalize" [@@noalloc]
external ctx_size : unit -> int = "caml_nc_sha512_ctx_size" [@@noalloc]
end
(* XXX TODO
* Unsolved: bounds-checked XORs are slowing things down considerably... *)
external xor_into : buffer -> off -> buffer -> off -> size -> unit = "caml_nc_xor_into" [@@noalloc]
external count8be : buffer -> off -> buffer -> off -> size -> unit = "caml_nc_count_8_be" [@@noalloc]
external count16be : buffer -> off -> buffer -> off -> size -> unit = "caml_nc_count_16_be" [@@noalloc]
external add16be : buffer -> off -> int64 -> unit = "caml_nc_add_16_be" [@@noalloc]
external blit : buffer -> off -> buffer -> off -> size -> unit = "caml_blit_bigstring_to_bigstring" [@@noalloc]