ifdef(`default',`
(* EXPECTPV FILENAME: examplesnd/attackspeed/piwoolampk-orig.m4.pi TAG: 1
RESULT ev:endBparam(x) ==> ev:beginBparam(x) is false.
RESULT ev:endBfull(x,y,z) ==> ev:beginBfull(x,y,z) is false.
RESULT evinj:endBparam(x) ==> evinj:beginBparam(x) is false.
RESULT (even ev:endBparam(x) ==> ev:beginBparam(x) is false.)
RESULT evinj:endBfull(x,y,z) ==> evinj:beginBfull(x,y,z) is false.
RESULT (even ev:endBfull(x,y,z) ==> ev:beginBfull(x,y,z) is false.)
0.044s (user 0.020s + system 0.024s), max rss 8724K
END *)
')
ifdef(`notrace',`
param reconstructTrace = no.
(* EXPECTPV FILENAME: examplesnd/attackspeed/piwoolampk-orig.m4.pi TAG: 2
RESULT ev:endBparam(x) ==> ev:beginBparam(x) cannot be proved.
RESULT ev:endBfull(x,y,z) ==> ev:beginBfull(x,y,z) cannot be proved.
RESULT evinj:endBparam(x) ==> evinj:beginBparam(x) cannot be proved.
RESULT (even ev:endBparam(x) ==> ev:beginBparam(x) cannot be proved.)
RESULT evinj:endBfull(x,y,z) ==> evinj:beginBfull(x,y,z) cannot be proved.
RESULT (even ev:endBfull(x,y,z) ==> ev:beginBfull(x,y,z) cannot be proved.)
0.036s (user 0.020s + system 0.016s), max rss 8600K
END *)
')
ifdef(`nounif',`
param unifyDerivation = false.
(* EXPECTPV FILENAME: examplesnd/attackspeed/piwoolampk-orig.m4.pi TAG: 3
RESULT ev:endBparam(x) ==> ev:beginBparam(x) is false.
RESULT ev:endBfull(x,y,z) ==> ev:beginBfull(x,y,z) is false.
RESULT evinj:endBparam(x) ==> evinj:beginBparam(x) is false.
RESULT (even ev:endBparam(x) ==> ev:beginBparam(x) is false.)
RESULT evinj:endBfull(x,y,z) ==> evinj:beginBfull(x,y,z) is false.
RESULT (even ev:endBfull(x,y,z) ==> ev:beginBfull(x,y,z) is false.)
0.048s (user 0.024s + system 0.024s), max rss 8744K
END *)
')
ifdef(`noback',`
param traceBacktracking = false.
(* EXPECTPV FILENAME: examplesnd/attackspeed/piwoolampk-orig.m4.pi TAG: 4
RESULT ev:endBparam(x) ==> ev:beginBparam(x) is false.
RESULT ev:endBfull(x,y,z) ==> ev:beginBfull(x,y,z) is false.
RESULT evinj:endBparam(x) ==> evinj:beginBparam(x) is false.
RESULT (even ev:endBparam(x) ==> ev:beginBparam(x) is false.)
RESULT evinj:endBfull(x,y,z) ==> evinj:beginBfull(x,y,z) is false.
RESULT (even ev:endBfull(x,y,z) ==> ev:beginBfull(x,y,z) is false.)
0.048s (user 0.036s + system 0.012s), max rss 8740K
END *)
')
free c.
(*

Woo and Lam public-key auth protocol (1992, computer)

A -> B: A
B -> A: N
A -> B: { N }_skA
B -> S: A
S -> B: A, { A, pkA }_skS

Terminates with attack

Full agreement is true, but there is an attack !
(Indeed, the messages never mention B.)

If we include B as a pseudo first message sent to A, then full agreement
is false.
*)

(* Signatures *)

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

(* Host name / key
   The server has a table (host name, public key), which we
   represent by the function getkey. *)

fun host/1.
private reduc getkey(host(x)) = x.

(* Secrecy assumptions *)

not skA.
not skB.
not skS.

query ev:endBparam(x) ==> ev:beginBparam(x).
query ev:endBfull(x,y,z) ==> ev:beginBfull(x,y,z).
query evinj:endBparam(x) ==> evinj:beginBparam(x).
query evinj:endBfull(x,y,z) ==> evinj:beginBfull(x,y,z).

let processA = in(c, hostB0); (* Choose B *)
               event beginBparam(hostB0);
               out(c, hostA);
               in(c,n);
	       event beginBfull(hostB0, hostA, n);
	       out(c,sign(n,skA)).

let processB = in(c, hostA0);
               new n; out(c,n);
               in(c,m); 
               out(c, hostA0);
               in(c, (=hostA0, m4)); 
                  let (=hostA0, pkA2) = checksign(m4, pkS) in
                     if n = checksign(m,pkA2) then
			(* OK *)
                        if hostA0 = hostA then
			  event endBparam(hostB);
			  event endBfull(hostB, hostA0, n).

let processS = in(c, hostA);
	       out(c, (hostA, sign((hostA, getkey(hostA)), skS))).

process new skA; new skB; new skS;
        let pkA = pk(skA) in
        let pkB = pk(skB) in
        let pkS = pk(skS) in
	let hostA = host(pkA) in
	let hostB = host(pkB) in
	out(c, pkA); out(c, pkB); out(c, pkS);
	out(c, hostA); out(c, hostB);
	((!processA) | (!processB) | (!processS))
