# 5G-IPAKA: An Improved Primary Authentication and Key Agreement Protocol for 5G Networks
## 2 Overview of the 5G AKA Protocol
The \(AUSF\) generates a 5G AV from the 5G HE AV received from the UDM/ARPF by computing \(HXRE*\) from \(XRES*\), computing \(K_{SEAF}\) from \(K_{AUSF}\), replacing \(XRES*\) with \(HXRE5*\), and replacing \(K_{AUSF}\) with \(K_{SEAF}\) in the 5G HE AV, where \(HXRES*=SHA256(RAND||XRES*),K_{SEAF}=KDF(K_{AUSF},SNN)\), and \(SHA256()\) is a hash function;
9. The ASUF creates a 5G serving environment authentication vector (5G SE AV) by removing \(K_{SEAF}\) from the 5G AV, then sends the 5G SE AV (i.e., \(RAND\), \(AUTN\), and \(HXRES*\)) to the \(SEAF\);
10. The \(SEAF\) stores \(HXRES*\), and then sends \(RAND\), \(AUTN\), \(ngKSI\), and \(ABBA\) to the \(UE\). Here, \(ngKSI\) is used by the \(UE\) and the access and mobility management function (\(AMF\)) to identify the \(K_{AMF}\) and the partial native security context that is created if the authentication is successful. \(ABBA\) denotes the anti-bidding down between architectures (\(ABBA\)) parameter;
11. In the \(UE\), the ME forwards \(RAND\) and \(AUTN\) to the USIM. Upon receipt of \(RAND\) and \(AUTN\), the USIM first computes the anonymity key \(AK\) and retrieves the sequence number \(SQN=(SQN\oplus AK)\oplus AK\). Next, the USIM computes \(XMAC=f_{1}(K,SQN||RAND||AMF)\) and compares this with \(MAC\), which is included in \(AUTN\). Then, the USIM verifies that the received \(SQN\) is in the correct range. If \(XMAC\) is the same as \(MAC\) and \(SQN\) is in the correct range, then the USIM computes a response \(RES=f_{2}(K,RAND)\), \(CK\), and \(IK\), and then returns \(RES\), \(CK\), and \(IK\) to the ME. The ME then computes \(RES*=KDF(CK||IK,SNN||RAND||RES)\), \(K_{AUSF}\), and \(K_{SEAF}\);
12. The \(UE\) sends \(RES*\) to the \(SEAF\);
13. The \(SEAF\) computes \(HRES*=SHA256(RAND||RES*)\) and compares this with \(HXRES*\). If they coincide, then the \(SEAF\) considers the authentication successful from the serving network point of view; if not, then the \(SEAF\) considers the authentication unsuccessful;
14. The \(SEAF\) sends the received \(RES*\) to the \(AUSF\);
15. The \(AUSF\) compares the received \(RES*\) with the stored \(XRES*\). If \(RES*\) and \(XRES*\) are equal, then the \(AUSF\) considers the authentication successful from the home network point of view. Then, the \(\mathit{AUSF}\) informs the UDM about the authentication result;
* The \(\mathit{AUSF}\) indicates to the \(\mathit{SEAF}\) whether the authentication was successful or not from the home network point of view (i.e., \(\mathit{Result}\)). If the authentication was successful, then the ASUF also sends \(K_{\mathit{SEAF}}\) and \(\mathit{SUPI}\) to the \(\mathit{SEAF}\). In step \(11\), if \(\mathit{XMAC}\) and \(\mathit{MAC}\) are different, then the USIM indicates to the ME an \(\mathit{MAC}\) failure of \(\mathit{AUTN}\). Then, the \(\mathit{UE}\) sends a \"\(\mathit{MAC}\) failure\" indication to the \(\mathit{SEAF}\). Further, the \(\mathit{SEAF}\) sends the \"\(\mathit{MAC}\) failure\" indication to the \(\mathit{AUSF}\). Finally, the ASUF sends the \"\(\mathit{MAC}\) failure\" indication to the UDM/ARPF. In step \(11\), if \(\mathit{SQN}\) is not in the correct range, then the USIM computes \(\mathit{AUTS}=\mathit{SQN}_{\mathit{UE}}\oplus\mathit{AK}^{*}||\mathit{MAC }-\mathit{S}\), and then sends \(\mathit{AUTS}\) with a \"synchronization failure\" indication to the ME, where \(\mathit{SQN}_{\mathit{UE}}\) denotes the highest sequence number the USIM has accepted, \(\mathit{AK}^{*}=f_{5}^{*}(K,\mathit{RAND}),\ \mathit{MAC}-\mathit{S}=f_{1}^{*}(K, \mathit{SQN}_{\mathit{UE}}\big{|}\big{|}\mathit{RAND}\big{|}\big{|}\mathit{AMF }_{0})\), \(\mathit{AMF}_{0}\) is a dummy value of all zeros, \(f_{1}^{*}()\) is a message authentication function, and \(f_{5}^{*}()\) is a key-generating function. Then, the \(\mathit{UE}\) sends \(\mathit{AUTS}\) with a \"synchronization failure\" indication to the \(\mathit{SEAF}\). Further, the \(\mathit{SEAF}\) sends \(\mathit{RAND}\) and \(\mathit{AUTS}\) with a \"synchronization failure\" indication to the \(\mathit{AUSF}\).