param keyCompromise = strict.
(* Needham-Schroeder shared key *)

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.

(* constants 0 and 1 *)

data c0/0.
data c1/0.

(* Secrecy assumptions *)

not Kas.
not Kbs.

query attacker:secretA[];
      attacker:secretB[].
query evinj:endAparam(x,y) ==> evinj:beginAparam(x,y).
query evinj:endAkey(x,y,z) ==> evinj:beginAkey(x,y,z).
query evinj:endBparam(x,y) ==> evinj:beginBparam(x,y).
query evinj:endBkey(x,y,z) ==> evinj:beginBkey(x,y,z).


let processA =
	new secretA;
	in(c, h);
	event beginBparam(A,h);
	new Na;
	out(c,(A, h, Na));
	in(c,m2);
	let (=Na, =h, k, m) = decrypt(m2, Kas) in
	event beginBkey(A, h, k);
	out(c,m);
	in(c, m3);
	let (=c0, n) = decrypt(m3, k) in
	out(c, encrypt((c1, n), k));
	if h = B then
	event endAparam(A, h);
	event endAkey(A, h, k);
	out(c, encrypt(secretA, k)).

let processB =
	new secretB;
	in(c,m4);
	let (k,h) = decrypt(m4,Kbs) in
	event beginAparam(h, B);
	event beginAkey(h, B, k);
	new Nb;
	out(c, encrypt((c0, Nb), k));
	in(c,m5);
	let (=c1, =Nb) = decrypt(m5,k) in
	if h = A then
	event endBparam(h, B);
	event endBkey(h, B, k);
	out(c, encrypt(secretB, k)).

let processS =
	in(c, (h1,h2,n));
	let ks1 = getkey(h1) in
	let ks2 = getkey(h2) in
	new k;
	out(c, encrypt((n, h2, k, encrypt((k,h1),ks2)), ks1)).

process
	new Kas;
	new Kbs;
	let A = host(Kas) in
	let B = host(Kbs) in
	out(c, A);
	out(c, B);
	((!processA) | (!processB) | (!processS))

(* EXPECTPV
RESULT not attacker_p1:secretA[!comp = @session1(),!1 = v_8] is true.
RESULT not attacker_p1:secretB[!comp = @session1(),!1 = v_8] cannot be proved.
RESULT evinj:endAparam(@session1(),x,y) ==> evinj:beginAparam(v_8,x,y) is true.
RESULT evinj:endAkey(@session1(),x,y,z) ==> evinj:beginAkey(v_8,x,y,z) is true.
RESULT evinj:endBparam(@session1(),x,y) ==> evinj:beginBparam(v_8,x,y) cannot be proved.
RESULT (but ev:endBparam(@session1(),x,y) ==> ev:beginBparam(v_8,x,y) is true.)
RESULT evinj:endBkey(@session1(),x,y,z) ==> evinj:beginBkey(v_8,x,y,z) cannot be proved.
RESULT (but ev:endBkey(@session1(),x,y,z) ==> ev:beginBkey(v_8,x,y,z) is true.)
0.424s (user 0.372s + system 0.052s), max rss 11304K
END *)
