(* Copyright 2012-2015 by Adam Petcher.				* * Use of this source code is governed by the license described	* * in the LICENSE file at the root of the source tree.		*)
Set Implicit Arguments.
(*Add LoadPath "../FCF".*)
Section RelatedKeyAttack.
Variable K D R Phi_s : Set.
Variable K_EqDec : EqDec K.
Variable D_EqDec : EqDec D.
Variable R_EqDec : EqDec R.
Variable RndK : Comp K.
Variable RndR : Comp R.
Variable f : K -> D -> R.
Variable Phi : Phi_s -> K -> K.
Variable A : OracleComp (Phi_s * D) R bool.
Definition RKA_F k (s : unit) p :=
[phi_s, x] <-2 p; ret (f (Phi phi_s k) x, tt).
Definition RKA_randomFunc := @randomFunc (K * D) R RndR _.
Definition RKA_R k s p :=
[phi_s, x] <-2 p; (RKA_randomFunc s (Phi phi_s k, x)).
Definition RKA_G0 :=
k <-$ RndK;
[b, _] <-$2 A _ _ (RKA_F k) tt;
ret b.
Definition RKA_G1 :=
k <-$ RndK;
[b, _] <-$2 A _ _ (RKA_R k) nil;
ret b.
Definition RKA_Advantage :=
| Pr[RKA_G0] - Pr[RKA_G1] |.
End RelatedKeyAttack.
Definition dual_f (A B C : Set)(f : A -> B -> C) : B -> A -> C :=
fun b a => f a b.
Section NMAC_to_HMAC.
Variable c p : nat.
Definition b := @b c p.
Variable h : Bvector c -> Bvector b -> Bvector c.
Variable iv : Bvector c.
Variable fpad : Bvector c -> Bvector p.
Definition GHMAC_2K := GHMAC_2K h iv fpad.
Variable opad ipad : Bvector b.
Hypothesis opad_ne_ipad : opad <> ipad.
Definition GHMAC := GHMAC h iv fpad opad ipad.
Variable A : OracleComp (list (Bvector b)) (Bvector c) bool.
Definition app_fpad := @app_fpad c p fpad.
Definition h_star := h_star p h.
Definition GNMAC := GNMAC h fpad.
Definition A_NMAC :=
x <-$ {0, 1}^(c + c);
[b, _] <-$2 A _ _ (f_oracle GNMAC _ x) tt;
ret b.
Definition A_HMAC :=
x <-$ {0, 1}^b;
[b, _] <-$2 A _ _ (f_oracle GHMAC _ x) tt;
ret b.

Theorem GHMAC_2K_GNMAC_equiv :
forall k ls,
let (k_Out, k_In) := splitVector b b k in
let k' := Vector.append (h iv k_Out) (h iv k_In) in
GHMAC_2K k ls = GNMAC k' ls.