Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mirage-crypto: revise DES to avoid global state in key derivation / key usage #223

Merged
merged 3 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/cipher_block.ml
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,7 @@ module DES = struct
invalid_arg "DES.of_secret: key length %u" (String.length key) ;
let key = Bytes.of_string key in
let keybuf = Bytes.create k_s in
Native.DES.des3key key direction ;
Native.DES.cp3key keybuf ;
Native.DES.des3key key direction keybuf;
Bytes.unsafe_to_string keybuf

let e_of_secret = gen_of_secret ~direction:0
Expand All @@ -438,8 +437,7 @@ module DES = struct
let of_secret secret = (e_of_secret secret, d_of_secret secret)

let encrypt ~key ~blocks src off1 dst off2 =
Native.DES.use3key key ;
Native.DES.ddes src off1 dst off2 blocks
Native.DES.ddes src off1 dst off2 blocks key

let decrypt = encrypt
end
Expand Down
6 changes: 2 additions & 4 deletions src/native.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ module AES = struct
end

module DES = struct
external ddes : string -> int -> bytes -> int -> int -> unit = "mc_des_ddes" [@@noalloc]
external des3key : bytes -> int -> unit = "mc_des_des3key" [@@noalloc]
external cp3key : bytes -> unit = "mc_des_cp3key" [@@noalloc]
external use3key : string -> unit = "mc_des_use3key" [@@noalloc]
external ddes : string -> int -> bytes -> int -> int -> string -> unit = "mc_des_ddes_bc" "mc_des_ddes" [@@noalloc]
external des3key : bytes -> int -> bytes -> unit = "mc_des_des3key" [@@noalloc]
external k_s : unit -> int = "mc_des_key_size" [@@noalloc]
end

Expand Down
Loading
Loading