(* Definition ltb (n m:nat):bool := if beq_nat n m then false else leb n m. Lemma ltb_char n m: ltb n m = true <-> (n<m)%nat. unfold ltb. remember (beq_nat n m). destruct b; symmetry in Heqb; split; intros. inv H. apply beq_nat_true in Heqb. subst. omega. apply beq_nat_false in Heqb. apply leb_complete in H. omega. apply leb_correct. omega. Qed. *)
Function toBlocks (l : Blist) {measure length l} : list Blist :=
(match l with
| nil => nil
| _ :: _ => if leb (List.length l) 511 then [firstn 512 l]
else firstn 512 l :: toBlocks (skipn 512 l)
end)%list.
Definition sha_splitandpad_blocks (msg : Blist) : list Blist :=
toBlocks (sha_splitandpad_inc msg).

Theorem HMAC_list_concat_sap_instantiated
h (HH: forall x y, length x = c -> length y = b -> length (h x y)  = c)
iv (IV: length iv = c) (op ip : Blist) (IL: length ip = b) (OL: length op = b)
(FOLD_hash_blocks_eq : forall (l : Blist) (ls : list Blist),
length l = b ->
Forall (fun x : list bool => length x = b) ls ->
fold_left h (l :: ls) iv =
hash_blocks_bits _ B h iv (l ++ concat ls))
: forall (k m : Blist), length k = b ->
HMAC_List.HMAC c p h iv sha_splitandpad_blocks fpad op ip k m =
HMAC_Concat.HMAC c p B h iv sha_splitandpad_inc fpad op ip k m.