libosmogsm 1.13.1.1-afb4 Osmocom GSM library

gprs_cipher.h
Go to the documentation of this file.
1
3#pragma once
4
5#include <osmocom/core/linuxlist.h>
6#include <osmocom/core/utils.h>
7
8#include <stdint.h>
9
10#define GSM0464_CIPH_MAX_BLOCK 1523
11
12/* 3GPP TS 24.008 § 10.5.5.3 */
13 enum gprs_ciph_algo {
14 GPRS_ALGO_GEA0 = 0,
15 GPRS_ALGO_GEA1 = 1,
16 GPRS_ALGO_GEA2 = 2,
17 GPRS_ALGO_GEA3 = 3,
18 GPRS_ALGO_GEA4 = 4,
19 _GPRS_ALGO_NUM
20};
21
22/* 3GPP TS 04.64 Table A.1: */
23 enum gprs_cipher_direction {
24 GPRS_CIPH_MS2SGSN = 0,
25 GPRS_CIPH_SGSN2MS = 1,
26};
27
28 extern const struct value_string gprs_cipher_names[];
29
30/* An implementation of a GPRS cipher */
31 struct 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 */
40 int (*run)(uint8_t *out, uint16_t len, uint8_t *kc, uint32_t iv,
41 enum gprs_cipher_direction direction);
42};
43
44/* register a cipher with the core (from a plugin) */
45 int gprs_cipher_register(struct gprs_cipher_impl *ciph);
46
47/* load all available GPRS cipher plugins */
48 int gprs_cipher_load(const char *path);
49
50/* function to be called by core code */
51 int gprs_cipher_run(uint8_t *out, uint16_t len, enum gprs_ciph_algo algo,
52 uint8_t *kc, uint32_t iv, enum gprs_cipher_direction dir);
53
54/* Do we have an implementation for this cipher? */
55 int gprs_cipher_supported(enum gprs_ciph_algo algo);
56
57/* Return key length for supported cipher, in bytes */
58 unsigned gprs_cipher_key_length(enum gprs_ciph_algo algo);
59
60/* 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);
gprs_ciph_algo
gprs_ciph_algo
Definition: gprs_cipher.h:13
GPRS_ALGO_GEA1
@ GPRS_ALGO_GEA1
Definition: gprs_cipher.h:15
GPRS_ALGO_GEA3
@ GPRS_ALGO_GEA3
Definition: gprs_cipher.h:17
_GPRS_ALGO_NUM
@ _GPRS_ALGO_NUM
Definition: gprs_cipher.h:19
GPRS_ALGO_GEA4
@ GPRS_ALGO_GEA4
Definition: gprs_cipher.h:18
GPRS_ALGO_GEA2
@ GPRS_ALGO_GEA2
Definition: gprs_cipher.h:16
GPRS_ALGO_GEA0
@ GPRS_ALGO_GEA0
Definition: gprs_cipher.h:14
gprs_cipher_direction
gprs_cipher_direction
Definition: gprs_cipher.h:23
GPRS_CIPH_MS2SGSN
@ GPRS_CIPH_MS2SGSN
Definition: gprs_cipher.h:24
GPRS_CIPH_SGSN2MS
@ GPRS_CIPH_SGSN2MS
Definition: gprs_cipher.h:25
gprs_cipher_gen_input_ui
uint32_t gprs_cipher_gen_input_ui(uint32_t iov_ui, uint8_t sapi, uint32_t lfn, uint32_t oc)
Definition: gprs_cipher_core.c:123
gprs_cipher_key_length
unsigned gprs_cipher_key_length(enum gprs_ciph_algo algo)
Obtain key lenght for given GPRS cipher.
Definition: gprs_cipher_core.c:99
gprs_cipher_run
int gprs_cipher_run(uint8_t *out, uint16_t len, enum gprs_ciph_algo algo, uint8_t *kc, uint32_t iv, enum gprs_cipher_direction dir)
Definition: gprs_cipher_core.c:78
gprs_cipher_supported
int gprs_cipher_supported(enum gprs_ciph_algo algo)
Definition: gprs_cipher_core.c:111
gprs_cipher_names
const struct value_string gprs_cipher_names[]
Definition: gprs_cipher_core.c:41
gprs_cipher_register
int gprs_cipher_register(struct gprs_cipher_impl *ciph)
Definition: gprs_cipher_core.c:51
gprs_cipher_load
int gprs_cipher_load(const char *path)
Definition: gprs_cipher_core.c:67
gprs_cipher_gen_input_i
uint32_t gprs_cipher_gen_input_i(uint32_t iov_i, uint32_t lfn, uint32_t oc)
Definition: gprs_cipher_core.c:131
len
uint8_t len
Definition: gsm_04_11.h:0
linuxlist.h
gprs_cipher_impl
Definition: gprs_cipher.h:31
gprs_cipher_impl::algo
enum gprs_ciph_algo algo
Definition: gprs_cipher.h:33
gprs_cipher_impl::priority
unsigned int priority
Definition: gprs_cipher.h:35
gprs_cipher_impl::run
int(* run)(uint8_t *out, uint16_t len, uint8_t *kc, uint32_t iv, enum gprs_cipher_direction direction)
Definition: gprs_cipher.h:40
gprs_cipher_impl::list
struct llist_head list
Definition: gprs_cipher.h:32
gprs_cipher_impl::name
const char * name
Definition: gprs_cipher.h:34
llist_head
value_string
utils.h