# Hwang modified Neumann Stubblebine
#
# Modelled after the description in the SPORE library
# http://www.lsv.ens-cachan.fr/spore/neumannStubblebineHwang.html
#
# Note:
# According to SPORE there are no attacks on this protocol, scyther
# finds one however. This has to be investigated further.


usertype Server, SessionKey, TimeStamp, TicketKey;
usertype ExpiredTimeStamp;
secret k: Function;

const a, b, e: Agent;
const s: Server;
const Fresh: Function;
const Compromised: Function;

const ne: Nonce;
const kee: SessionKey;
untrusted e;
compromised k(e,s);

protocol neustub-Hwang^KeyCompromise(C)
{
    // Read the names of 3 agents and disclose a session between them including
    // corresponding session key to simulate key compromise
    role C {
        const Ni,Nr,Mi,Mr: Nonce;
        const Kir: SessionKey;
        const Tr: ExpiredTimeStamp;
        var I,R,S: Agent;

        read_C1(C,C,    I,R,S);
        send_C2(C,C,    I,Ni,
                        R,{I,Ni,Tr,Nr}k(R,S),
                        {R,Ni,Kir,Tr}k(I,S),
                        {I,Kir,Tr}k(R,S), Nr,
                        {Nr}Kir,
                        Mi,{I,Kir,Tr}k(R,S),
                        Mr,{Mi}Kir,
                        {Mr}Kir,
                        Kir
               );
        claim_C3(C,Empty, (Compromised,Kir));
    }
}

protocol neustub-Hwang(I,R,S)
{
    role I
    {
        const Ni,Mi: Nonce;
        var Nr,Mr: Nonce;
        var T: Ticket;
        var Tb: TimeStamp;
        var Kir: SessionKey;
        
        send_1(I,R, I, Ni);
        read_!3(S,I, { R,Ni,Kir,Tb}k(I,S), T, Nr);
        send_4(I,R,T,{Nr}Kir);
        send_5(I,R,Mi,T);
        read_6(R,I,Mr,{Mi}Kir);
        send_7(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;
        const Nr,Mr: Nonce;
        var Kir: SessionKey;
        const Tb: TimeStamp;
        var T: Ticket;
        
        read_1(I,R, I, Ni);
        send_!2(R,S, R, {I, Ni, Tb, Nr}k(R,S));
        read_4(I,R,{I,Kir,Tb}k(R,S),{Nr}Kir);
        read_5(I,R,Mi,T);
        send_6(R,I,Mr,{Mi}Kir);
        read_7(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;
        const Kir: SessionKey;
        var Tb: TimeStamp;

        read_!2(R,S, R, {I,Ni,Tb,Nr}k(R,S));
        send_!3(S,I, { R, Ni, Kir, Tb}k(I,S), { I,Kir,Tb}k(R,S),Nr );
    }
}

