(* 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: channel.

type G.
type exponent.

(* Passive adversary *)
set attacker = passive.

(* Shared key encryption *)

fun enc(bitstring, G): bitstring.
reduc forall x: bitstring, y: G; dec(enc(x,y),y) = x.

(* Diffie-Hellman *)

const g: G.
fun exp(G, exponent): G.
equation forall x: exponent, y: exponent; exp(exp(g, x), y) = exp(exp(g, y), x).

(* Test whether s is secret *)

free s: bitstring [private].
query attacker(s).

(* The process *)

let p0 = new n0: exponent; 
         (out(c,exp(g, n0)) | in(c,x1:G); let k = exp(x1,n0) in out(c, enc(s,k))).

let p1 = new n1: exponent; 
         (out(c,exp(g, n1)) | in(c,x0:G); 
                         let k = exp(x0,n1) in 
                         in (c,m: bitstring); 
                         let s2 = dec(m,k) in 0).

process p0 | p1

(* EXPECTPV
RESULT not attacker(s[]) is true.
0.012s (user 0.012s + system 0.000s), max rss 8516K
END *)
