(*
Yahalom protocol. Version of Burrows, Abadi, Needham, SRC039

Message 1 A -> B: A; Na 
Message 2 B -> S: B; { A; Na; Nb }Kbs 
Message 3 S -> A: { B; Kab; Na; Nb }Kas ; { A; Kab }Kbs 
Message 4 A -> B: { A; Kab }Kbs ; { Nb }Kab

*)

free c.

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

(* Shared key cryptography *)

fun encrypt/2.
reduc decrypt(encrypt(x,y),y) = x.

(* Secrecy assumptions *)

not kas.
not kbs.

private free secretA, secretB.

noninterf secretA, secretB.
noninterf secretA.
noninterf secretB.

let processA =
	new Na;
	out(c, (host(kas), Na));
	in(c, (cert1, cert2));
	let (b, k, =Na, nb) = decrypt(cert1, kas) in
	out(c, (cert2, encrypt(nb, k)));
	(* OK *)
	if b = host(kbs) then
	out(c, encrypt(secretA, k)).

let processB =
	in(c, (a,na));
	new Nb;
	out(c, (host(kbs), encrypt((a, na, Nb), kbs)));
	in(c, (cert2, m));
	let (=a, k) = decrypt(cert2, kbs) in
	if Nb = decrypt(m, k) then
	(* OK *)
	if a = host(kas) then
	out(c, encrypt(secretB, k)).

let processS =
	in(c, (h2, m));
	let k2 = getkey(h2) in
	let (h1, n1, n2) = decrypt(m, k2) in
	let k1 = getkey(h1) in
	new k;
	out(c, (encrypt((h2, k, n1, n2), k1), encrypt((h1, k), k2))).


process new kas; new kbs; 
	((!processA) | (!processB) | (!processS))

(* EXPECTPV
RESULT Non-interference secretA, secretB cannot be proved.
RESULT Non-interference secretA is true.
RESULT Non-interference secretB is true.
0.120s (user 0.096s + system 0.024s), max rss 9348K
END *)
