Security — NAS/AS Security (Key Hierarchy, SMC, NEA/NIA)¶
Learning objectives¶
After reading this page, you will be able to do the following.
- Explain Why (that authentication alone cannot protect the content of communication) as a countermeasure against eavesdropping and tampering.
- Explain the derivation tree from KSEAF onward in the key hierarchy (KSEAF→KAMF→{KNASenc/KNASint, KgNB}→{KRRCenc/KRRCint, KUPenc/KUPint}). State what each key protects.
- Follow the NAS Security Mode Command / Complete procedure and explain from which message ciphering and integrity protection become active.
- Follow the AS Security Mode Command / Complete procedure and explain the flow by which the KgNB-derived RRC/UP protection becomes active.
- Explain the meaning of NEA/NIA (NEA0/1/2/3 · NIA0/1/2/3 = NULL/SNOW 3G/AES/ZUC) and the mechanism by which they are selected.
- Understand security contexts (Native / Mapped, ngKSI, ABBA) and the ordering that NAS SMC comes first and AS SMC comes after.
- Organize what integrity protection and ciphering apply to (NAS/RRC/UP, and the Rel-16 enhancement of User Plane integrity protection).
Prerequisites¶
It will go more smoothly if you understand the following first. If you haven't yet, start from the Curriculum.
- Up to how KSEAF is established in primary authentication → Authentication chapter (this chapter is its continuation, dealing with what comes "next" after KSEAF is established)
- The big picture of Registration (establishing security was outlined as part of the registration procedure) → Initial Registration
- NAS / N1 (the layer that carries control messages between UE and AMF) → N1
- The roles of the NFs that terminate security → AMF (co-located with SEAF) / AUSF / UDM
What you'll learn in this chapter¶
This chapter narrows its focus to what happens "next" after KSEAF is established. That is, it deals precisely with key derivation from KSEAF onward (KAMF→NAS/AS keys) and the procedure that enables NAS/AS protection (Security Mode Command).
- Primary authentication (5G-AKA / EAP-AKA') itself (up to KSEAF establishment) is not repeated. See the Authentication chapter.
- SUCI concealment (concealing the real SUPI) is also not covered in this chapter; you are directed to the Authentication chapter / Registration chapter.
- The bird's-eye view of the key hierarchy from the root through KSEAF is consolidated in AUSF's key hierarchy. To avoid duplication, this chapter puts the branches from KAMF onward in the spotlight of its diagrams.
Why — why NAS/AS security is necessary¶
We start from Why (why it is necessary). When primary authentication (Authentication chapter) finishes, you can confirm "that the counterpart is a legitimate subscriber / a legitimate network." But that alone does not protect the content of communication. After authentication, the following two threats remain.
- Eavesdropping — Because anyone can receive radio waves, if you do not encrypt, the content of control messages and user data can be read.
- Tampering — If the content is rewritten in transit and you cannot detect it, you will act exactly as the attacker instructs (e.g., a spoofed command from an impersonating network).
So, based on the shared key agreed in authentication, subsequent communication is protected with ciphering (confidentiality) and integrity protection (tamper detection). Doing this across the two systems of the NAS layer (UE⇔AMF control) and the AS layer (UE⇔gNB radio control and user data) is the theme of this chapter.
Analogy: after identity verification, seal the envelope and stamp a tally seal
Primary authentication is "identity verification at the counter." But even after your identity is verified, if you carry the documents to be handed over out in the open, the content can be seen (eavesdropping) and swapped (tampering). ・Sealing the envelope = ciphering (confidentiality). Do not show the content to third parties. ・Stamping a tally seal (signature) = integrity protection (integrity). If it has been opened or swapped, you can tell. Identity verification (authentication) and sealing plus stamping the tally seal (ciphering + integrity protection) are separate tasks, and only with both in place can you safely carry the documents (communication).
Overview¶
KSEAF is the anchor key established in authentication. Starting from here, the keys branch into two systems: NAS protection (terminated by the AMF) and AS protection (terminated by the gNB).
- NAS system — KSEAF→KAMF→KNASenc / KNASint. Protects the NAS messages between UE and AMF. Enabled by NAS Security Mode Command / Complete (AMF-led).
- AS system — KAMF→KgNB→KRRCenc / KRRCint / KUPenc / KUPint. Protects the RRC (radio control) and UP (user data) between UE and gNB. Enabled by AS Security Mode Command / Complete (gNB-led).
Ordering is important. First NAS SMC runs first and establishes NAS protection, and only after KgNB is handed to the gNB does AS SMC establish AS protection.
flowchart LR
KSEAF["KSEAF
(established in authentication)"] --> KAMF["KAMF
(derived by the AMF)"]
KAMF --> NAS["NAS protection
KNASenc / KNASint
(UE⇔AMF)"]
KAMF --> KGNB["KgNB
(→ to the gNB)"]
KGNB --> AS["AS protection
KRRCenc/KRRCint
KUPenc/KUPint
(UE⇔gNB)"]
NAS -. "NAS SMC comes first" .-> AS
For the bird's-eye view of the key hierarchy from the root through KSEAF, see AUSF's key hierarchy. This chapter drills into the branches from KAMF onward in the diagram above.
Basic Concept — a beginner-friendly explanation¶
To understand security, keep four keywords in mind.
1. The difference between ciphering (confidentiality) and integrity protection (tamper detection)¶
- Ciphering (Ciphering / Confidentiality) — Make the content unreadable to third parties. A countermeasure against eavesdropping. In 5G it is done with the NEA (NR Encryption Algorithm) algorithms.
- Integrity protection — Attach a short verification code called MAC-I (Message Authentication Code for Integrity) to the message and detect tampering. It does not hide the content, but it guarantees "that it has not been rewritten." In 5G it is done with NIA (NR Integrity Algorithm).
The two are independent, separate mechanisms
Ciphering and integrity protection are done with separate keys and separate algorithms (e.g., for NAS, ciphering with KNASenc + NEA, integrity with KNASint + NIA). It is not the case that "if you encrypt, tampering is also prevented." With ciphering alone, even if the content cannot be read, the possibility of bit manipulation remains, so integrity protection is used together.
2. The idea of key derivation (KDF)¶
To make a lower key from a higher key, you use a KDF (Key Derivation Function). When you put a "parent key" and an "input parameter representing the purpose" into the KDF, a "child key" comes out. Because different inputs yield a different child key even from the same parent, you can safely mass-produce independent keys per purpose (the basics of KDF are in TS 33.220, and the application in 5G is in TS 33.501 Annex A; the details of individual input parameters are to be confirmed).
3. Why split keys per layer¶
The reason for splitting keys for NAS, RRC, and UP use is containment of damage (key separation). Even if the key of one layer leaks, the keys of the other layers cannot be back-calculated thanks to the one-way property of the KDF, so the damage can be contained. Also, because NAS is terminated by the AMF and AS by the gNB, by handing the gNB only KgNB and below, and not KAMF or the NAS keys, the scope of compromise of the radio-side node is limited.
4. ngKSI and the security context¶
- Security context (5G NAS security context) — The bundle of the established set of keys (KAMF, selected algorithms, counters, etc.).
- ngKSI (Key Set Identifier in 5G) — A short number that identifies that security context. Used so the UE and the network can agree on "which key set they are talking with." It is assigned at authentication and referenced in subsequent messages.
Architecture¶
Here is the key derivation tree starting from KSEAF. The root side (K through KSEAF) is consolidated in AUSF's key hierarchy, and this diagram concentrates on the branches from KAMF onward.
flowchart TB
KSEAF["KSEAF
(established in authentication, anchor key)"]
KAMF["KAMF
(derived by SEAF/AMF)"]
KNASenc["KNASenc
NAS ciphering"]
KNASint["KNASint
NAS integrity"]
KgNB["KgNB
(conveyed AMF→gNB)"]
KRRCenc["KRRCenc
RRC ciphering"]
KRRCint["KRRCint
RRC integrity"]
KUPenc["KUPenc
UP ciphering"]
KUPint["KUPint
UP integrity (introduced in Rel-15 / relaxed in Rel-16)"]
KSEAF --> KAMF
KAMF --> KNASenc
KAMF --> KNASint
KAMF --> KgNB
KgNB --> KRRCenc
KgNB --> KRRCint
KgNB --> KUPenc
KgNB --> KUPint
What each key "protects, and where":
- KAMF — Derived by SEAF/AMF from KSEAF. The parent of the NAS keys and KgNB. Held by the AMF and not handed to the gNB.
- KNASenc / KNASint — Ciphering / integrity protection of the NAS messages between UE and AMF. Terminated by the AMF.
- KgNB — Derived from KAMF and conveyed from the AMF to the gNB over N2 (NGAP) (N2). The parent of the AS keys.
- KRRCenc / KRRCint — Ciphering / integrity protection of the RRC (radio control) between UE and gNB. Terminated by the gNB.
- KUPenc / KUPint — Ciphering / integrity protection of the UP (User Plane / user data) between UE and gNB. UP integrity protection (KUPint) was introduced in Rel-15 with constraints on its application, but Rel-16 relaxed the constraints and advanced full data rate support (see Release differences below).
The details of derivation input parameters are to be confirmed
The KDF inputs of each key (algorithm type distinguisher, algorithm identity, etc.) are specified in TS 33.501 Annex A, but this chapter does not assert down to the concrete bit assignments of each parameter (to be confirmed). Here we concentrate on the structure of "which child derives from which parent, and what it protects."
Network Function (the elements involved)¶
The elements involved in this procedure, and how they act in this chapter.
| Element | Role in this procedure | Keys held/obtained | Action in this procedure | Impact on failure |
|---|---|---|---|---|
| UE | The counterpart for both NAS/AS. Derives the same keys as the network and verifies/applies SMC | KSEAF, KAMF, KNAS, KgNB, KRRC, KUP* | Receive/verify NAS/AS SMC and reply with Complete | Cannot enable protection → registration/communication impossible |
| AMF(SEAF) | Termination of NAS security. Derives KAMF/NAS keys, selects algorithms, and leads the NAS SMC | KSEAF, KAMF, KNASenc, KNASint, KgNB(derives→to gNB) | Send NAS SMC, derive KgNB and convey it over N2 | NAS protection is not established, so subsequent registration does not proceed |
| gNB | Termination of AS security. Derives RRC/UP keys from KgNB and leads the AS SMC | KgNB, KRRCenc, KRRCint, KUPenc, KUPint | Send AS SMC, enable RRC/UP protection | AS protection is not established, so the radio segment is not protected |
| AUSF / UDM | The source/reference of keys (do not act directly in this procedure, but are the preceding stage of KSEAF establishment) | KAUSF/KSEAF(source), K/OPc(UDM) | In principle do not appear in this procedure (completed in the authentication stage) | (Failures in the authentication stage propagate here) |
AUSF/UDM are the 'preceding stage' in this procedure
AUSF/UDM are the leads in the authentication stage that establishes KSEAF (Authentication chapter). In this chapter's SMC procedure, they in principle do not appear directly in signaling, and the focus is on the key derivation below KSEAF and the enabling of protection.
Interface / Protocol¶
The interfaces and protocols used in this procedure.
| Interface | Protocol | Use in this procedure | Scope |
|---|---|---|---|
| N1 | NAS (5GMM) | NAS Security Mode Command / Complete (UE⇔AMF) | The center of this chapter |
| N2 | NGAP | Conveying KgNB, triggering AS SMC (delivering security information to the gNB via Initial Context Setup, etc.) | The center of this chapter |
| Uu / RRC | RRC (protection enforced in PDCP) | AS Security Mode Command / Complete (gNB⇔UE, radio segment) | RAN side (radio) = outline |
RRC / AS SMC is on the RAN (radio) side
AS SMC is an RRC message between gNB and UE, and does not appear in the core network (N1/N2) (it completes within the gNB). Because the radio side (RRC/PDCP) is close to being outside the scope of the core network that is the main subject of this site, this chapter deals with the positioning of the procedure and the flow of keys, and keeps the details of RRC (TS 38.331 / TS 38.323) to an outline. For protocol details, see the Protocol Dictionary.
Procedure — Call Flow¶
This is the heart of this page. Enabling protection proceeds in the order (A) NAS SMC first, (B) AS SMC after. The premise is that KSEAF is already established (Authentication chapter).
Premise: KSEAF establishment and KAMF derivation
When primary authentication succeeds, the SEAF(AMF) receives KSEAF and derives KAMF from it (TS 33.501 §6.2). This procedure starts immediately after that, from making the NAS keys from KAMF and enabling protection with the NAS SMC.
(A) NAS Security Mode Command / Complete¶
The AMF leads, and with the selected NAS algorithms (NEA/NIA) enables NAS integrity protection first, followed by ciphering. Basis: TS 33.501 §6.7.2 / TS 24.501 (the NAS SMC messages).
sequenceDiagram
autonumber
participant UE
participant AMF as AMF / SEAF
Note over UE,AMF: Authentication succeeded → AMF derives KAMF → derives KNASint/KNASenc
Note right of AMF: AMF selects NEA/NIA from the
UE security capability (TS 33.501 §6.7.2)
AMF->>UE: Security Mode Command (NAS)
(selected NEA/NIA, ngKSI, ABBA,
replayed UE security capability)
Note right of AMF: This message is 【integrity-protected only】
(MAC-I added with KNASint, no ciphering)
Note right of UE: UE derives the same KNASint/KNASenc,
verifies MAC-I and checks the resent UE sec capability matches
UE->>AMF: Security Mode Complete (NAS)
(IMEISV etc. as needed)
Note right of UE: This reply is 【integrity-protected + ciphered】
Note over UE,AMF: Subsequent NAS has ciphering + integrity protection active
Step-by-step (numbers correspond to the diagram above)¶
- AMF→UE: Security Mode Command(NAS) — The AMF sends the selected NEA/NIA, the ngKSI (which key set), the ABBA, and the replay (resend) of the UE security capability.
- This message itself is sent integrity-protected only (MAC-I added with KNASint) and is not ciphered. So the content (selected algorithms, etc.) can be read in the clear by the UE and by observers (TS 33.501 §6.7.2).
- (Inside the UE) verification — The UE also derives the same KNASint/KNASenc itself and verifies the MAC-I. It further checks whether the replayed UE security capability matches its own declared values (detection of a downgrade / bidding-down attack).
- UE→AMF: Security Mode Complete(NAS) — If verification is OK, it returns a reply. From this reply, both integrity protection and ciphering are active. Subsequent NAS messages (Registration Accept, etc.) are ciphered and their content becomes invisible.
From where ciphering becomes active
The NAS SMC itself is integrity-protected only. Ciphering starts, for UL (uplink), from Security Mode Complete, and for DL (downlink), from the message after Security Mode Command (TS 33.501 §6.7.2). This behavior is consistent with the notes in Registration's Packet Analysis.
The roles of ABBA and ngKSI
- ABBA (Anti-Bidding down Between Architectures) — A parameter that prevents an attack (bidding down) that deliberately downgrades to a weaker scheme between generations/architectures. It is tied to KAMF derivation (TS 33.501).
- ngKSI — The identifier of the security context (key set) in use. It aligns the UE's and the network's recognition of the key set.
(B) AS Security Mode Command / Complete¶
After NAS protection is established, the AMF derives KgNB and hands it to the gNB over N2. The gNB derives the RRC/UP keys from KgNB and enables radio-segment protection with the AS SMC (RRC message). Basis: TS 33.501 §6.7.4 / TS 38.331 (RRC).
sequenceDiagram
autonumber
participant UE
participant gNB
participant AMF
Note over AMF: AMF derives KgNB from KAMF
AMF->>gNB: (N2/NGAP) Convey KgNB and UE security capability
via Initial Context Setup, etc.
Note right of gNB: gNB derives
KRRCint/KRRCenc/KUPint/KUPenc from KgNB
and selects NEA/NIA for AS
gNB->>UE: AS Security Mode Command (RRC)
(selected AS algorithms, MAC-I)
Note right of gNB: Integrity protection becomes active first (RRC)
Note right of UE: UE derives the same KgNB-derived keys
and verifies MAC-I
UE->>gNB: AS Security Mode Complete (RRC)
Note over UE,gNB: Subsequent RRC/UP protection active (enforced at the PDCP layer)
Step-by-step (numbers correspond to the diagram above)¶
- AMF→gNB (N2/NGAP) — The AMF conveys KgNB and the UE security capability to the gNB in an NGAP message such as Initial Context Setup (N2).
- (Inside the gNB) key derivation and algorithm selection — The gNB derives KRRCint/KRRCenc/KUPint/KUPenc from KgNB and selects the NEA/NIA for AS.
- gNB→UE: AS Security Mode Command(RRC) — Contains the selected AS algorithms and MAC-I. Integrity protection becomes active first (TS 33.501 §6.7.4 / TS 38.331).
- UE→gNB: AS Security Mode Complete(RRC) — The UE derives the same KgNB-derived keys, verifies the MAC-I, and replies. Subsequent RRC / UP protection is active (the actual protection is enforced at the PDCP layer. TS 38.323).
Order: NAS SMC first, AS SMC after
NAS SMC (A) always runs first. Only once NAS is protected (i.e., KAMF is established and KgNB can be safely derived from it) can KgNB be handed to the gNB and AS SMC (B) be performed. This order is never reversed (TS 33.501 §6.7).
Signal Flow¶
The main messages are organized in a table. The IEs are made consistent with the Message Dictionary.
| Message | Protocol | Source→Dest | Purpose | Main IEs | Result |
|---|---|---|---|---|---|
| Security Mode Command | NAS(5GMM) | AMF→UE | Instruct NAS protection | selected NEA/NIA, ngKSI, ABBA, replayed UE security capability, MAC-I | UE verifies and finalizes NAS keys |
| Security Mode Complete | NAS(5GMM) | UE→AMF | NAS protection established | (IMEISV etc., as needed), MAC-I | Subsequent NAS ciphered + integrity-protected |
| Security Mode Reject | NAS(5GMM) | UE→AMF | Reject NAS SMC (on verification failure) | 5GMM cause | Protection not established → to re-authentication/failure handling |
| (N2) Initial Context Setup Request | NGAP | AMF→gNB | Convey KgNB and UE sec capability | Security Key(KgNB), UE Security Capabilities | gNB obtains the material for AS key derivation |
| AS Security Mode Command | RRC | gNB→UE | Instruct AS(RRC/UP) protection | selected AS ciphering/integrity algorithms, MAC-I | UE finalizes AS keys |
| AS Security Mode Complete | RRC | UE→gNB | AS protection established | MAC-I | Subsequent RRC/UP protection active |
Main IE terms: selected NEA/NIA (the selected ciphering/integrity algorithms) / ngKSI (key set identifier) / ABBA (anti-bidding-down defense) / replayed UE security capability (the resend of the UE's declared capability = for tamper detection) / MAC-I (integrity verification code). For details, see the Message Dictionary.
State Machine¶
The state transitions of security establishment as seen from the UE (basis: TS 33.501 §6.7; the classification of security contexts is in TS 33.501 §6.3 / TS 24.501 §4.4).
stateDiagram-v2
[*] --> NoSecurity: Before authentication / no protection
NoSecurity --> KSEAFEstablished: Primary authentication succeeds (Authentication chapter)
KSEAFEstablished --> NASProtected: NAS SMC Command/Complete succeeds
NASProtected --> ASProtected: AS SMC Command/Complete succeeds
NASProtected --> NoSecurity: NAS SMC Reject / MAC-I failure
ASProtected --> [*]: NAS + AS protection established (normal operation)
- NoSecurity — No protection. The first Registration Request, etc., is sent in this state (some may be sent without integrity protection = there are details to be confirmed).
- KSEAFEstablished — Authentication succeeded and established up to KSEAF/KAMF. NAS protection is still "before being enabled."
- NASProtected — NAS SMC completed. NAS between UE and AMF is ciphered + integrity-protected.
- ASProtected — AS SMC completed. RRC/UP between UE and gNB is also protected. The normal operating state.
Native / Mapped security contexts
Security contexts come in Native (newly created in 5G authentication) and Mapped (created by mapping from an old context at handover from EPS, etc.). There is also a "full/partial" distinction. The main focus of this chapter is the establishment of a Native 5G NAS security context (around TS 33.501 §6.3; the details of the fine classification are to be confirmed).
Packet Analysis (Wireshark)¶
Because the NAS SMC is a NAS message, capture it with nas-5gs. The point that NAS is carried nested inside NGAP(N2) is the same as in Registration's Packet Analysis.
Main display filters¶
| Filter | Meaning |
|---|---|
nas-5gs |
5GS NAS messages in general (including Security Mode Command/Complete) |
ngap |
NGAP (the envelope that carries NAS / N2) |
nas-5gs.mm.message_type |
Identify by NAS 5GMM message type (Security Mode Command/Complete/Reject); the concrete value is to be confirmed |
The hex value of message type is to be confirmed
The concrete value of nas-5gs.mm.message_type for Security Mode Command/Complete, etc., is based on the 3GPP assignment (around TS 24.501 §9.7), but the display may differ by Wireshark version / dissector implementation. Treat the numeric value as to be confirmed, and on real equipment it is most reliable to check the protocol hierarchy display in the GUI.
Points to look at when decoding¶
- Security Mode Command can be read in the clear — Because it is sent integrity-protected only (no ciphering), you can confirm selected NEA/NIA, ngKSI, ABBA, and replayed UE security capability in the clear.
- After ciphering, the NAS payload becomes invisible — From Security Mode Complete onward (for DL, from the message after SMC), NAS is ciphered and appears in Wireshark as a Security protected NAS message, and the inner 5GMM message cannot be seen without the decryption key.
- MAC — Integrity-protected NAS carries a MAC (Message Authentication Code) field.
AS SMC is not visible in ngap (it is inside the RAN)
AS Security Mode Command/Complete are RRC messages between gNB and UE, and do not appear in an N2(NGAP) capture (they are not visible with the ngap filter). RRC flows over the radio segment (Uu) and terminates within the gNB, so to observe AS SMC you need a capture on the RAN side (Uu/RRC). Only the conveyance of KgNB (inside Initial Context Setup) appears on N2.
Configuration¶
The structure-level essentials of the configuration that makes protection work. Concrete values and vendor-specific ones (Cisco, etc.) are implementation-dependent, and no fictitious values are written here.
AMF side (NAS security) — e.g., Open5GS / free5GC¶
- Supported NEA / NIA and priority — Enumerate the ciphering algorithms (NEA0/1/2/3) and integrity algorithms (NIA0/1/2/3) the AMF supports, and set their priority. Selection is made by matching against the UE's security capability.
- Whether the NULL algorithms (NEA0 / NIA0) are allowed — Whether to allow NEA0 (no ciphering) or NIA0 (no integrity) is a policy. In operational networks, NIA0 is in principle not allowed, and it is permitted only for unauthenticated emergency calls (TS 33.501).
gNB side (AS security)¶
- Supported AS algorithms and priority — Enumeration and priority of the ciphering/integrity algorithms for RRC/UP.
- Enabling User Plane integrity protection (UP IP) — Whether to request/enable UP integrity protection (introduced in Rel-15, application range expanded in Rel-16; the application conditions are to be confirmed).
Concrete values and vendor-specific ones are implementation-dependent
Configuration key names, hierarchy, mandatory items, and the format of algorithm priority differ across Open5GS / free5GC / commercial vendors. The above are structure-level essentials; check the actual values in the documentation of each implementation (implementation-dependent).
Trouble Shooting¶
Isolating typical security-establishment failures. For details of Cause values, see the Cause Dictionary.
| Symptom | Likely cause | Check points | Related logs/packets | Direction of remedy |
|---|---|---|---|---|
| (a) NAS SMC failure (Security Mode Reject) | Algorithm mismatch, inconsistency in the UE security capability | The AMF's supported NEA/NIA vs. the UE's declared capability, and whether the replayed value matches | Security Mode Reject(NAS), AMF logs | Review both sides' supported algorithms/priorities and confirm capability consistency |
| (b) Integrity check failure (MAC-I mismatch) | Key/counter mismatch, tampering, implementation bug | Match of KNASint/derived keys, COUNT/ngKSI consistency | Message discard (dropped on the receiving side), AMF/UE logs | Confirm consistency of key derivation parameters and ngKSI. Discard is the defensive behavior per spec |
| (c) Security context inconsistency (ngKSI mismatch) | The key set referenced by the UE and the network is misaligned | Match of ngKSI, and the Native/Mapped distinction | Re-authentication logs | Align ngKSI. If unresolved, rebuild the context via re-authentication |
| (d) AS SMC failure | KgNB derivation inconsistency, RRC algorithm mismatch, faulty KgNB conveyance over N2 | KgNB conveyance to the gNB (Initial Context Setup), AS supported algorithms | AS SMC failure (RRC), gNB/AMF logs | Confirm KgNB conveyance and AS supported algorithms. Also confirm whether NAS SMC has been established first |
A MAC-I mismatch resulting in 'discard' is the correct behavior
A message that fails the integrity check is discarded on the receiving side. This is not an anomaly; it is the correct result of the tamper-detection defense working. If it happens frequently, suspect an inconsistency in key derivation parameters, COUNT, or ngKSI, or an implementation bug.
Comparison with EPC¶
Contrasting 4G(EPC) security with 5G.
| Aspect | 4G / EPC | 5G / 5GC |
|---|---|---|
| Anchor key | KASME | KSEAF (→KAMF→…) |
| NAS keys | KNASenc / KNASint (derived from KASME) | KNASenc / KNASint (derived from KAMF) |
| Radio-side parent key | KeNB | KgNB (derived from KAMF) |
| RRC keys | KRRCenc / KRRCint | KRRCenc / KRRCint |
| UP keys | KUPenc (ciphering only, basically) | KUPenc + KUPint (UP integrity protection introduced in Rel-15, application range expanded in Rel-16) |
| Ciphering algorithms | EEA (EEA0/1/2/3) | NEA (NEA0/1/2/3) |
| Integrity algorithms | EIA (EIA0/1/2/3) | NIA (NIA0/1/2/3) |
| Anti-downgrade defense | — | Introduced the ABBA parameter |
The algorithms are largely common inside; the names changed
EEA/EIA and NEA/NIA have largely common number correspondence and underlying algorithms (NULL/SNOW 3G/AES/ZUC) (e.g., xEA1=SNOW 3G, xEA2=AES, xEA3=ZUC, xEA0=NULL). In 5G, the main evolutions are that the parent of the keys is replaced from KASME with KSEAF/KAMF, and that the positioning of UP integrity protection (KUPint) is strengthened. For the exact correspondence of numbers and algorithms, see TS 33.501 §5.11.
Release differences¶
Uncertain items are marked to be confirmed and are not asserted.
- Rel-15 — The basis of 5G security. KSEAF/KAMF, the NAS/AS key hierarchy, NAS/AS SMC, NEA/NIA(0/1/2/3), ngKSI, and ABBA are established (the basis of TS 33.501).
- Rel-16 — The main topic is the extension of User Plane integrity protection (UP IP). In Rel-15 there were constraints on applying UP integrity protection, but Rel-16 strengthened the application range/performance aspects (the concrete mandatory conditions and application range are to be confirmed).
- Rel-17 / Rel-18 (5G-Advanced) — Extensions of security features continue (the concrete differences to this chapter's procedure are to be confirmed).
The mandatory conditions of UP integrity protection are to be confirmed
When UP integrity protection (KUPint) is "mandatory" depends on the UE/gNB capabilities, data rate, operator policy, and Release. It is not "always mandatory" but conditional, and the exact application conditions (especially the handling at high data rates) are to be confirmed in the applicable edition of TS 33.501. This chapter avoids asserting.
3GPP Specification¶
| Spec | Section | Content |
|---|---|---|
| TS 33.501 | §5.11 | Security algorithms (NEA / NIA, NULL/SNOW 3G/AES/ZUC) |
| TS 33.501 | §6.2 | Key hierarchy and KDF |
| TS 33.501 | §6.3 | Security contexts (Native / Mapped, etc.; the section number is to be confirmed) |
| TS 33.501 | §6.7.2 | NAS Security Mode Command procedure |
| TS 33.501 | §6.7.4 | AS Security Mode Command procedure |
| TS 33.501 | Annex A | Input parameters of the key derivation function (KDF) (details to be confirmed) |
| TS 24.501 | §5.4.2 | The NAS-side Security Mode Control procedure (SMC messages; the section number is to be confirmed) |
| TS 38.331 | (various RRC sections) | RRC (AS Security Mode Command, etc.) |
| TS 38.323 | — | PDCP (the layer that enforces ciphering and integrity protection) |
| TS 33.220 | — | The basics of GBA/KDF (the prototype of the key derivation function) |
Handling of section numbers
TS 33.501 §5.11 / §6.2 / §6.7.2 / §6.7.4 are referenced as the backbone of this chapter. §6.3 (security contexts), TS 24.501 §5.4.2, the KDF input parameters in Annex A, and the individual section numbers of TS 38.331/38.323 may differ by edition, and some are marked to be confirmed.
FAQ¶
Q1. What is the difference between ciphering and integrity protection?
Ciphering (confidentiality) makes the content unreadable to third parties (a countermeasure against eavesdropping, done with NEA). Integrity protection attaches a MAC-I to detect tampering (a countermeasure against tampering, done with NIA). Ciphering, which hides the content, and integrity protection, which sees through rewrites, are separate mechanisms, and both are used together. Ciphering alone cannot detect tampering.
Q2. What are the order and difference between NAS SMC and AS SMC?
NAS SMC comes first, AS SMC comes after. NAS SMC is AMF-led and protects the NAS between UE and AMF (KNASenc/KNASint). AS SMC is gNB-led and protects the RRC/UP between UE and gNB (KRRC/KUP). After NAS is established and KgNB can be safely derived from KAMF, KgNB is handed to the gNB and AS SMC is performed (TS 33.501 §6.7).
Q3. What are NEA0 / NIA0? May they be used?
NEA0 = NULL ciphering (no ciphering), NIA0 = NULL integrity (no integrity protection). In operational networks, the NULL that disables protection is in principle not used. In particular, NIA0 (no integrity) makes tamper detection impossible, so it is permitted only for unauthenticated emergency calls (TS 33.501).
Q4. When is User Plane integrity protection mandatory?
It is not uniformly "always mandatory." UP integrity protection (KUPint) was introduced in Rel-15 and its application range was expanded in Rel-16, but its application depends on the UE/gNB capabilities, data rate, operator policy, and Release. The exact mandatory conditions (especially the handling at high data rates) are to be confirmed in the applicable edition of TS 33.501.
Q5. What is ngKSI?
ngKSI (Key Set Identifier in 5G) is a short number that identifies the security context (key set) in use. It is used so the UE and the network agree on "which key they are talking with." It is assigned at authentication and referenced in the SMC, etc. If the ngKSI is misaligned, a key set inconsistency arises, and the context may be rebuilt via re-authentication (Trouble Shooting (c)).
Summary¶
- Authentication (identity verification) alone cannot protect the content of communication. The theme of this chapter is protecting NAS/AS with ciphering (confidentiality) + integrity protection (tamper detection).
- Starting from KSEAF, keys derive as KAMF→{KNASenc/KNASint, KgNB}→{KRRCenc/KRRCint, KUPenc/KUPint}. Keys are split per layer to contain damage.
- Protection is enabled in the order NAS SMC (AMF-led, first) → AS SMC (gNB-led, after). The NAS SMC is sent integrity-protected only, and ciphering begins from Complete onward (from the next message for DL).
- The algorithms are NEA (ciphering) / NIA (integrity) in 0/1/2/3 (NULL/SNOW 3G/AES/ZUC). Selection is decided by the UE security capability and the network's priority.
- ngKSI identifies the security context. Contexts come in Native / Mapped. ABBA prevents downgrade attacks.
- For the key hierarchy from the root through KSEAF, see AUSF's key hierarchy; for primary authentication, see the Authentication chapter.
- The basis is TS 33.501 §5.11 (NEA/NIA) / §6.2 (key hierarchy) / §6.7.2 (NAS SMC) · §6.7.4 (AS SMC) / TS 24.501 / TS 38.331 / TS 38.323.
Practice — comprehension check and exercises¶
Comprehension check¶
Q1. Of ciphering and integrity protection, which handles tamper detection? (answer)
Integrity protection. It attaches a MAC-I to detect tampering. Ciphering only makes the content unreadable and does not do tamper detection.
Q2. Which of NAS SMC and AS SMC comes first? Who leads each? (answer)
NAS SMC comes first (AMF-led), AS SMC comes after (gNB-led). After NAS protection is established, KgNB is handed to the gNB and AS protection is enabled.
Q3. From which key is KgNB derived, and where is it handed? (answer)
It is derived from KAMF and conveyed from the AMF to the gNB over N2 (NGAP). From here the gNB derives KRRC/KUP.
Q4. Is the Security Mode Command itself ciphered? (answer)
No. It is sent integrity-protected only (no ciphering). So the selected algorithms, etc., can be confirmed in the clear. Ciphering becomes active from Complete onward (for DL, from the message after SMC).
Q5. What is the underlying ciphering algorithm for NEA2 / NIA2? (answer)
AES (xEA2=AES, xEA1=SNOW 3G, xEA3=ZUC, xEA0=NULL). For the exact correspondence, see TS 33.501 §5.11.
Exercises¶
Problem: Fill in the blanks [1]–[4] in the following key derivation tree, then reorder the protection-enabling steps A–D correctly.
[Key derivation tree]
KSEAF → [1] → { [2] / KNASint, [3] }
[3] → { KRRCenc / KRRCint, KUPenc / [4] }
[Order]
A. UE→gNB: AS Security Mode Complete
B. AMF→UE: NAS Security Mode Command
C. gNB→UE: AS Security Mode Command
D. UE→AMF: NAS Security Mode Complete
Answer
Key derivation tree - [1] = KAMF - [2] = KNASenc - [3] = KgNB - [4] = KUPint
Order: B → D → C → A - B: NAS SMC (AMF→UE, integrity-protected only) - D: NAS SMC Complete (UE→AMF, subsequent NAS ciphered + integrity-protected) - C: AS SMC (gNB→UE, KgNB-derived RRC/UP keys) - A: AS SMC Complete (UE→gNB, subsequent RRC/UP protection active)
※ The overall frame that NAS (B, D) comes first and AS (C, A) comes after is the most important.
Next Step¶
The next steps to deepen your understanding.
- PDU Session chapter (establishing the data-communication pipe, including Secondary Authentication)
- Related NFs: AMF (co-located with SEAF, NAS termination) / AUSF (has the key hierarchy diagram, the source of KSEAF) / UDM (the source of K/OPc)
- Preceding procedures: Authentication chapter (up to KSEAF establishment) / Initial Registration (the positioning of security establishment)
- Dictionaries: Message Dictionary / Cause Dictionary / Protocol Dictionary / NF Dictionary / Interface Dictionary