param maxDepth = 4.

free c.
(*

WooLam shared-key auth protocol
Corrections of Gordon, Jeffrey CSFW'01

A -> B : A
B -> A : N (fresh)
A -> B : { m3, B, N }_kAS
B -> S : A,B,{ m3, B, N }_kAS
S -> B : { m5, A, N }_kBS
B: verify { m5, A, N }_kBS = the message from S

Correct.

Full agreement is wrong because the adversary can make B see something
different from { m3, B, N }_kAS (even though the server and A correctly see it)
so this is no real attack.

*)

(* Tags *)

data m3/0.
data m5/0.

(* Shared-key cryptography *)

fun encrypt/2.
reduc decrypt(encrypt(m,k),k) = m.

(* Host name / key *)

fun host/1.
private reduc getkey(host(x)) = x.

(* Secrecy assumptions *)

not kBS.
not kAS.

query evinj:endBparam(x) ==> evinj:beginBparam(x).
query evinj:endBfull(x,y,z) ==> evinj:beginBfull(x,y,z).

let processA = 
	in(c, hostB2); (* Choose the B host *)
	event beginBparam(hostB2);
        out(c,hostA); in(c,n); 
	event beginBfull(hostB2, hostA, n);
        out(c, encrypt((m3, hostB2, n), kAS)).

let processB = 
	in(c, hostA2);
	new N;
	out(c, N);
	in(c, m);
        out(c, (hostA2, hostB, m));
        in(c, m2);
	let (=m5, =hostA2, =N) = decrypt(m2, kBS) in
        (* OK *)
        if hostA2 = hostA then 
	event endBparam(hostB);
	event endBfull(hostB, hostA2, N).

let processS = 
	in(c,(hostA1, hostB1, m2));
        let (=m3, =hostB1, n) = decrypt(m2, getkey(hostA1)) in
        out(c, encrypt((m5, hostA1, n), getkey(hostB1))).

process new kAS; new kBS;
        let hostA = host(kAS) in
        let hostB = host(kBS) in
	out(c, hostA); out(c, hostB);
	((!processA) | (!processB) | (!processS))

(* EXPECTPV
RESULT evinj:endBparam(x) ==> evinj:beginBparam(x) is true.
RESULT evinj:endBfull(x,y,z) ==> evinj:beginBfull(x,y,z) cannot be proved.
RESULT (even ev:endBfull(x,y,z) ==> ev:beginBfull(x,y,z) cannot be proved.)
0.024s (user 0.008s + system 0.016s), max rss 8664K
END *)
