>
Home5G NRCross-Layer TopicsSecurity Key Hierarchy
🧠 Cross-Layer TopicsAdvanced

5G Security Key Hierarchy in 5G NR

From K in the USIM down to the AS keys — the full 5G key derivation tree.

📚 3GPP-basedTS 33.501

5G security is a tree of keys. One long-term secret you never transmit sits at the root, and every key that actually protects traffic is derived from it, level by level, by one-way functions. The deeper you go, the more specific and the more disposable the key — so compromising a leaf never exposes the root. This whole structure, from the USIM secret down to the ciphers on the air, is defined in TS 33.501.

Introduction

The 5G security key hierarchy (TS 33.501) is the layered structure of cryptographic keys that protects everything a UE and the network exchange — from the initial authentication handshake down to the ciphering and integrity of every RRC message and user-data packet on the air. It is a strict tree: a single permanent secret at the root, and a cascade of derived keys beneath it, each produced by a one-way function from its parent.

You encounter this hierarchy at every security-relevant moment in the UE lifecycle. It is built during primary authentication at registration, activated by the NAS and AS Security Mode Command procedures, exercised again at handover (fresh RAN keys per cell), reactivated from a stored context on idle-to-connected transitions, and even re-keyed on the fly to stop a PDCP counter from wrapping. Every one of those events is really a set of KDF calls somewhere in this tree.

It matters because the layering is what contains damage. A key handed to a serving network, or to one specific gNB, can be refreshed or revoked without ever touching the root secret, and a compromised gNB never sees the keys that protect the core-facing signalling. Understanding which key lives where — and what freshness input separates it from its neighbours — is the difference between reasoning about a security design and merely memorising acronyms.

Why a key hierarchy is needed

💡

In plain words: think of a hotel. The owner holds the one master key that opens everything and never leaves the safe (that is K). From it the front desk cuts a building key for the manager, who cuts a floor key for a cleaner, who is handed a single room card that expires at checkout. If a room card is stolen, you re-cut that one card — the master in the safe is untouched, and the card never reveals how to make a master. 5G keys work exactly like that: each level is more specific, more disposable, and mathematically unable to reveal the level above it.

Concretely, three properties force this design. First, the root must never travel: the permanent subscriber secret exists in only two places and is never sent over any interface, so no interception can ever expose it. Second, blast-radius isolation: a visited network, or one AMF, or one gNB, should get only the key material it needs and no more, so a breach anywhere is contained — refreshable and revocable without re-touching the root. Third, forward and backward separation: because every step is a one-way function keyed by its parent, holding a child key tells an attacker nothing about the parent or its siblings. The tree is the mechanism that delivers all three at once.

What

A layered set of keys, each derived from its parent by a one-way KDF, running from the permanent root K down to the leaf ciphering/integrity keys applied in PDCP on the air.

Why

Layering isolates blast radius. A key handed to a serving network, or to one specific AMF or gNB, can be refreshed or revoked without ever touching K, and a visited network never learns the permanent secret.

How

Primary authentication (5G-AKA or EAP-AKA') builds the anchor K_SEAF; the serving network derives K_AMF, which forks into NAS keys and the RAN key K_gNB; the gNB derives the RRC and UP leaf keys.

The Root of Trust and the Anchor Key

At the very top is K, the permanent subscriber key. It exists in exactly two places and is never sent over any interface: the tamper-resistant USIM in the device and the UDM/ARPF (Unified Data Management / Authentication credential Repository and Processing Function) in the home network. Everything below K is produced by key derivation functions, and because those functions are one-way, holding a child key tells an attacker nothing about its parent.

What

During primary authentication, K is used inside the USIM/ARPF to produce CK and IK (the cipher key and integrity key of AKA). From those the home network builds K_AUSF, then the anchor key K_SEAF, and the serving network turns that into K_AMF.

Why

Layering isolates blast radius. A key handed to a serving network, or to one specific AMF, can be refreshed or revoked without ever touching K. A visited network never learns the permanent secret.

How

The chosen method is either 5G-AKA or EAP-AKA'. Both run over the K/CK/IK base and both end by delivering the same anchor, K_SEAF, to the SEAF in the serving network.

Primary authentication is orchestrated by three network functions. The AUSF (Authentication Server Function) sits in the home network and holds K_AUSF. The UDM/ARPF generates the authentication vector from K. The SEAF (Security Anchor Function), co-located with the AMF in the serving network, receives the anchor key. In 5G-AKA the home network derives K_AUSF from CK, IK and the serving-network name, and computes an expected response HXRES*; the visited network only ever sees K_SEAF once the UE's response is confirmed. In EAP-AKA' the same CK, IK are first transformed into CK', IK' bound to the serving-network name, an EAP exchange runs to completion, and the EAP master session key yields K_AUSF. Either way the important property is identical: the anchor K_SEAF is cryptographically bound to this serving network, so a key stolen in one visited network cannot be replayed to authenticate the subscriber in another.

🎯

Why an "anchor" at all? K_SEAF is the single point from which the entire serving-network-side hierarchy grows. Keep it and you can regenerate every NAS and AS key without re-running authentication; that is exactly what a key change on the fly and idle-to-connected transitions exploit.

How Keys Are Derived — KDF, HMAC-SHA256 and FC codes

Every arrow in the hierarchy is one call to the same 3GPP key derivation function. The KDF defined in TS 33.220 (Annex B) is HMAC-SHA256: a keyed hash that takes the parent key as the HMAC key and a carefully constructed input string S as the message, and returns 256 bits of pseudo-random output used as the child key.

derived key = HMAC-SHA256( parent key, S )   where   S = FC ‖ P0 ‖ L0 ‖ P1 ‖ L1 ‖ …

The input string S always begins with a one-byte FC (Function Code) that names which derivation this is — a different FC for K_AUSF, for K_SEAF, for K_AMF, for K_gNB, and so on — so that even if two derivations shared the same parent and parameters they could never collide. After the FC come parameter blocks, each a value Pn immediately followed by its two-byte length Ln. The parameters are the freshness and binding inputs: the serving-network name, the SUPI, NAS COUNT values, the target cell's PCI and frequency, and so on. Because the parent key is the HMAC key, you cannot run the function backwards, and because every input is length-prefixed, no two different parameter sets can ever produce the same input string.

DerivationParent key (HMAC key)Key freshness / binding inputs in S
K_AUSFCKIK (5G-AKA) or EAP MSKServing-network name (SN name), SQN ⊕ AK
K_SEAFK_AUSFServing-network name (SN name)
K_AMFK_SEAFSUPI, ABBA parameter
K_NASint / K_NASencK_AMFAlgorithm type distinguisher, algorithm ID (NIA/NEA)
K_gNBK_AMFUplink NAS COUNT
NHK_AMFPrevious NH (or K_gNB for the first hop) — chained
K_gNB*K_gNB or NHTarget PCI, target ARFCN-DL
K_RRCint/enc, K_UPint/encK_gNBAlgorithm type distinguisher, algorithm ID
📘

The ABBA parameter: Anti-Bidding-down Between Architectures. It is fed into the K_AMF derivation to bind the key to the set of security features the network actually supports, so an attacker cannot force the UE and network down to a weaker feature set that a future release deprecates.

The K_AMF Fork — NAS Keys and the RAN Key

K_AMF is the fork in the tree, and it stays inside the AMF. From it two completely independent branches grow.

  • The NAS security keys protect signalling between the UE and the AMF: K_NASenc (ciphering) and K_NASint (integrity). These cover NAS messages such as Registration, Service Request, and PDU-session signalling. They are derived with an algorithm-type distinguisher and the negotiated NIA/NEA identity as inputs, so changing the NAS algorithm re-derives the key.
  • The RAN key K_gNB is the root of the entire Access Stratum branch. The AMF derives it from K_AMF using the current uplink NAS COUNT as the freshness input and hands only K_gNB to the serving gNB.

This split is the heart of 5G key separation. NAS keys live in the AMF and never reach the RAN; AS keys live in the gNB and never reach the core. A gNB that is compromised — a real concern with distributed and small-cell deployments — therefore cannot read or forge NAS signalling, and it never sees K_AMF, only its child K_gNB. From K_gNB the gNB derives four leaf keys, split by plane and by function, all applied inside PDCP.

KeyDerived fromUsed for
K— (permanent root)Master secret in USIM and UDM/ARPF; generates CK/IK in AKA. Never transmitted.
CK, IKK (+ RAND)AKA cipher/integrity keys; base for K_AUSF.
K_AUSFCK, IK / EAP MSKHeld in AUSF; parent of the anchor. Also anchors Steering-of-Roaming and later K_AKMA.
K_SEAFK_AUSFAnchor key delivered to the serving network's SEAF.
K_AMFK_SEAFBound to one AMF; parent of NAS keys and K_gNB and NH.
K_NASencK_AMFCiphering of NAS signalling (UE ↔ AMF).
K_NASintK_AMFIntegrity protection of NAS signalling.
K_gNBK_AMF (UL NAS COUNT)Root of the AS branch; delivered to serving gNB.
K_RRCencK_gNBCiphering of RRC signalling on SRBs.
K_RRCintK_gNBIntegrity protection of RRC signalling on SRBs (mandatory).
K_UPencK_gNBCiphering of user data on DRBs.
K_UPintK_gNBIntegrity protection of user data on DRBs (optional, per-DRB — new in 5G).
🔒

Mandatory vs optional: integrity is mandatory for SRBs once AS security is active (RRC signalling must be integrity-protected with a real NIA). User-plane integrity is optional, negotiated per DRB via the User Plane Security Policy; when enabled it applies K_UPint. Ciphering of both RRC and UP is applied by PDCP when configured. See PDCP (Ciphering & Integrity).

The Key-Derivation Tree

Reading top to bottom, each arrow is one HMAC-SHA256 call. The chain runs KCK/IKK_AUSFK_SEAFK_AMF, then forks: the left branch is NAS, the right branch is AS via K_gNB. The side labels name the key freshness input mixed into each step.

K (USIM and UDM/ARPF) CK, IK KDF (AUSF) K_AUSF + SN name K_SEAF (anchor) + SUPI, ABBA K_AMF + UL NAS COUNT K_NASenc K_NASint NAS branch (UE ↔ AMF) K_gNB AS branch (UE ↔ gNB) K_RRCenc K_RRCint K_UPenc K_UPint RRC (SRB) keys · UP (DRB) keys — applied in PDCP NH is also derived from K_AMF and chained (see handover)
Figure 1. The 5G key hierarchy of TS 33.501: root K down to the leaf AS keys, forking at K_AMF into the NAS and AS (K_gNB) branches. Side labels show each step's key freshness input.

Handover Key Handling — NH, NCC and K_gNB*

When the UE moves between gNBs, the target must receive a fresh K_gNB the source cannot predict — otherwise a compromised source gNB could keep eavesdropping on the UE at its new cell. 5G solves this with a chain of Next Hop values counted by an NH Chaining Counter.

NH / NCC

NH (Next Hop) is key material derived from K_AMF; NCC (NH Chaining Counter) is the counter that records how many hops down the NH chain a given value is. The AMF provisions {NH, NCC} pairs to the gNB.

Why K_gNB*

At handover the source computes K_gNB* — the key the target will adopt as its K_gNB — and passes it plus the associated NCC to the target inside the handover preparation signalling.

Horizontal vs vertical

Horizontal: K_gNB* is derived from the current K_gNB (source still knows the input — weaker). Vertical: derived from an unused fresh NH the source cannot invert — the target gets forward security.

Both derivations also mix in the target cell's PCI (Physical Cell Identity) and downlink frequency ARFCN-DL, binding K_gNB* to the specific target cell. The chosen NCC is echoed to the UE in the handover command (RRCReconfiguration with reconfigurationWithSync) so the UE derives the identical K_gNB*. If the received NCC equals the UE's stored value, a horizontal derivation happened; if it is greater, the UE knows a vertical derivation occurred and iterates the NH chain forward (each iteration a fresh HMAC-SHA256 over the previous NH) until its counter matches, then derives K_gNB* from that NH.

AspectHorizontal derivationVertical derivation
Input to K_gNB*Current active K_gNBFresh unused NH (from K_AMF)
NCC behaviourUE's stored NCC unchanged (echoed value equal)Echoed NCC greater than stored → UE advances the chain
Also mixed inTarget PCI, ARFCN-DLTarget PCI, ARFCN-DL
Security propertySource knows the input — no forward security this hopSource cannot invert NH — forward security
Typical useXn handover when no fresh NH is availableN2 (via AMF) handover, or Xn once AMF supplies a new NH

The same machinery covers a key change on the fly in connected mode. If the network wants to refresh K_gNB without a real handover — for example to recover from a PDCP COUNT that is about to wrap and repeat — it runs an intra-cell handover, deriving a new K_gNB exactly as above so the counters restart from a fresh key. A full refresh of K_AMF and the NAS keys, by contrast, requires re-running primary authentication and then a NAS Security Mode Command to activate the new context. See Xn Handover for where K_gNB* and NCC travel in the HANDOVER REQUEST.

🎯

Two-hop forward security: even with vertical derivation, a target that later becomes a source can reuse an NH only once. Because each NH is chained from K_AMF, a compromised gNB is locked out of the UE's keys after at most two hops — the practical guarantee the NH/NCC design is built to give.

Identity Privacy — SUPI, SUCI and ECIES

Keys protect traffic, but the subscriber's identity needs protecting too. In 4G the permanent IMSI was occasionally sent in the clear, enabling IMSI-catchers. 5G closes that hole: the permanent identifier, the SUPI (Subscription Permanent Identifier), is never sent over the air in the clear. Instead the UE sends a SUCI (Subscription Concealed Identifier) — the SUPI encrypted with the home network's public key.

What

The SUCI conceals only the subscriber-specific part (the MSIN) of the SUPI. The routing part (MCC/MNC, i.e. the home network id) stays in the clear so the serving network can route the authentication request to the right home network.

Why

So a passive attacker on the air interface cannot map a transmission to a specific subscriber. Only the home network, holding the private key, can de-conceal a SUCI back to a SUPI.

How

Concealment uses ECIES (Elliptic Curve Integrated Encryption Scheme). The UE generates an ephemeral key pair, does an ECDH with the home network public key stored in the USIM, derives a symmetric key, and encrypts the MSIN. Profiles A (Curve25519) and B (secp256r1) are defined in TS 33.501 Annex C.

The home network public key is provisioned in the USIM together with a Home Network Public Key Identifier, so the operator can rotate keys and the UE can tell the network which key it used. Because the UE picks a fresh ephemeral key for every concealment, two SUCI values for the same subscriber look unrelated on the air — there is no linkability. The SUCI also carries a Protection Scheme Identifier (0 for null-scheme, used only for unauthenticated emergency registration or test USIMs; 1/2 for ECIES profiles A/B). De-concealment happens at the UDM/SIDF (Subscription Identifier De-concealing Function) in the home network, the only place the private key exists.

📘

5G-GUTI is still preferred: once registered, the UE is addressed by the temporary 5G-GUTI for as long as possible, so even the SUCI is sent rarely. The SUCI is the fallback for the very first contact or when the network has lost the UE's context.

Security Contexts, ngKSI and the NEA/NIA Algorithms

All these keys are grouped into a 5G security context: the key set (K_AMF plus derived NAS keys), the selected algorithms, the NAS COUNT values, and a key-set identifier. A context comes in two flavours. A native context is created directly by a 5G primary authentication run. A mapped context is derived from an EPS (4G) context during interworking — for example when a UE moves from LTE to NR, K_AMF is mapped from the LTE K_ASME. The UE and network can hold a native and a mapped context at once and switch between them.

Each context is tagged by an ngKSI (Key Set Identifier in 5G), a small value carried in NAS signalling so the UE and AMF can refer to "the context we already share" without transmitting any key. The ngKSI includes a type flag distinguishing native from mapped, plus a 3-bit value; the reserved value 111 means "no key available". This is how, after an idle period, a Service Request can reactivate an existing context instead of re-authenticating — the ngKSI names the context both sides kept.

Keys are useless without an algorithm to apply them. 5G negotiates one ciphering algorithm and one integrity algorithm, separately for NAS (in the NAS Security Mode Command) and for AS (in the AS Security Mode Command). Each is identified by a 4-bit code: the NEA family for enciphering and the NIA family for integrity.

Ciphering (NEA)Integrity (NIA)Core algorithmNotes
NEA0NIA0NULLNo protection — only unauthenticated emergency / test
NEA1NIA1128-SNOW 3GStream cipher, inherited from LTE
NEA2NIA2128-AESAES in CTR (cipher) / CMAC (integrity)
NEA3NIA3128-ZUCStream cipher, favoured in some markets

All keys today are 128 bits, though the hierarchy already carries 256-bit key material (the KDF output) so that 256-bit algorithm variants can be introduced without redesign. The algorithm identity is itself an input to the leaf-key derivation (the "algorithm type distinguisher" plus the 4-bit ID), which is why re-negotiating an algorithm re-derives its key — the same K_gNB with a different NIA gives a different K_RRCint.

⚠️

NIA0 trap: the NULL integrity algorithm NIA0 is permitted only for unauthenticated emergency calls. In normal operation RRC and NAS integrity always use a real algorithm — a null-integrity SRB in a normal call would be a security fault, not a valid configuration.

🔀

LTE ↔ NR: the shape is familiar but 5G adds layers. LTE's anchor was K_ASME derived at the MME; 5G inserts K_AUSF and a dedicated anchor K_SEAF above K_AMF, binding the anchor to the serving-network name. LTE algorithms were EEA/EIA; 5G renames them NEA/NIA (same SNOW 3G / AES / ZUC cores). Genuinely new in 5G: optional user-plane integrity (K_UPint per DRB), SUPI concealment via SUCI/ECIES (LTE sent IMSI in the clear), and the anchor-key design that keeps the permanent secret and the NAS keys away from a compromised RAN.

⚠ Common pitfalls / gotchas

  • Assuming user-plane integrity is always on. UP integrity (K_UPint) is optional and per-DRB, driven by the User Plane Security Policy; only SRB (RRC) integrity is mandatory once AS security is active.
  • Confusing horizontal and vertical handover keying. Equal echoed NCC means horizontal (no forward security this hop); a greater NCC means vertical — the UE must advance the NH chain, not just re-key.
  • Thinking the SUCI hides everything. Only the MSIN is concealed; the MCC/MNC routing part stays in the clear so the request can reach the home network.
  • Forgetting algorithm identity is a key input. Re-negotiating a NEA/NIA re-derives the leaf key — the same K_gNB with a different NIA yields a different K_RRCint.
  • Treating ngKSI = 111 as an error. It is the defined "no key available" value that forces a fresh authentication, not a fault.

Summary

5G security is one strict tree defined in TS 33.501. The permanent root K lives only in the USIM and UDM/ARPF and is never transmitted; primary authentication (5G-AKA or EAP-AKA') turns it into CK/IKK_AUSF → the serving-network-bound anchor K_SEAFK_AMF. Every arrow is one HMAC-SHA256 KDF call whose input string starts with a distinguishing FC and carries length-prefixed freshness inputs, so derivations are one-way and collision-free.

K_AMF forks into the NAS branch (K_NASenc/K_NASint, staying in the AMF) and the AS branch via K_gNB (derived with the uplink NAS COUNT, handed to the gNB), which fans out into the PDCP leaf keys K_RRCenc/K_RRCint and K_UPenc/K_UPint. Key separation keeps core secrets out of the RAN, so a compromised gNB never sees K_AMF. Mobility re-keys the AS branch through the NH/NCC chain and K_gNB* (horizontal vs vertical, bound to target PCI/ARFCN-DL), giving two-hop forward security.

Around the key tree sit three more mechanisms: identity privacy (SUPI concealed as a SUCI via ECIES, de-concealed only at the home SIDF), security contexts tagged by ngKSI (native vs mapped, reactivated without re-authentication), and the negotiated NEA/NIA algorithm families. The single idea to carry away: every key that touches real traffic is disposable and derived, so a leaf compromise never climbs back to the root.

Q&A Quick Q&A

Q. What is the anchor key and where does it come from?

A. K_SEAF. It is derived from K_AUSF (bound to the serving-network name) during primary authentication — 5G-AKA or EAP-AKA' — and delivered to the SEAF in the serving network. It is the single anchor from which K_AMF and everything below is grown.

Q. Which function derives the keys, and what stops it being reversed?

A. Every step is HMAC-SHA256 (the TS 33.220 KDF) with the parent key as the HMAC key and an input string S = FC ‖ P0 ‖ L0 ‖ …. The parent-key-as-HMAC-key property makes it one-way; the leading FC and length-prefixed parameters make every derivation domain-separated and collision-free.

Q. Where does K_gNB come from, and does the gNB ever see K_AMF?

A. The AMF derives K_gNB from K_AMF with the uplink NAS COUNT as freshness and sends only K_gNB to the gNB. The gNB never sees K_AMF — key separation keeps core secrets out of the RAN.

Q. What is the difference between horizontal and vertical K_gNB* derivation?

A. Horizontal derives K_gNB* from the current K_gNB (the source still knows the input). Vertical derives it from a fresh unused NH the source cannot invert, giving forward security. The NCC echoed to the UE tells it which happened: equal means horizontal, greater means vertical (advance the NH chain). Both also bind in the target PCI and ARFCN-DL.

Q. How does 5G hide the permanent subscriber identity?

A. The SUPI is never sent in the clear; the UE sends a SUCI, formed by encrypting the MSIN with the home network public key using ECIES and a fresh ephemeral key each time. Only the home network's SIDF, holding the private key, can de-conceal it. The routing part stays clear for routing.

Q. What do native vs mapped contexts and ngKSI mean?

A. A native context comes from a 5G authentication run; a mapped context is derived from a 4G/EPS context during interworking. The ngKSI identifies a stored context (with a native/mapped type flag) so both sides can reactivate it without re-authenticating; value 111 means no key available.

Where this connects

The hierarchy is the theory; these are where the keys are actually put to work:

AS Security Mode — algorithm negotiation & activationPDCP — Ciphering & IntegrityXn Handover — K_gNB* / NCC in flight