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

(*

    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

*)
(* Needham Shroeder public key protocol.
   Original version, with a flaw discovered by Lowe *)

pred c/1 elimVar,decompData.
nounif c:x.

fun host/1.
fun sign/2.
fun pk/1.
fun encrypt/2.

query c:secret[].

not c:sS[].
not c:sA[].

reduc

(* The attacker *)

c:x & c:y -> c:sign(x,y);
c:sign(x,y) -> c:x;
c:x & c:encrypt(m,pk(x)) -> c:m;
c:x -> c:pk(x);
c:x & c:y -> c:encrypt(x,y);
c:host(x);

(* The protocol *)
(* Initialisation *)

c:pk(sA[]);
c:pk(sS[]);

(* A *)

c:sign((pkx, host(x)), sS[]) -> c:encrypt((Na[pkx], host(sA[])), pkx);
c:sign((pkx, host(x)), sS[]) & c:encrypt((Na[pkx], y, host(x)), pk(sA[]))
   -> c:encrypt((y,k[x]), pkx);

(* B *)

c:encrypt((x,host(a)), pk(sA[])) & c:sign((pka, host(a)), sS[]) -> c:encrypt((x, Nb[x,a], host(sA[])), pka);
c:encrypt((x,host(sA[])), pk(sA[])) & c:sign((pka, host(sA[])), sS[]) & c:encrypt((Nb[x, sA[]], z), pk(sA[]))
   -> c:encrypt(secret[], pk(z));

(* server *)

c:(host(s1),host(s2)) -> c:sign((pk(s2), host(s2)), sS[]).
