Hint Rewrite change_compspecs_t_struct_SHA256state_st' : norm.
Definition initPostKeyNullConditional r (c:val) (k: val) h wsh sh key ctxkey: mpred:=
match k with
Vint z => if Int.eq z Int.zero
then if zeq r Z0
then (hmacstate_PreInitNull wsh key h c) * (data_at_ Tsh (tarray tuchar 64) ctxkey)
else FF
else FF
| Vptr b ofs => if zeq r 0 then FF
else
((data_at wsh t_struct_hmac_ctx_st (*keyed*)HMS c) *
(data_at Tsh (tarray tuchar 64) (map Vubyte (HMAC_SHA256.mkKey key))
ctxkey)  *
(data_at sh (tarray tuchar (Zlength key)) (map Vubyte key)
(Vptr b ofs)))
| _ => FF
end.
Definition PostKeyNull c k pad gv h1 l wsh sh key ckb ckoff: environ -> mpred :=
EX  cb : block,
(EX  cofs : ptrofs,
(EX  r : Z,
PROP  (c = Vptr cb cofs /\ (r = 0 \/ r = 1))
LOCAL  (temp _reset (Vint (Int.repr r));
lvar _ctx_key (tarray tuchar 64) (Vptr ckb ckoff);
lvar _pad (tarray tuchar 64) pad; temp _ctx c;
temp _key k; temp _len (Vint (Int.repr l));
gvars gv)
SEP  (data_at_ Tsh (tarray tuchar 64) pad;
initPostKeyNullConditional r c k h1 wsh sh key (Vptr ckb ckoff);
K_vector gv))).

(* Specifications: *)
Lemma Init_part1_j_lt_len Espec (kb ckb cb: block) (kofs ckoff cofs: ptrofs)
l wsh sh (key: list byte) gv pad
(HMS' : reptype t_struct_hmac_ctx_st): forall
(Hwsh: writable_share wsh)
(Hsh: readable_share sh)
(KL1 : l = Zlength key)
(KL2 : 0 < l <= Int.max_signed)
(KL3 : l * 8 < two_p 64)
(HMS' : reptype t_struct_hmac_ctx_st)
(KHMS : HMS' = HMS)
(FC_ctx : field_compatible t_struct_hmac_ctx_st [] (Vptr cb cofs))
(FC_md_ctx : field_compatible t_struct_hmac_ctx_st [StructField _md_ctx]
(Vptr cb cofs))
(FC_cxtkey : field_compatible (Tarray tuchar 64 noattr) [] (Vptr ckb ckoff))
(lt_64_l : 64 < l),
@semax CompSpecs Espec
(func_tycontext f_HMAC_Init HmacVarSpecs HmacFunSpecs nil)
(PROP  ()
LOCAL  (temp _j (Vint (Int.repr 64)); temp _reset (Vint (Int.repr 1));
lvar _ctx_key (tarray tuchar 64) (Vptr ckb ckoff);
lvar _pad (tarray tuchar 64) pad; temp _ctx (Vptr cb cofs);
temp _key (Vptr kb kofs); temp _len (Vint (Int.repr l));
gvars gv)
SEP  (data_at sh (tarray tuchar (Zlength key)) (map Vubyte key)
(Vptr kb kofs); data_at_ Tsh (tarray tuchar 64) pad;
K_vector gv; data_at_ wsh t_struct_hmac_ctx_st (Vptr cb cofs);
data_at_ Tsh (tarray tuchar 64) (Vptr ckb ckoff)))
(Ssequence
(Scall None
(Evar _SHA256_Init
(Tfunction
(Tcons (tptr (Tstruct _SHA256state_st noattr)) Tnil)
tvoid cc_default))
[Eaddrof
(Efield
(Ederef
(Etempvar _ctx
(tptr (Tstruct _hmac_ctx_st noattr)))
(Tstruct _hmac_ctx_st noattr)) _md_ctx
(Tstruct _SHA256state_st noattr))
(tptr (Tstruct _SHA256state_st noattr))])
(Ssequence
(Scall None
(Evar _SHA256_Update
(Tfunction
(Tcons (tptr (Tstruct _SHA256state_st noattr))
(Tcons (tptr tvoid) (Tcons tuint Tnil)))
tvoid cc_default))
[Eaddrof
(Efield
(Ederef
(Etempvar _ctx
(tptr (Tstruct _hmac_ctx_st noattr)))
(Tstruct _hmac_ctx_st noattr)) _md_ctx
(Tstruct _SHA256state_st noattr))
(tptr (Tstruct _SHA256state_st noattr));
Etempvar _key (tptr tuchar); Etempvar _len tint])
(Ssequence
(Scall None
(Evar _SHA256_Final
(Tfunction
(Tcons (tptr tuchar)
(Tcons
(tptr (Tstruct _SHA256state_st noattr))
Tnil)) tvoid cc_default))
[Evar _ctx_key (tarray tuchar 64);
Eaddrof
(Efield
(Ederef
(Etempvar _ctx
(tptr (Tstruct _hmac_ctx_st noattr)))
(Tstruct _hmac_ctx_st noattr)) _md_ctx
(Tstruct _SHA256state_st noattr))
(tptr (Tstruct _SHA256state_st noattr))])
(Scall None
(Evar _memset (Tfunction
(Tcons (tptr tvoid)
(Tcons tint (Tcons tuint Tnil)))
(tptr tvoid) cc_default))
((Ebinop Oadd (Evar _ctx_key (tarray tuchar 64))
(Econst_int (Int.repr 32) tint) (tptr tuchar)) ::
(Econst_int (Int.repr 0) tint) ::
(Econst_int (Int.repr 32) tint) :: nil)))))
(normal_ret_assert  (PROP  ()
LOCAL  (temp _reset (Vint (Int.repr 1));
lvar _ctx_key (tarray tuchar 64) (Vptr ckb ckoff);
lvar _pad (tarray tuchar 64) pad; temp _ctx (Vptr cb cofs);
temp _key (Vptr kb kofs); temp _len (Vint (Int.repr l));
gvars gv)
SEP  (data_at_ Tsh (tarray tuchar 64) pad;
data_at wsh t_struct_hmac_ctx_st HMS' (Vptr cb cofs);
data_at sh (tarray tuchar (Zlength key))
(map Vubyte key) (Vptr kb kofs);
data_at Tsh (tarray tuchar 64)
(map Vubyte (HMAC_SHA256.mkKey key))
(Vptr ckb ckoff); K_vector gv))).