Instance CompSpecs : compspecs.Instance CompSpecs_Preserve: change_composite_env spec_sha.CompSpecs CompSpecs.Definition Vprog : varspecs.Record TREP := mkTrep { t: type; v: reptype t}.Record TREP := mkTrep { t: type; v: reptype t}.Record TREP := mkTrep { t: type; v: reptype t}.Record TREP := mkTrep { t: type; v: reptype t}.Definition tp_of (T:TREP) : type.Definition v_of (T:TREP) : reptype (tp_of T).(****** Coq-representation of hmac states, and predicates characterizing the incremental functions.

If the corresponding predicates for SHA operations were modeled as functions, the ones here could be, too *)

Inductive hmacabs :=  (* HMAC abstract state *)
 HMACabs: forall (ctx iSha oSha: s256abs) (*sha structures for md_ctx, i_ctx, o_ctx*),
                 hmacabs.(****** Coq-representation of hmac states, and predicates characterizing the incremental functions.

If the corresponding predicates for SHA operations were modeled as functions, the ones here could be, too *)

Inductive hmacabs :=  (* HMAC abstract state *)
 HMACabs: forall (ctx iSha oSha: s256abs) (*sha structures for md_ctx, i_ctx, o_ctx*),
                 hmacabs.Definition absCtxt (h:hmacabs): s256abs :=
  match h with HMACabs ctx _ _ => ctx end.Definition innerShaInit (k: list byte):s256abs :=
   HMAC_SHA256.mkArg k Ipad.Definition outerShaInit (k: list byte):s256abs :=
   HMAC_SHA256.mkArg k Opad.Definition hmacInit (k:list byte):hmacabs :=
  let key := HMAC_SHA256.mkKey k in
  let iS := innerShaInit key in
  let oS := outerShaInit key in
  HMACabs iS iS oS.Definition hmacUpdate (data: list byte) (h1:hmacabs): hmacabs :=
  match h1 with
    HMACabs ctx1 iS oS
  => let ctx2 := ctx1 ++ data in
     HMACabs ctx2 iS oS
  end.Definition hmacFinalSimple h : list byte :=
  match h with
    HMACabs ctx iS oS
  => let inner := SHA256.SHA_256 ctx in
     SHA256.SHA_256 (oS ++ inner)
  end.Definition hmacFinal h : (hmacabs * list byte) :=
  match h with
    HMACabs ctx iS oS
  => let inner := SHA256.SHA_256 ctx in
     let outerArg := oS ++ inner in
     (HMACabs outerArg iS oS, SHA256.SHA_256 outerArg)
  end.(*hmac cleanup not modelled*)

Definition hmacSimple (k:list byte) (data:list byte):list byte:=
  hmacFinalSimple (hmacUpdate data (hmacInit k)).Definition hmac (k:list byte) (data:list byte):(hmacabs * list byte) :=
  hmacFinal (hmacUpdate data (hmacInit k)).

(* Specifications: *)
Lemma hmacSimple_sound k data: hmacSimple k data = HMAC256 data k.
Lemma hmac_sound k data: snd(hmac k data) = HMAC256 data k.
Lemma hmacUpdate_app data data' h: hmacUpdate data (hmacUpdate data' h) = hmacUpdate (data'++data) h.