Skip to content

Commit

Permalink
ghash and initkey: 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 906d5a0 commit 4c96e52
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/cipher_block.ml
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,12 @@ module Modes = struct
let derive cs =
assert (String.length cs >= tagsize);
let k = Bytes.create keysize in
Native.GHASH.keyinit cs 0 k;
Native.GHASH.keyinit cs k;
Bytes.unsafe_to_string k
let hash0 = Bytes.make tagsize '\x00'
let digesti ~key i =
let res = Bytes.copy hash0 in
i (fun cs -> Native.GHASH.ghash key res cs 0 (String.length cs));
i (fun cs -> Native.GHASH.ghash key res cs (String.length cs));
Bytes.unsafe_to_string res
end

Expand Down
4 changes: 2 additions & 2 deletions src/native.ml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ end

module GHASH = struct
external keysize : unit -> int = "mc_ghash_key_size" [@@noalloc]
external keyinit : string -> int -> bytes -> unit = "mc_ghash_init_key" [@@noalloc]
external ghash : string -> bytes -> string -> int -> int -> unit = "mc_ghash" [@@noalloc]
external keyinit : string -> bytes -> unit = "mc_ghash_init_key" [@@noalloc]
external ghash : string -> bytes -> string -> int -> unit = "mc_ghash" [@@noalloc]
external mode : unit -> int = "mc_ghash_mode" [@@noalloc]
end

Expand Down
8 changes: 4 additions & 4 deletions src/native/ghash_ctmul.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,14 +284,14 @@ static inline void __copy (uint64_t key[2], uint32_t m[4]) {
m[3] = key[1] >> 32;
}

CAMLprim value mc_ghash_init_key_generic (value key, value off, value m) {
CAMLprim value mc_ghash_init_key_generic (value key, value m) {
//push key at off into m
__copy ((uint64_t *) _st_uint8_off(key, off), (uint32_t *) m);
__copy ((uint64_t *) _st_uint8(key), (uint32_t *) m);
return Val_unit;
}

CAMLprim value mc_ghash_generic (value m, value hash, value src, value off, value len) {
br_ghash_ctmul(Bp_val(hash), Bp_val(m), _st_uint8_off(src, off), Int_val(len));
CAMLprim value mc_ghash_generic (value m, value hash, value src, value len) {
br_ghash_ctmul(Bp_val(hash), Bp_val(m), _st_uint8(src), Int_val(len));
return Val_unit;
}

Expand Down
8 changes: 4 additions & 4 deletions src/native/ghash_generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,15 @@ CAMLprim value mc_ghash_key_size_generic (__unit ()) {
return Val_int (sizeof (__uint128_t) * __t_size);
}

CAMLprim value mc_ghash_init_key_generic (value key, value off, value m) {
__derive ((uint64_t *) _st_uint8_off (key, off), (__uint128_t *) Bp_val (m));
CAMLprim value mc_ghash_init_key_generic (value key, value m) {
__derive ((uint64_t *) _st_uint8 (key), (__uint128_t *) Bp_val (m));
return Val_unit;
}

CAMLprim value
mc_ghash_generic (value m, value hash, value src, value off, value len) {
mc_ghash_generic (value m, value hash, value src, value len) {
__ghash ((__uint128_t *) Bp_val (m), (uint64_t *) Bp_val (hash),
_st_uint8_off (src, off), Int_val (len) );
_st_uint8 (src), Int_val (len) );
return Val_unit;
}

Expand Down
12 changes: 6 additions & 6 deletions src/native/ghash_pclmul.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,19 +196,19 @@ CAMLprim value mc_ghash_key_size (__unit ()) {
return s;
}

CAMLprim value mc_ghash_init_key (value key, value off, value m) {
CAMLprim value mc_ghash_init_key (value key, value m) {
_mc_switch_accel(pclmul,
mc_ghash_init_key_generic(key, off, m),
__derive ((__m128i *) _st_uint8_off (key, off), (__m128i *) Bp_val (m)))
mc_ghash_init_key_generic(key, m),
__derive ((__m128i *) _st_uint8 (key), (__m128i *) Bp_val (m)))
return Val_unit;
}

CAMLprim value
mc_ghash (value k, value hash, value src, value off, value len) {
mc_ghash (value k, value hash, value src, value len) {
_mc_switch_accel(pclmul,
mc_ghash_generic(k, hash, src, off, len),
mc_ghash_generic(k, hash, src, len),
__ghash ( (__m128i *) Bp_val (k), (__m128i *) Bp_val (hash),
(__m128i *) _st_uint8_off (src, off), Int_val (len) ))
(__m128i *) _st_uint8 (src), Int_val (len) ))
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 @@ -102,10 +102,10 @@ mc_aes_dec_generic (value src, value off1, value dst, value off2, value rk, valu

CAMLprim value mc_ghash_key_size_generic (__unit ());

CAMLprim value mc_ghash_init_key_generic (value key, value off, value m);
CAMLprim value mc_ghash_init_key_generic (value key, value m);

CAMLprim value
mc_ghash_generic (value m, value hash, value src, value off, value len);
mc_ghash_generic (value m, value hash, value src, value len);

CAMLprim value
mc_xor_into_generic (value b1, value off1, value b2, value off2, value n);
Expand Down

0 comments on commit 4c96e52

Please sign in to comment.