# Otway Rees
#
# Modelled after the description in the SPORE library
# http://www.lsv.ens-cachan.fr/spore/otwayRees.html
#


const Fresh: Function;
const Compromised: Function;

usertype String,SessionKey;

protocol otwayrees(I,R,S)
{
    role I
    {
        fresh Ni : Nonce;
        fresh M : String;
        var Kir : SessionKey;

        send_1(I,R, M,I,R,{Ni,M,I,R}k(I,S) );
        recv_4(R,I, M,{Ni,Kir}k(I,S) );

        claim_I1(I, Secret,Kir);
        claim_I2(I, Nisynch);
        claim_I3(I, Empty, (Fresh,Kir));
    }

    role R
    {
        var M : String;
        fresh Nr : Nonce;
        var Kir : SessionKey;
        var T1,T2: Ticket;

        recv_1(I,R, M,I,R, T1 );
        send_2(R,S, M,I,R, T1, { Nr,M,I,R }k(R,S) );
        recv_3(S,R, M, T2, { Nr,Kir }k(R,S) );
        send_4(R,I, M, T2 );

        claim_R1(R, Secret,Kir);
        claim_R2(R, Nisynch);
        claim_R3(R, Empty, (Fresh,Kir));
    }

    role S
    {
        var Ni,Nr : Nonce;
        var M : String;
        fresh Kir : SessionKey;
        
        recv_2(R,S, M,I,R, { Ni,M,I,R}k(I,S), { Nr,M,I,R }k(R,S) );
        send_3(S,R, M, { Ni,Kir }k(I,S) , { Nr,Kir }k(R,S) );
    }
}

