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


usertype Server, SessionKey, TimeStamp, TicketKey;
usertype ExpiredTimeStamp;

const Fresh: Function;
const Compromised: Function;

protocol ksl(I,R,S)
{
    role I
    {
        fresh Ni, Mi: Nonce;
        var Nc, Mr: Nonce;
        var T: Ticket;
        var Kir: SessionKey;
        
        send_1(I,R, Ni, I);
        recv_4(R,I, { Ni,R,Kir }k(I,S), T, Nc, {Ni}Kir );
        send_5(I,R, { Nc }Kir );
        
        send_6(I,R, Mi,T );
        recv_7(R,I, Mr,{Mi}Kir );
        send_8(I,R, {Mr}Kir );

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

    role R
    {
        var Ni,Mi: Nonce;
        fresh Nr,Nc,Mr: Nonce;
        var Kir: SessionKey;
        fresh Kbb: TicketKey;
        fresh Tr: TimeStamp;
        var T: Ticket;
        
        recv_1(I,R, Ni, I);
        send_2(R,S, Ni, I, Nr, R );
        recv_3(S,R, { Nr, I, Kir }k(R,S), T );
        send_4(R,I, T, { Tr, I, Kir }Kbb, Nc, {Ni}Kir );
        recv_5(I,R, { Nc }Kir );
        
        recv_6(I,R, Mi,{ Tr, I, Kir }Kbb );
        send_7(R,I, Mr,{Mi}Kir );
        recv_8(I,R, {Mr}Kir );

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

    role S
    {
        var Ni, Nr: Nonce;
        fresh Kir: SessionKey;

        recv_2(R,S, Ni, I, Nr, R );
        send_3(S,R, { Nr, I, Kir }k(R,S), { Ni,R,Kir }k(I,S) );
    }
}

