Section: 5.4.1.3.3 Authentication response by the UE
Content: The UE shall respond to an AUTHENTICATION REQUEST message. With the exception of the cases described in subclause 5.4.1.3.6 and 5.4.1.3.7 case l, the UE shall process the 5G authentication challenge data and respond with an AUTHENTICATION RESPONSE message to the network. Upon a successful 5G authentication challenge, the UE shall determine the PLMN identity to be used for the calculation of the new KAMF from the 5G authentication challenge data according to the following rules: a) When the UE moves from 5GMM-IDLE mode to 5GMM-CONNECTED mode, until the first handover, the UE shall use the PLMN identity of the selected PLMN; and b) After handover or inter-system change to N1 mode in 5GMM-CONNECTED mode, 1) if the target cell is not a shared network cell, the UE shall use the PLMN identity received as part of the broadcast system information; 2) if the target cell is a shared network cell and the UE has a valid 5G-GUTI, the UE shall use the PLMN identity that is part of the 5G-GUTI; and 3) if the target cell is a shared network cell and the UE has a valid 4G-GUTI, but not a valid 5G-GUTI, the UE shall use the PLMN identity that is part of the 4G-GUTI. Upon a successful 5G authentication challenge, the new KAMF calculated from the 5G authentication challenge data shall be stored in a new 5G NAS security context in the volatile memory of the ME. The USIM will compute the authentication response (RES) using the 5G authentication challenge data received from the ME, and pass RES to the ME. From the RES, RES* is then generated according to Annex A of 3GPP TS 33.501[ Security architecture and procedures for 5G System ]  [24]. In order to avoid a synchronisation failure, when the UE receives an AUTHENTICATION REQUEST message, the UE shall store the received RAND together with the RES*, in the volatile memory of the ME. When the UE receives a subsequent AUTHENTICATION REQUEST message, if the stored RAND value is equal to the new received value in the AUTHENTICATION REQUEST message, then the ME shall not pass the RAND to the USIM, but shall send the AUTHENTICATION RESPONSE message with the stored RES*. If there is no valid stored RAND in the ME or the stored RAND is different from the new received value in the AUTHENTICATION REQUEST message, the ME shall pass the RAND to the USIM, shall override any previously stored RAND and RES* with the new ones and start, or reset and restart timer T3516. The RAND and RES* values stored in the ME shall be deleted and timer T3516, if running, shall be stopped: a) upon receipt of a 1) SECURITY MODE COMMAND message, 2) SERVICE REJECT message, 3) REGISTRATION REJECT message, 4) REGISTRATION ACCEPT message, 5) AUTHENTICATION REJECT message, or 6) SERVICE ACCEPT message; b) upon expiry of timer T3516; c) if the UE enters the 5GMM state 5GMM-DEREGISTERED or 5GMM-NULL; or d) if the UE enters 5GMM-IDLE mode.