

(* Modele LAK avec du nounif permettant d'assurer la non-terminaison et suffisament précis pour une query d'authentification simplifiée a partir de hkey(k)*)
(* je suis surprise de voir can not be proved sur la query complete  alors que ProVerif dit is true quand je lui decompose *)

(* -------------------------------------------------- *)
(*	       FIXED LAK                              *)
(* -------------------------------------------------- *)

(* ==THEORY== *)
(* Public communication channel *)
free i : channel.
free r : channel.

(*free rI:channel[private].
free rR:channel[private].*)
free  k : bitstring[private].

(* functions *)
fun hone(bitstring) : bitstring.
fun htwo(bitstring): bitstring.
fun hkey(bitstring) : bitstring[private].


(*not attacker(rI).
not attacker(rR).
not x:bitstring;attacker(hkey(x)).
not attacker(k).
*)

set preciseActions = true.

nounif x:bitstring; mess(new rI,*x).
nounif x:bitstring; mess(new rR,*x).

(*  nounif x:bitstring; attacker(hone( *x)).
*)


(* == DECLARATIONS OF EVENTS == *)
event Rin_1(bitstring,bitstring).
event Rout_1(bitstring,bitstring,bitstring).
event Rin_2(bitstring,bitstring,bitstring,bitstring).
event Rtest_1(bitstring,bitstring,bitstring,bitstring).
event Rout_2(bitstring,bitstring,bitstring,bitstring,bitstring).
event Iout_1(bitstring,bitstring).
event Iin_1(bitstring,bitstring,bitstring).
event Itest_1(bitstring,bitstring,bitstring).
event Iout_2(bitstring,bitstring,bitstring,bitstring).


(* == DECLARATIONS OF QUERIES == *)
(* query k:bitstring,
      m1:bitstring, m2:bitstring, m3:bitstring;
   (event(Rtest_1(k,m1,m2,m3))  ==>
   (event(Rin_2(k,m1,m2,m3))  ==>
   (event(Iout_2(k,m1,m2,m3))  ==>
   (event(Iin_1(k,m1,m2))  ==>
   (event(Rout_1(k,m1,m2))  ==>
   (event(Rin_1(k,m1))  ==>
   (event(Iout_1(k,m1))))))))).

*)

(*
query k:bitstring,
      m1:bitstring, m2:bitstring;
   (event(Itest_1(hkey(k),m1,m2))  ==>
   (event(Iin_1(hkey(k),m1,m2))  ==>
   (event(Rout_1(hkey(k),m1,m2))  ==>
   (event(Rin_1(hkey(k),m1))  ==>
   (event(Iout_1(hkey(k),m1))))))).
*)

(* cannot be proved *)
 query k:bitstring,
      m1:bitstring, m2:bitstring;
   (event(Itest_1(hkey(k),m1,m2))  ==>
   (event(Rout_1(hkey(k),m1,m2))  ==>
   (event(Iout_1(hkey(k),m1))))).

(* is true *)
query k:bitstring,
      m1:bitstring, m2:bitstring;
   event(Itest_1(hkey(k),m1,m2))  ==> (event(Rout_1(hkey(k),m1,m2))  &&  event(Iout_1(hkey(k),m1))).


(* is true *)
query k:bitstring,
      m1:bitstring, m2:bitstring;
    (event(Itest_1(hkey(k),m1,m2)) && event(Rout_1(hkey(k),m1,m2)))  ==> event(Iout_1(hkey(k),m1)).



(* == PROTOCOL WITH EVENTS == *)
let SYSTEM =
 (* ! *)
  new rI:channel;
  new rR:channel; (
      out(rI,k) | out(rR,k) |
     !
      ((
        new r1: bitstring;
        in(rI,yI:bitstring);
         event Iout_1(yI,r1);
        out(i, r1);
        in(i, x: bitstring);
        event Iin_1(yI,r1,x);
        let ((xr2: bitstring,xh: bitstring)) = x in
        let (=hone((r1,xr2,yI))) = xh in
        event Itest_1(yI,r1,x);
        event Iout_2(yI,r1,x,htwo((xh,r1,yI)));
        out(i, htwo((xh,r1,yI)));
        out(rI,hkey(yI))
      )|(
        new r2: bitstring;
        in(rR,yR:bitstring);
        in(r, xr1: bitstring);
        event Rin_1(yR,xr1);
        event Rout_1(yR,xr1,(r2,hone((xr1,r2,yR))));
        out(r, (r2,hone((xr1,r2,yR))));
        in(r, x2: bitstring);
        event Rin_2(yR,xr1,(r2,hone((xr1,r2,yR))),x2);
        let (=htwo((hone((xr1,r2,yR)),xr1,yR))) = x2 in
        event Rtest_1(yR,xr1,(r2,hone((xr1,r2,yR))),x2);
        new nextStep: bitstring;
        event Rout_2(yR,xr1,(r2,hone((xr1,r2,yR))),x2,nextStep);
        out(i, nextStep);
        out(rR,hkey(yR))

      ))
)
.
process SYSTEM

(* EXPECTPV
RESULT event(Itest_1(hkey(k_1),m1,m2)) ==> (event(Rout_1(hkey(k_1),m1,m2)) ==> event(Iout_1(hkey(k_1),m1))) is true.
RESULT event(Itest_1(hkey(k_1),m1,m2)) ==> event(Rout_1(hkey(k_1),m1,m2)) && event(Iout_1(hkey(k_1),m1)) is true.
RESULT event(Itest_1(hkey(k_1),m1,m2)) && event(Rout_1(hkey(k_1),m1,m2)) ==> event(Iout_1(hkey(k_1),m1)) is true.
0.020s (user 0.012s + system 0.008s), max rss 9328K
END *)
