blob: 5756bb08cfe446af46f38237cad602e47cfcddff [file] [log] [blame]
Max4f169502016-06-30 10:39:00 +02001/*
Harald Weltee08da972017-11-13 01:00:26 +09002 * Copyright (C) 2016 by sysmocom - s.f.m.c. GmbH
Max4f169502016-06-30 10:39:00 +02003 *
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 Weltee08da972017-11-13 01:00:26 +09008 * the Free Software Foundation; either version 2 of the License, or
Max4f169502016-06-30 10:39:00 +02009 * (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 Welte8cc27672017-10-16 16:00:36 +020029/*! \addtogroup gea
Harald Welte96e2a002017-06-12 21:44:18 +020030 * @{
Harald Welte8cc27672017-10-16 16:00:36 +020031 * Implementation of GPRS Ciphers GEA3 and GEA4.
32 * \file gea.c */
Harald Welte96e2a002017-06-12 21:44:18 +020033
Neels Hofmeyr87e45502017-06-20 00:17:59 +020034/*! Performs the GEA4 algorithm as in 3GPP TS 55.226 V9.0.0
Max4f169502016-06-30 10:39:00 +020035 * \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 */
41int 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 Hofmeyr87e45502017-06-20 00:17:59 +020048/*! Performs the GEA3 algorithm as in 3GPP TS 55.216 V6.2.0
Max4f169502016-06-30 10:39:00 +020049 * \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 */
55int 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 Welte96e2a002017-06-12 21:44:18 +020062
63/*! @} */