pespin has submitted this change. (
https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/40420?usp=email )
Change subject: mme: Move LTE_CryptoFunction* to library/
......................................................................
mme: Move LTE_CryptoFunction* to library/
S1AP_Emulation is already importing LTE_CryptoFunction.ttcn, so it
really belongs to library and not to mme/ directory.
While at it, split Snow3G algos to its own subdir so it can be easily
exported standalone, eg. when used by 5G NAS in the future.
Change-Id: I76f86beeb2c49110eea0fac6abffee8307a3c22c
---
A library/LTE_CryptoFunctionDefs.cc
R library/LTE_CryptoFunctions.ttcn
R library/lte_crypto/key_derivation.c
R library/lte_crypto/key_derivation.h
R library/snow_3g/Snow3G_FunctionDefs.cc
A library/snow_3g/Snow3G_Functions.ttcn
R library/snow_3g/snow-3g.c
R library/snow_3g/snow-3g.h
M mme/gen_links.sh
M mme/regen_makefile.sh
10 files changed, 125 insertions(+), 72 deletions(-)
Approvals:
laforge: Looks good to me, but someone else must approve
fixeria: Looks good to me, approved
Jenkins Builder: Verified
diff --git a/library/LTE_CryptoFunctionDefs.cc b/library/LTE_CryptoFunctionDefs.cc
new file mode 100644
index 0000000..fafb22a
--- /dev/null
+++ b/library/LTE_CryptoFunctionDefs.cc
@@ -0,0 +1,89 @@
+/* Utility functions from ogslib imported to TTCN-3
+ *
+ * (C) 2019 Harald Welte <laforge(a)gnumonks.org>
+ * All rights reserved.
+ *
+ * Released under the terms of GNU General Public License, Version 2 or
+ * (at your option) any later version.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <stdint.h>
+
+#include <Boolean.hh>
+#include <Integer.hh>
+#include <Octetstring.hh>
+#include <Bitstring.hh>
+
+#include "key_derivation.h"
+
+namespace LTE__CryptoFunctions {
+
+OCTETSTRING f__kdf__kasme(const OCTETSTRING& ck, const OCTETSTRING& ik, const
OCTETSTRING& plmn_id,
+ const OCTETSTRING& sqn, const OCTETSTRING& ak)
+{
+ TTCN_Buffer ttcn_buf_ck(ck);
+ TTCN_Buffer ttcn_buf_ik(ik);
+ TTCN_Buffer ttcn_buf_plmn_id(plmn_id);
+ TTCN_Buffer ttcn_buf_sqn(sqn);
+ TTCN_Buffer ttcn_buf_ak(ak);
+ uint8_t kasme[32];
+
+ hss_auc_kasme(ttcn_buf_ck.get_data(), ttcn_buf_ik.get_data(),
ttcn_buf_plmn_id.get_data(),
+ ttcn_buf_sqn.get_data(), ttcn_buf_ak.get_data(), kasme);
+ return OCTETSTRING(sizeof(kasme), kasme);
+}
+
+OCTETSTRING f__kdf__nas__int(const INTEGER& alg_id, const OCTETSTRING &kasme)
+{
+ TTCN_Buffer ttcn_buf_kasme(kasme);
+ uint8_t knas[16];
+
+ mme_kdf_nas(MME_KDF_NAS_INT_ALG, (int)alg_id, (const uint8_t*)
ttcn_buf_kasme.get_data(), knas);
+ return OCTETSTRING(sizeof(knas), knas);
+}
+
+OCTETSTRING f__kdf__nas__enc(const INTEGER& alg_id, const OCTETSTRING &kasme)
+{
+ TTCN_Buffer ttcn_buf_kasme(kasme);
+ uint8_t knas[16];
+
+ mme_kdf_nas(MME_KDF_NAS_ENC_ALG, (int)alg_id, (const uint8_t*)
ttcn_buf_kasme.get_data(), knas);
+ return OCTETSTRING(sizeof(knas), knas);
+}
+
+
+OCTETSTRING f__kdf__enb(const OCTETSTRING &kasme, const INTEGER &ul_count)
+{
+ TTCN_Buffer ttcn_buf_kasme(kasme);
+ uint8_t kenb[32];
+
+ mme_kdf_enb(ttcn_buf_kasme.get_data(), (int)ul_count, kenb);
+ return OCTETSTRING(sizeof(kenb), kenb);
+}
+
+OCTETSTRING f__kdf__nh(const OCTETSTRING &kasme, const OCTETSTRING &sync_inp)
+{
+ TTCN_Buffer ttcn_buf_kasme(kasme);
+ TTCN_Buffer ttcn_buf_sync_inp(sync_inp);
+ uint8_t kenb[32];
+
+ mme_kdf_nh(ttcn_buf_kasme.get_data(), ttcn_buf_sync_inp.get_data(), kenb);
+ return OCTETSTRING(sizeof(kenb), kenb);
+}
+
+OCTETSTRING f__kdf__nas__token(const OCTETSTRING &kasme, const INTEGER
&ul_count)
+{
+ TTCN_Buffer ttcn_buf_kasme(kasme);
+ uint8_t nas_token[32];
+
+ mme_kdf_nas_token(ttcn_buf_kasme.get_data(), (int)ul_count, nas_token);
+ return OCTETSTRING(sizeof(nas_token), nas_token);
+}
+
+
+} // namespace
diff --git a/mme/LTE_CryptoFunctions.ttcn b/library/LTE_CryptoFunctions.ttcn
similarity index 96%
rename from mme/LTE_CryptoFunctions.ttcn
rename to library/LTE_CryptoFunctions.ttcn
index fafcb34..57e0c4d 100644
--- a/mme/LTE_CryptoFunctions.ttcn
+++ b/library/LTE_CryptoFunctions.ttcn
@@ -14,6 +14,8 @@
import from General_Types all;
import from Misc_Helpers all;
+import from Snow3G_Functions all;
+
import from S1AP_Types all;
import from S1AP_PDU_Descriptions all;
@@ -24,12 +26,6 @@
* low-level API (external C/C++ code)
*********************************************************************************/
-external function f_snow_3g_f8(in OCT16 key, in integer count, in integer bearer,
- in boolean is_downlink, in octetstring data) return octetstring;
-
-external function f_snow_3g_f9(in OCT16 key, in integer count, in integer fresh,
- in boolean is_downlink, in octetstring data) return OCT4;
-
external function f_kdf_kasme(in OCT16 ck, in OCT16 ik, in OCT3 plmn_id,
in OCT6 sqn, in OCT6 ak) return OCT32;
diff --git a/mme/key_derivation.c b/library/lte_crypto/key_derivation.c
similarity index 100%
rename from mme/key_derivation.c
rename to library/lte_crypto/key_derivation.c
diff --git a/mme/key_derivation.h b/library/lte_crypto/key_derivation.h
similarity index 100%
rename from mme/key_derivation.h
rename to library/lte_crypto/key_derivation.h
diff --git a/mme/LTE_CryptoFunctionDefs.cc b/library/snow_3g/Snow3G_FunctionDefs.cc
similarity index 65%
rename from mme/LTE_CryptoFunctionDefs.cc
rename to library/snow_3g/Snow3G_FunctionDefs.cc
index 7f82224..340afda 100644
--- a/mme/LTE_CryptoFunctionDefs.cc
+++ b/library/snow_3g/Snow3G_FunctionDefs.cc
@@ -20,7 +20,6 @@
#include <Bitstring.hh>
#include "snow-3g.h"
-#include "key_derivation.h"
//#define DEBUG
@@ -70,7 +69,7 @@
}
#endif
-namespace LTE__CryptoFunctions {
+namespace Snow3G__Functions {
/* f8.
@@ -131,67 +130,4 @@
return OCTETSTRING(4, tmp);
}
-OCTETSTRING f__kdf__kasme(const OCTETSTRING& ck, const OCTETSTRING& ik, const
OCTETSTRING& plmn_id,
- const OCTETSTRING& sqn, const OCTETSTRING& ak)
-{
- TTCN_Buffer ttcn_buf_ck(ck);
- TTCN_Buffer ttcn_buf_ik(ik);
- TTCN_Buffer ttcn_buf_plmn_id(plmn_id);
- TTCN_Buffer ttcn_buf_sqn(sqn);
- TTCN_Buffer ttcn_buf_ak(ak);
- uint8_t kasme[32];
-
- hss_auc_kasme(ttcn_buf_ck.get_data(), ttcn_buf_ik.get_data(),
ttcn_buf_plmn_id.get_data(),
- ttcn_buf_sqn.get_data(), ttcn_buf_ak.get_data(), kasme);
- return OCTETSTRING(sizeof(kasme), kasme);
-}
-
-OCTETSTRING f__kdf__nas__int(const INTEGER& alg_id, const OCTETSTRING &kasme)
-{
- TTCN_Buffer ttcn_buf_kasme(kasme);
- uint8_t knas[16];
-
- mme_kdf_nas(MME_KDF_NAS_INT_ALG, (int)alg_id, (const u8*) ttcn_buf_kasme.get_data(),
knas);
- return OCTETSTRING(sizeof(knas), knas);
-}
-
-OCTETSTRING f__kdf__nas__enc(const INTEGER& alg_id, const OCTETSTRING &kasme)
-{
- TTCN_Buffer ttcn_buf_kasme(kasme);
- uint8_t knas[16];
-
- mme_kdf_nas(MME_KDF_NAS_ENC_ALG, (int)alg_id, (const u8*) ttcn_buf_kasme.get_data(),
knas);
- return OCTETSTRING(sizeof(knas), knas);
-}
-
-
-OCTETSTRING f__kdf__enb(const OCTETSTRING &kasme, const INTEGER &ul_count)
-{
- TTCN_Buffer ttcn_buf_kasme(kasme);
- uint8_t kenb[32];
-
- mme_kdf_enb(ttcn_buf_kasme.get_data(), (int)ul_count, kenb);
- return OCTETSTRING(sizeof(kenb), kenb);
-}
-
-OCTETSTRING f__kdf__nh(const OCTETSTRING &kasme, const OCTETSTRING &sync_inp)
-{
- TTCN_Buffer ttcn_buf_kasme(kasme);
- TTCN_Buffer ttcn_buf_sync_inp(sync_inp);
- uint8_t kenb[32];
-
- mme_kdf_nh(ttcn_buf_kasme.get_data(), ttcn_buf_sync_inp.get_data(), kenb);
- return OCTETSTRING(sizeof(kenb), kenb);
-}
-
-OCTETSTRING f__kdf__nas__token(const OCTETSTRING &kasme, const INTEGER
&ul_count)
-{
- TTCN_Buffer ttcn_buf_kasme(kasme);
- uint8_t nas_token[32];
-
- mme_kdf_nas_token(ttcn_buf_kasme.get_data(), (int)ul_count, nas_token);
- return OCTETSTRING(sizeof(nas_token), nas_token);
-}
-
-
} // namespace
diff --git a/library/snow_3g/Snow3G_Functions.ttcn
b/library/snow_3g/Snow3G_Functions.ttcn
new file mode 100644
index 0000000..3662163
--- /dev/null
+++ b/library/snow_3g/Snow3G_Functions.ttcn
@@ -0,0 +1,22 @@
+/* Utility functions from ogslib imported to TTCN-3
+ *
+ * (C) 2019 Harald Welte <laforge(a)gnumonks.org>
+ * All rights reserved.
+ *
+ * Released under the terms of GNU General Public License, Version 2 or
+ * (at your option) any later version.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+module Snow3G_Functions {
+
+import from General_Types all;
+
+external function f_snow_3g_f8(in OCT16 key, in integer count, in integer bearer,
+ in boolean is_downlink, in octetstring data) return octetstring;
+
+external function f_snow_3g_f9(in OCT16 key, in integer count, in integer fresh,
+ in boolean is_downlink, in octetstring data) return OCT4;
+
+} // namespace
diff --git a/mme/snow-3g.c b/library/snow_3g/snow-3g.c
similarity index 100%
rename from mme/snow-3g.c
rename to library/snow_3g/snow-3g.c
diff --git a/mme/snow-3g.h b/library/snow_3g/snow-3g.h
similarity index 100%
rename from mme/snow-3g.h
rename to library/snow_3g/snow-3g.h
diff --git a/mme/gen_links.sh b/mme/gen_links.sh
index e2e9fb0..af0355f 100755
--- a/mme/gen_links.sh
+++ b/mme/gen_links.sh
@@ -69,12 +69,21 @@
FILES+="S1AP_EncDec.cc S1AP_Types.ttcn S1AP_Templates.ttcn "
gen_links $DIR $FILES
+DIR=../library/snow_3g
+FILES="snow-3g.c snow-3g.h Snow3G_FunctionDefs.cc Snow3G_Functions.ttcn "
+gen_links $DIR $FILES
+
+DIR=../library/lte_crypto
+FILES="key_derivation.c key_derivation.h "
+gen_links $DIR $FILES
+
DIR=../library
FILES="Misc_Helpers.ttcn General_Types.ttcn GSM_Types.ttcn Osmocom_Types.ttcn
Native_Functions.ttcn Native_FunctionDefs.cc IPCP_Types.ttcn IPCP_Templates.ttcn "
FILES+="SGsAP_Templates.ttcn SGsAP_CodecPort.ttcn SGsAP_CodecPort_CtrlFunct.ttcn
SGsAP_CodecPort_CtrlFunctDef.cc SGsAP_Emulation.ttcn DNS_Helpers.ttcn "
FILES+="L3_Templates.ttcn RLCMAC_CSN1_Templates.ttcn RLCMAC_CSN1_Types.ttcn "
FILES+="S1AP_CodecPort.ttcn S1AP_CodecPort_CtrlFunctDef.cc
S1AP_CodecPort_CtrlFunct.ttcn S1AP_Functions.ttcn S1AP_Emulation.ttcn "
-FILES+="NAS_EPS_Templates.ttcn GTPv2_PrivateExtensions.ttcn GTPv2_Templates.ttcn
"
+FILES+="NAS_EPS_Templates.ttcn LTE_CryptoFunctionDefs.cc LTE_CryptoFunctions.ttcn
"
+FILES+="GTPv2_PrivateExtensions.ttcn GTPv2_Templates.ttcn "
FILES+="DIAMETER_Types.ttcn DIAMETER_CodecPort.ttcn
DIAMETER_CodecPort_CtrlFunct.ttcn DIAMETER_CodecPort_CtrlFunctDef.cc
DIAMETER_Emulation.ttcn "
FILES+="DIAMETER_Templates.ttcn DIAMETER_ts29_272_Templates.ttcn "
FILES+="GTPv1C_CodecPort.ttcn GTPv1C_CodecPort_CtrlFunct.ttcn
GTPv1C_CodecPort_CtrlFunctDef.cc GTPv1U_CodecPort.ttcn GTPv1U_CodecPort_CtrlFunct.ttcn
GTPv1U_CodecPort_CtrlFunctDef.cc GTP_Emulation.ttcn GTPv1C_Templates.ttcn
Osmocom_Gb_Types.ttcn "
diff --git a/mme/regen_makefile.sh b/mme/regen_makefile.sh
index 768fbd2..4eb0f1a 100755
--- a/mme/regen_makefile.sh
+++ b/mme/regen_makefile.sh
@@ -21,6 +21,7 @@
S1AP_CodecPort_CtrlFunctDef.cc
S1AP_EncDec.cc
SGsAP_CodecPort_CtrlFunctDef.cc
+ Snow3G_FunctionDefs.cc
TCCConversion.cc
TCCEncoding.cc
TCCInterface.cc
--
To view, visit
https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/40420?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: osmo-ttcn3-hacks
Gerrit-Branch: master
Gerrit-Change-Id: I76f86beeb2c49110eea0fac6abffee8307a3c22c
Gerrit-Change-Number: 40420
Gerrit-PatchSet: 3
Gerrit-Owner: pespin <pespin(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: jolly <andreas(a)eversberg.eu>
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>