diff options
Diffstat (limited to 'src/gsm')
-rw-r--r-- | src/gsm/Makefile.am | 4 | ||||
-rw-r--r-- | src/gsm/gea.c | 60 | ||||
-rw-r--r-- | src/gsm/gprs_gea.c | 48 |
3 files changed, 110 insertions, 2 deletions
diff --git a/src/gsm/Makefile.am b/src/gsm/Makefile.am index 781f153a..0f43f48a 100644 --- a/src/gsm/Makefile.am +++ b/src/gsm/Makefile.am @@ -24,10 +24,10 @@ libgsmint_la_SOURCES = a5.c rxlev_stat.c tlv_parser.c comp128.c comp128v23.c \ conv_tch_afs_6_7_gen.c conv_tch_afs_5_9_gen.c \ conv_tch_afs_5_15_gen.c conv_tch_afs_4_75_gen.c \ auth_core.c auth_comp128v1.c auth_comp128v23.c \ - auth_milenage.c milenage/aes-encblock.c \ + auth_milenage.c milenage/aes-encblock.c gea.c \ milenage/aes-internal.c milenage/aes-internal-enc.c \ milenage/milenage.c gan.c ipa.c gsm0341.c apn.c \ - gsup.c + gsup.c gprs_gea.c libgsmint_la_LDFLAGS = -no-undefined libgsmint_la_LIBADD = ../libosmocore.la diff --git a/src/gsm/gea.c b/src/gsm/gea.c new file mode 100644 index 00000000..b8f6768a --- /dev/null +++ b/src/gsm/gea.c @@ -0,0 +1,60 @@ +/* + * gea.c + * + * Implementation of GEA3 and GEA4 + * + * Copyright (C) 2016 by Sysmocom s.f.m.c. GmbH + * + * All Rights Reserved + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include <osmocom/core/bits.h> +#include <osmocom/crypt/gprs_cipher.h> +#include <osmocom/crypt/auth.h> +#include <osmocom/gsm/kasumi.h> + +#include <stdint.h> +#include <string.h> + +/*! \brief Performs the GEA4 algorithm as in 3GPP TS 55.226 V9.0.0 + * \param[in,out] out Buffer for gamma for encrypted/decrypted + * \param[in] len Length of out, in bytes + * \param[in] kc Buffer with the ciphering key + * \param[in] iv Init vector + * \param[in] direct Direction: 0 (MS -> SGSN) or 1 (SGSN -> MS) + */ +int gea4(uint8_t *out, uint16_t len, uint8_t *kc, uint32_t iv, + enum gprs_cipher_direction direction) +{ + _kasumi_kgcore(0xFF, 0, iv, direction, kc, out, len * 8); + return 0; +} + +/*! \brief Performs the GEA3 algorithm as in 3GPP TS 55.216 V6.2.0 + * \param[in,out] out Buffer for gamma for encrypted/decrypted + * \param[in] len Length of out, in bytes + * \param[in] kc Buffer with the ciphering key + * \param[in] iv Init vector + * \param[in] direct Direction: 0 (MS -> SGSN) or 1 (SGSN -> MS) + */ +int gea3(uint8_t *out, uint16_t len, uint8_t *kc, uint32_t iv, + enum gprs_cipher_direction direction) +{ + uint8_t ck[gprs_cipher_key_length(GPRS_ALGO_GEA4)]; + osmo_c4(ck, kc); + return gea4(out, len, ck, iv, direction); +} diff --git a/src/gsm/gprs_gea.c b/src/gsm/gprs_gea.c new file mode 100644 index 00000000..8ff16484 --- /dev/null +++ b/src/gsm/gprs_gea.c @@ -0,0 +1,48 @@ +/* + * gprs_gea.c + * + * GEA 3 & 4 plugin + * + * Copyright (C) 2016 by Sysmocom s.f.m.c. GmbH + * + * All Rights Reserved + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include <osmocom/crypt/gprs_cipher.h> +#include <osmocom/gsm/gea.h> + +#include <stdint.h> + +static struct gprs_cipher_impl gea3_impl = { + .algo = GPRS_ALGO_GEA3, + .name = "GEA3 (libosmogsm built-in)", + .priority = 100, + .run = &gea3, +}; + +static struct gprs_cipher_impl gea4_impl = { + .algo = GPRS_ALGO_GEA4, + .name = "GEA4 (libosmogsm built-in)", + .priority = 100, + .run = &gea4, +}; + +static __attribute__((constructor)) void on_dso_load_gea(void) +{ + gprs_cipher_register(&gea3_impl); + gprs_cipher_register(&gea4_impl); +} |