summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2016-04-20 10:39:00 +0200
committerHarald Welte <laforge@gnumonks.org>2016-05-05 18:48:05 +0200
commitcd9cb90f452ed83a3df0bf9d136aea19186c7f7b (patch)
treee6972a4528b0a942b846649beb947ef87a71146f /src
parent3a96d2837c2d5648692737ad5ddcc3893e12e913 (diff)
auth_core: Add osmo_auth_3g_from_2g() to compute CK+IK from Kc
This function performs the C5+C4 conversion to derive UMTS key material from a 2G-only subscriber.
Diffstat (limited to 'src')
-rw-r--r--src/gsm/auth_core.c41
-rw-r--r--src/gsm/libosmogsm.map1
2 files changed, 42 insertions, 0 deletions
diff --git a/src/gsm/auth_core.c b/src/gsm/auth_core.c
index 3a0866be..b78cdd50 100644
--- a/src/gsm/auth_core.c
+++ b/src/gsm/auth_core.c
@@ -90,6 +90,47 @@ int osmo_auth_supported(enum osmo_auth_algo algo)
return 0;
}
+/* C5 function to derive UMTS IK from GSM Kc */
+static inline void c5_function(uint8_t *ik, const uint8_t *kc)
+{
+ unsigned int i;
+
+ for (i = 0; i < 4; i++)
+ ik[i] = kc[i] ^ kc[i+4];
+ memcpy(ik+4, kc, 8);
+ for (i = 12; i < 16; i++)
+ ik[i] = ik[i-12];
+}
+
+/* C4 function to derive UMTS CK from GSM Kc */
+static inline void c4_function(uint8_t *ck, const uint8_t *kc)
+{
+ memcpy(ck, kc, 8);
+ memcpy(ck+8, kc, 8);
+}
+
+/*! \brief Generate 3G CK + IK from 2G authentication vector
+ * \param vec Authentication Vector to be modified
+ *
+ * This function performs the C5 and C4 functions to derive the UMTS key
+ * material from the GSM key material in the supplied vector, _if_ the input
+ * vector doesn't yet have UMTS authentication capability */
+int osmo_auth_3g_from_2g(struct osmo_auth_vector *vec)
+{
+ if ((vec->auth_types & OSMO_AUTH_TYPE_GSM) &&
+ !(vec->auth_types & OSMO_AUTH_TYPE_UMTS)) {
+ c5_function(vec->ik, vec->kc);
+ c4_function(vec->ck, vec->kc);
+ /* We cannot actually set OSMO_AUTH_TYPE_UMTS as we have no
+ * AUTN and no RES, and thus can only perform GSM
+ * authentication with this tuple.
+ * */
+ return 1;
+ }
+
+ return 0;
+}
+
/*! \brief Generate authentication vector
* \param[out] vec Generated authentication vector
* \param[in] aud Subscriber-specific key material
diff --git a/src/gsm/libosmogsm.map b/src/gsm/libosmogsm.map
index 5ed9499c..5284842c 100644
--- a/src/gsm/libosmogsm.map
+++ b/src/gsm/libosmogsm.map
@@ -231,6 +231,7 @@ osmo_auth_alg_name;
osmo_auth_alg_parse;
osmo_auth_gen_vec;
osmo_auth_gen_vec_auts;
+osmo_auth_3g_from_2g;
osmo_auth_load;
osmo_auth_register;
osmo_auth_supported;