free c.

(* 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 kA.
not kB.

private free bad.

param verboseRules = yes.

private free secretA, secretB.
query attacker:secretA;
      attacker:secretB.

let processA = 
	in(c, hostB0);
	new C; new Na;
        out(c, (C, hostA, hostB0, encrypt((Na, C, hostA, hostB0), kA)));
	in(c, (=C, m2));
	let (=Na, k) = decrypt(m2, kA) in
	(* OK *)
	(if hostB0 = hostB then 
	out(c, encrypt(secretA, k)))
        else out(c, bad).


let processB = 
	in(c, (C1, hostA1, =hostB, m2));
	new Nb;
	out(c, (C1, hostA1, hostB, m2, encrypt((Nb, C1, hostA1, hostB), kB)));
	in(c, (=C1, m3, m4));
	let (=Nb, k) = decrypt(m4, kB) in
	out(c, (C1, m3));
	(* OK *)
	if hostA1 = hostA then
	out(c, encrypt(secretB, k)).


let processS = in(c, (C1, hostA1, hostB1, m2, m3));
	       let (Na1, =C1, =hostA1, =hostB1) = decrypt(m2, getkey(hostA1)) in
	       let (Nb1, =C1, =hostA1, =hostB1) = decrypt(m3, getkey(hostB1)) in
	       new k;
               out(c, (C1, encrypt((Na1, k), getkey(hostA1)), 
                           encrypt((Nb1, k), getkey(hostB1)))).


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

(* EXPECTPV
RESULT not attacker:secretA[] is true.
RESULT not attacker:secretB[] is true.
0.044s (user 0.016s + system 0.028s), max rss 8844K
END *)
