(* Signed Diffie-Hellman
	A -> B : { e^n0 }skA, pkA    (n0 fresh)
        B -> A : { e^n1 }skB         (n1 fresh)
          A and B compute the key as k = (e^n0)^n1 = (e^n1)^n0
        A -> B : { s }k

 *)

free c.
private free s.

(* Signatures *)

fun sign/2.
fun pk/1.
reduc getmess(sign(m,k)) = m.
reduc checksign(sign(m,k), pk(k)) = m.

(* Shared key cryptography *)

fun enc/2.
reduc dec(enc(x,y),y) = x.

(* Diffie-Hellman functions *)

fun f/2.
fun g/1.
equation f(x,g(y)) = f(y,g(x)).

(* Test whether s is secret *)

query attacker:s.

(* The process *)

let p0 = in(c, pkX);
	 new n0; 
         out(c,(sign(g(n0), skA), pkA));
	 in(c,m1); 
	 let x1 = checksign(m1, pkX) in
	 let k = f(n0,x1) in 
  	 if pkX = pkB then
	 out(c, enc(s,k)).

let p1 = in(c, (m0, pkY));
	 let x0 = checksign(m0, pkY) in
	 new n1; 
         let k = f(n1,x0) in 
         out(c,sign(g(n1), skB));
         in (c,m); 
         let s2 = dec(m,k) in 0.

process 
	new skA;
	let pkA = pk(skA) in
	out(c, pkA);
	new skB;
	let pkB = pk(skB) in
	out(c, pkB);
	((!p0) | (!p1))

(* EXPECTPV
RESULT not attacker:s[] is true.
0.016s (user 0.008s + system 0.008s), max rss 8592K
END *)
