blob: 20f0514be10c1e98cfd7904be938156908fd1893 [file] [log] [blame]
Neels Hofmeyr17518fe2017-06-20 04:35:06 +02001/*! \file gprs_cipher.h */
2
Sylvain Munaut12ba7782014-06-16 10:13:40 +02003#pragma once
Harald Welteb9ce51c2010-06-30 19:43:11 +02004
Pablo Neira Ayuso83419342011-03-22 16:36:13 +01005#include <osmocom/core/linuxlist.h>
Maxb897c422016-06-28 14:03:21 +02006#include <osmocom/core/utils.h>
Harald Welteb9ce51c2010-06-30 19:43:11 +02007
Max4f169502016-06-30 10:39:00 +02008#include <stdint.h>
9
Harald Welteb9ce51c2010-06-30 19:43:11 +020010#define GSM0464_CIPH_MAX_BLOCK 1523
11
Maxdda9dff2016-06-28 17:05:35 +020012/* 3GPP TS 24.008 ยง 10.5.5.3 */
Harald Welteb9ce51c2010-06-30 19:43:11 +020013enum gprs_ciph_algo {
Maxdda9dff2016-06-28 17:05:35 +020014 GPRS_ALGO_GEA0 = 0,
15 GPRS_ALGO_GEA1 = 1,
16 GPRS_ALGO_GEA2 = 2,
17 GPRS_ALGO_GEA3 = 3,
18 GPRS_ALGO_GEA4 = 4,
Harald Welteb9ce51c2010-06-30 19:43:11 +020019 _GPRS_ALGO_NUM
20};
21
Maxc57e5da2016-06-27 16:19:12 +020022/* 3GPP TS 04.64 Table A.1: */
Harald Welteb9ce51c2010-06-30 19:43:11 +020023enum gprs_cipher_direction {
Maxc57e5da2016-06-27 16:19:12 +020024 GPRS_CIPH_MS2SGSN = 0,
25 GPRS_CIPH_SGSN2MS = 1,
Harald Welteb9ce51c2010-06-30 19:43:11 +020026};
27
Maxb897c422016-06-28 14:03:21 +020028extern const struct value_string gprs_cipher_names[];
29
Harald Welteb9ce51c2010-06-30 19:43:11 +020030/* An implementation of a GPRS cipher */
31struct gprs_cipher_impl {
32 struct llist_head list;
33 enum gprs_ciph_algo algo;
34 const char *name;
35 unsigned int priority;
36
37 /* As specified in 04.64 Annex A. Uses Kc, IV and direction
38 * to generate the 1523 bytes cipher stream that need to be
39 * XORed wit the plaintext for encrypt / ciphertext for decrypt */
Maxbf990bb2016-04-21 14:46:30 +020040 int (*run)(uint8_t *out, uint16_t len, uint8_t *kc, uint32_t iv,
Harald Welteb9ce51c2010-06-30 19:43:11 +020041 enum gprs_cipher_direction direction);
42};
43
44/* register a cipher with the core (from a plugin) */
45int gprs_cipher_register(struct gprs_cipher_impl *ciph);
46
47/* load all available GPRS cipher plugins */
48int gprs_cipher_load(const char *path);
49
50/* function to be called by core code */
51int gprs_cipher_run(uint8_t *out, uint16_t len, enum gprs_ciph_algo algo,
Maxbf990bb2016-04-21 14:46:30 +020052 uint8_t *kc, uint32_t iv, enum gprs_cipher_direction dir);
Harald Welteb9ce51c2010-06-30 19:43:11 +020053
54/* Do we have an implementation for this cipher? */
55int gprs_cipher_supported(enum gprs_ciph_algo algo);
56
Maxbf990bb2016-04-21 14:46:30 +020057/* Return key length for supported cipher, in bytes */
58unsigned gprs_cipher_key_length(enum gprs_ciph_algo algo);
59
Harald Weltee335b912010-06-30 19:50:14 +020060/* GSM TS 04.64 / Section A.2.1 : Generation of 'input' */
61uint32_t gprs_cipher_gen_input_ui(uint32_t iov_ui, uint8_t sapi, uint32_t lfn, uint32_t oc);
62
63/* GSM TS 04.64 / Section A.2.1 : Generation of 'input' */
64uint32_t gprs_cipher_gen_input_i(uint32_t iov_i, uint32_t lfn, uint32_t oc);