(*************************************************************
 *                                                           *
 *  Cryptographic protocol verifier                          *
 *                                                           *
 *  Bruno Blanchet, Vincent Cheval, and Marc Sylvestre       *
 *                                                           *
 *  Copyright (C) INRIA, CNRS 2000-2020                      *
 *                                                           *
 *************************************************************)

(*

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details (in file LICENSE).

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

*)
(* 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
