blob: aedc898e9331bc998486749dac85e6e0fb5d71e9 [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.
Max4f169502016-06-30 10:39:00 +020015 */
16
17#include <osmocom/core/bits.h>
18#include <osmocom/crypt/gprs_cipher.h>
19#include <osmocom/crypt/auth.h>
20#include <osmocom/gsm/kasumi.h>
21
22#include <stdint.h>
23#include <string.h>
24
Harald Welte8cc27672017-10-16 16:00:36 +020025/*! \addtogroup gea
Harald Welte96e2a002017-06-12 21:44:18 +020026 * @{
Harald Welte8cc27672017-10-16 16:00:36 +020027 * Implementation of GPRS Ciphers GEA3 and GEA4.
28 * \file gea.c */
Harald Welte96e2a002017-06-12 21:44:18 +020029
Neels Hofmeyr87e45502017-06-20 00:17:59 +020030/*! Performs the GEA4 algorithm as in 3GPP TS 55.226 V9.0.0
Max4f169502016-06-30 10:39:00 +020031 * \param[in,out] out Buffer for gamma for encrypted/decrypted
32 * \param[in] len Length of out, in bytes
33 * \param[in] kc Buffer with the ciphering key
34 * \param[in] iv Init vector
35 * \param[in] direct Direction: 0 (MS -> SGSN) or 1 (SGSN -> MS)
36 */
37int gea4(uint8_t *out, uint16_t len, uint8_t *kc, uint32_t iv,
38 enum gprs_cipher_direction direction)
39{
40 _kasumi_kgcore(0xFF, 0, iv, direction, kc, out, len * 8);
41 return 0;
42}
43
Neels Hofmeyr87e45502017-06-20 00:17:59 +020044/*! Performs the GEA3 algorithm as in 3GPP TS 55.216 V6.2.0
Max4f169502016-06-30 10:39:00 +020045 * \param[in,out] out Buffer for gamma for encrypted/decrypted
46 * \param[in] len Length of out, in bytes
47 * \param[in] kc Buffer with the ciphering key
48 * \param[in] iv Init vector
49 * \param[in] direct Direction: 0 (MS -> SGSN) or 1 (SGSN -> MS)
50 */
51int gea3(uint8_t *out, uint16_t len, uint8_t *kc, uint32_t iv,
52 enum gprs_cipher_direction direction)
53{
54 uint8_t ck[gprs_cipher_key_length(GPRS_ALGO_GEA4)];
55 osmo_c4(ck, kc);
56 return gea4(out, len, ck, iv, direction);
57}
Harald Welte96e2a002017-06-12 21:44:18 +020058
59/*! @} */