(* Diffie-Hellman without signatures 
   Only resists passive attacks 
	A -> B : e^n0
        B -> A : e^n1
          A and B compute the key as k = (e^n0)^n1 = (e^n1)^n0
        A -> B : {s}k
*)

free c.
private free s.

(* Passive adversary *)
param attacker = passive.

(* 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 = new n0; 
         (out(c,g(n0)) | in(c,x1); let k = f(n0,x1) in out(c, enc(s,k))).

let p1 = new n1; 
         (out(c,g(n1)) | in(c,x0); 
                         let k = f(n1,x0) in 
                         in (c,m); 
                         let s2 = dec(m,k) in 0).

process p0 | p1

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