(*In this file, we verify the additional function hmac2, that we added to the c file in order to exercise the reuse of a key for several messages. The function calls hmac twice, (on the same message, using the same key) and puts the resulting (identical) digests side by side in a suitably large array.*)
Require sha.sha.
Local Open Scope logic.
Definition HMAC_Double_spec :=
DECLARE _HMAC
WITH keyVal: val, KEY:DATA,
msgVal: val, MSG:DATA,
sh: share, shmd: share, md: val, gv: globals
PRE [ _key OF tptr tuchar,
_key_len OF tint,
_d OF tptr tuchar,
_n OF tint,
_md OF tptr tuchar ]
PROP (readable_share sh; writable_share shmd;
has_lengthK (LEN KEY) (CONT KEY);
has_lengthD 512 (LEN MSG) (CONT MSG))
LOCAL (temp _md md; temp _key keyVal;
temp _key_len (Vint (Int.repr (LEN KEY)));
temp _d msgVal;
temp _n (Vint (Int.repr (LEN MSG)));
gvars gv)
SEP(data_block sh (CONT KEY) keyVal;
data_block sh (CONT MSG) msgVal;
K_vector gv;
memory_block shmd 64 md)
POST [ tptr tuchar ]
EX digest:_,
PROP (digest = HMAC256 (CONT MSG) (CONT KEY))
LOCAL (temp ret_temp md)
SEP(K_vector gv;
data_block shmd (digest++digest) md;
initPostKey sh keyVal (CONT KEY);
data_block sh (CONT MSG) msgVal).
Definition n324 := 324%Z.
Opaque n324.

Lemma body_hmac_double: semax_body HmacVarSpecs HmacFunSpecs
f_HMAC2 HMAC_Double_spec.