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