Skip to content

Commit

Permalink
aes derive_d derive_e: remove offset (always 0)
Browse files Browse the repository at this point in the history
  • Loading branch information
hannesm committed Mar 19, 2024
1 parent 4c96e52 commit f69f867
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/cipher_block.ml
Original file line number Diff line number Diff line change
Expand Up @@ -380,10 +380,10 @@ module AES = struct
| _ -> invalid_arg "AES.of_secret: key length %u" (String.length key)
in
let rk = Bytes.create (Native.AES.rk_s rounds) in
init key 0 rk rounds ;
init key rk rounds ;
Bytes.unsafe_to_string rk, rounds

let derive_d ?e buf off rk rs = Native.AES.derive_d buf off rk rs e
let derive_d ?e buf rk rs = Native.AES.derive_d buf rk rs e

let e_of_secret = of_secret_with Native.AES.derive_e
let d_of_secret = of_secret_with (derive_d ?e:None)
Expand Down
4 changes: 2 additions & 2 deletions src/native.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
module AES = struct
external enc : string -> int -> bytes -> int -> string -> int -> int -> unit = "mc_aes_enc_bc" "mc_aes_enc" [@@noalloc]
external dec : string -> int -> bytes -> int -> string -> int -> int -> unit = "mc_aes_dec_bc" "mc_aes_dec" [@@noalloc]
external derive_e : string -> int -> bytes -> int -> unit = "mc_aes_derive_e_key" [@@noalloc]
external derive_d : string -> int -> bytes -> int -> string option -> unit = "mc_aes_derive_d_key" [@@noalloc]
external derive_e : string -> bytes -> int -> unit = "mc_aes_derive_e_key" [@@noalloc]
external derive_d : string -> bytes -> int -> string option -> unit = "mc_aes_derive_d_key" [@@noalloc]
external rk_s : int -> int = "mc_aes_rk_size" [@@noalloc]
external mode : unit -> int = "mc_aes_mode" [@@noalloc]
end
Expand Down
12 changes: 6 additions & 6 deletions src/native/aes_aesni.c
Original file line number Diff line number Diff line change
Expand Up @@ -372,20 +372,20 @@ mc_aes_rk_size (value rounds) {
}

CAMLprim value
mc_aes_derive_e_key (value key, value off1, value rk, value rounds) {
mc_aes_derive_e_key (value key, value rk, value rounds) {
_mc_switch_accel(aesni,
mc_aes_derive_e_key_generic(key, off1, rk, rounds),
_mc_aesni_derive_e_key (_st_uint8_off (key, off1),
mc_aes_derive_e_key_generic(key, rk, rounds),
_mc_aesni_derive_e_key (_st_uint8 (key),
_bp_uint8 (rk),
Int_val (rounds)))
return Val_unit;
}

CAMLprim value
mc_aes_derive_d_key (value key, value off1, value kr, value rounds, value rk) {
mc_aes_derive_d_key (value key, value kr, value rounds, value rk) {
_mc_switch_accel(aesni,
mc_aes_derive_d_key_generic(key, off1, kr, rounds, rk),
_mc_aesni_derive_d_key (_st_uint8_off (key, off1),
mc_aes_derive_d_key_generic(key, kr, rounds, rk),
_mc_aesni_derive_d_key (_st_uint8 (key),
_bp_uint8 (kr),
Int_val (rounds),
Is_block(rk) ? _bp_uint8(Field(rk, 0)) : 0))
Expand Down
8 changes: 4 additions & 4 deletions src/native/aes_generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -1232,17 +1232,17 @@ mc_aes_rk_size_generic (value rounds) {
}

CAMLprim value
mc_aes_derive_e_key_generic (value key, value off1, value rk, value rounds) {
mc_aes_derive_e_key_generic (value key, value rk, value rounds) {
mc_rijndaelSetupEncrypt (_bp_uint32 (rk),
_st_uint8_off (key, off1),
_st_uint8 (key),
keybits_of_r (Int_val (rounds)));
return Val_unit;
}

CAMLprim value
mc_aes_derive_d_key_generic (value key, value off1, value kr, value rounds, value __unused (rk)) {
mc_aes_derive_d_key_generic (value key, value kr, value rounds, value __unused (rk)) {
mc_rijndaelSetupDecrypt (_bp_uint32 (kr),
_st_uint8_off (key, off1),
_st_uint8 (key),
keybits_of_r (Int_val (rounds)));
return Val_unit;
}
Expand Down
4 changes: 2 additions & 2 deletions src/native/mirage_crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ extern struct _mc_cpu_features mc_detected_cpu_features;
CAMLprim value mc_aes_rk_size_generic (value rounds);

CAMLprim value
mc_aes_derive_e_key_generic (value key, value off1, value rk, value rounds);
mc_aes_derive_e_key_generic (value key, value rk, value rounds);

CAMLprim value
mc_aes_derive_d_key_generic (value key, value off1, value kr, value rounds, value __unused (rk));
mc_aes_derive_d_key_generic (value key, value kr, value rounds, value __unused (rk));

CAMLprim value
mc_aes_enc_generic (value src, value off1, value dst, value off2, value rk, value rounds, value blocks);
Expand Down

0 comments on commit f69f867

Please sign in to comment.