Section: 5.3.5.7 AS Security key update
Content: The UE shall: 1> if UE is connected to E-UTRA/EPC or E-UTRA/5GC: 2> upon reception of sk-Counter as specified in TS 36.331[ Evolved Universal Terrestrial Radio Access (E-UTRA); Radio Resource Control (RRC); Protocol specification ]  [10]: 3> update the S-KgNB key based on the KeNB key and using the received sk-Counter value, as specified in TS 33.401[ 3GPP System Architecture Evolution (SAE); Security architecture ]  [30] for EN-DC, or TS 33.501[ Security architecture and procedures for 5G System ]  [11] for NGEN-DC; 3> derive the KRRCenc and KUPenc keys as specified in TS 33.401[ 3GPP System Architecture Evolution (SAE); Security architecture ]  [30] for EN-DC, or TS 33.501[ Security architecture and procedures for 5G System ]  [11] for NGEN-DC; 3> derive the KRRCint and KUPint keys as specified in TS 33.401[ 3GPP System Architecture Evolution (SAE); Security architecture ]  [30] for EN-DC or TS 33.501[ Security architecture and procedures for 5G System ]  [11] for NGEN-DC. 1> else if this procedure was initiated due to reception of the masterKeyUpdate: 2> if the nas-Container is included in the received masterKeyUpdate: 3> forward the nas-Container to the upper layers; 2> if the keySetChangeIndicator is set to true: 3> derive or update the KgNB key based on the KAMF key, as specified in TS 33.501[ Security architecture and procedures for 5G System ]  [11]; 2> else: 3> derive or update the KgNB key based on the current KgNB key or the NH, using the nextHopChainingCount value indicated in the received masterKeyUpdate, as specified in TS 33.501[ Security architecture and procedures for 5G System ]  [11]; 2> store the nextHopChainingCount value; 2> derive the keys associated with the KgNB key as follows: 3> if the securityAlgorithmConfig is included in SecurityConfig: 4> derive the KRRCenc and KUPenc keys associated with the cipheringAlgorithm indicated in the securityAlgorithmConfig, as specified in TS 33.501[ Security architecture and procedures for 5G System ]  [11]; 4> derive the KRRCint and KUPint keys associated with the integrityProtAlgorithm indicated in the securityAlgorithmConfig, as specified in TS 33.501[ Security architecture and procedures for 5G System ]  [11]; 3> else: 4> derive the KRRCenc and KUPenc keys associated with the current cipheringAlgorithm, as specified in TS 33.501[ Security architecture and procedures for 5G System ]  [11]; 4> derive the KRRCint and KUPint keys associated with the current integrityProtAlgorithm, as specified in TS 33.501[ Security architecture and procedures for 5G System ]  [11]. NOTE 1: Ciphering and integrity protection are optional to configure for the DRBs. 1> else if this procedure was initiated due to reception of the sk-Counter (UE is in NE-DC, or NR-DC, or is configured with SN terminated bearer(s)) or if the procedure was initiated due to selection of an sk-Counter for conditional reconfiguration execution for subsequent CPAC (UE is in NR-DC): 2> derive or update the secondary key (S-KgNB or S-KeNB) based on the KgNB key and using the received or selected sk-Counter value, as specified in TS 33.501[ Security architecture and procedures for 5G System ]  [11]; 2> derive the KRRCenc key and the KUPenc key as specified in TS 33.501[ Security architecture and procedures for 5G System ]  [11] using the ciphering algorithms indicated in the RadioBearerConfig associated with the secondary key (S-KgNB or S-KeNB) as indicated by keyToUse; 2> derive the KRRCint key and the KUPint key as specified in TS 33.501[ Security architecture and procedures for 5G System ]  [11] using the integrity protection algorithms indicated in the RadioBearerConfig associated with the secondary key (S-KgNB or S-KeNB) as indicated by keyToUse; NOTE 2: If the UE has no radio bearer configured with keyToUse set to secondary and receives the sk-Counter without any RadioBearerConfig with keyToUse set to secondary, the UE does not consider it as an invalid reconfiguration.