Max | 4f16950 | 2016-06-30 10:39:00 +0200 | [diff] [blame] | 1 | /* |
Harald Welte | e08da97 | 2017-11-13 01:00:26 +0900 | [diff] [blame] | 2 | * Copyright (C) 2016 by sysmocom - s.f.m.c. GmbH |
Max | 4f16950 | 2016-06-30 10:39:00 +0200 | [diff] [blame] | 3 | * |
| 4 | * All Rights Reserved |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
Harald Welte | e08da97 | 2017-11-13 01:00:26 +0900 | [diff] [blame] | 8 | * the Free Software Foundation; either version 2 of the License, or |
Max | 4f16950 | 2016-06-30 10:39:00 +0200 | [diff] [blame] | 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along |
| 17 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 | */ |
| 20 | |
| 21 | #include <osmocom/core/bits.h> |
| 22 | #include <osmocom/crypt/gprs_cipher.h> |
| 23 | #include <osmocom/crypt/auth.h> |
| 24 | #include <osmocom/gsm/kasumi.h> |
| 25 | |
| 26 | #include <stdint.h> |
| 27 | #include <string.h> |
| 28 | |
Harald Welte | 8cc2767 | 2017-10-16 16:00:36 +0200 | [diff] [blame] | 29 | /*! \addtogroup gea |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 30 | * @{ |
Harald Welte | 8cc2767 | 2017-10-16 16:00:36 +0200 | [diff] [blame] | 31 | * Implementation of GPRS Ciphers GEA3 and GEA4. |
| 32 | * \file gea.c */ |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 33 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 34 | /*! Performs the GEA4 algorithm as in 3GPP TS 55.226 V9.0.0 |
Max | 4f16950 | 2016-06-30 10:39:00 +0200 | [diff] [blame] | 35 | * \param[in,out] out Buffer for gamma for encrypted/decrypted |
| 36 | * \param[in] len Length of out, in bytes |
| 37 | * \param[in] kc Buffer with the ciphering key |
| 38 | * \param[in] iv Init vector |
| 39 | * \param[in] direct Direction: 0 (MS -> SGSN) or 1 (SGSN -> MS) |
| 40 | */ |
| 41 | int gea4(uint8_t *out, uint16_t len, uint8_t *kc, uint32_t iv, |
| 42 | enum gprs_cipher_direction direction) |
| 43 | { |
| 44 | _kasumi_kgcore(0xFF, 0, iv, direction, kc, out, len * 8); |
| 45 | return 0; |
| 46 | } |
| 47 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 48 | /*! Performs the GEA3 algorithm as in 3GPP TS 55.216 V6.2.0 |
Max | 4f16950 | 2016-06-30 10:39:00 +0200 | [diff] [blame] | 49 | * \param[in,out] out Buffer for gamma for encrypted/decrypted |
| 50 | * \param[in] len Length of out, in bytes |
| 51 | * \param[in] kc Buffer with the ciphering key |
| 52 | * \param[in] iv Init vector |
| 53 | * \param[in] direct Direction: 0 (MS -> SGSN) or 1 (SGSN -> MS) |
| 54 | */ |
| 55 | int gea3(uint8_t *out, uint16_t len, uint8_t *kc, uint32_t iv, |
| 56 | enum gprs_cipher_direction direction) |
| 57 | { |
| 58 | uint8_t ck[gprs_cipher_key_length(GPRS_ALGO_GEA4)]; |
| 59 | osmo_c4(ck, kc); |
| 60 | return gea4(out, len, ck, iv, direction); |
| 61 | } |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 62 | |
| 63 | /*! @} */ |