/*
 * From Boyd Mathuria
 *
 * To check: 3.38 or other?
 *
 */
usertype Sessionkey;
usertype Keypart;

protocol gongnonce(I,R,S)
{
	role I
	{
		fresh ni: Nonce;
		var nr: Nonce;
		fresh ki: Keypart;
		var kr: Keypart;

		send_1 (I,R, I,R,ni );
		recv_3 (S,I, { S,I,R, kr, I, ni }k(I,S), nr);
		send_4 (I,S, { I,S,I, ki, R, nr }k(I,S) );

		claim_6 (I, Secret, ki);
		claim_7 (I, Secret, kr);
		claim_8 (I, Nisynch);
		claim_9 (I, Niagree);
	}	
	
	role R
	{
		var ni: Nonce;
		fresh nr: Nonce;
		fresh kr: Keypart;
		var ki: Keypart;

		recv_1 (I,R, I,R,ni );
		send_2 (R,S, I,R, nr, { R,S,R, kr, I,ni }k(R,S));
		recv_5 (S,R, { S,R,I, ki, R, nr }k(R,S) );

		claim_10 (R, Secret, ki);
		claim_11 (R, Secret, kr);
		claim_12 (R, Nisynch);
		claim_13 (R, Niagree);
	}

	role S
	{
		var ni,nr: Nonce;
		var ki,kr: Keypart;

		recv_2 (R,S, I,R, nr, { R,S,R, kr, I,ni }k(R,S));
		send_3 (S,I, { S,I,R, kr, I, ni }k(I,S), nr);
		recv_4 (I,S, { I,S,I, ki, R, nr }k(I,S) );
		send_5 (S,R, { S,R,I, ki, R, nr }k(R,S) );
	}
}

