blob: 2639293cc3818c219c6fc310969ca112cd3f2f3c [file] [log] [blame]
Sylvain Munaut12ba7782014-06-16 10:13:40 +02001#pragma once
Harald Welteb9ce51c2010-06-30 19:43:11 +02002
Pablo Neira Ayuso83419342011-03-22 16:36:13 +01003#include <osmocom/core/linuxlist.h>
Maxb897c422016-06-28 14:03:21 +02004#include <osmocom/core/utils.h>
Harald Welteb9ce51c2010-06-30 19:43:11 +02005
6#define GSM0464_CIPH_MAX_BLOCK 1523
7
8enum gprs_ciph_algo {
9 GPRS_ALGO_GEA0,
10 GPRS_ALGO_GEA1,
11 GPRS_ALGO_GEA2,
12 GPRS_ALGO_GEA3,
Maxbf990bb2016-04-21 14:46:30 +020013 GPRS_ALGO_GEA4,
Harald Welteb9ce51c2010-06-30 19:43:11 +020014 _GPRS_ALGO_NUM
15};
16
Maxc57e5da2016-06-27 16:19:12 +020017/* 3GPP TS 04.64 Table A.1: */
Harald Welteb9ce51c2010-06-30 19:43:11 +020018enum gprs_cipher_direction {
Maxc57e5da2016-06-27 16:19:12 +020019 GPRS_CIPH_MS2SGSN = 0,
20 GPRS_CIPH_SGSN2MS = 1,
Harald Welteb9ce51c2010-06-30 19:43:11 +020021};
22
Maxb897c422016-06-28 14:03:21 +020023extern const struct value_string gprs_cipher_names[];
24
Harald Welteb9ce51c2010-06-30 19:43:11 +020025/* An implementation of a GPRS cipher */
26struct gprs_cipher_impl {
27 struct llist_head list;
28 enum gprs_ciph_algo algo;
29 const char *name;
30 unsigned int priority;
31
32 /* As specified in 04.64 Annex A. Uses Kc, IV and direction
33 * to generate the 1523 bytes cipher stream that need to be
34 * XORed wit the plaintext for encrypt / ciphertext for decrypt */
Maxbf990bb2016-04-21 14:46:30 +020035 int (*run)(uint8_t *out, uint16_t len, uint8_t *kc, uint32_t iv,
Harald Welteb9ce51c2010-06-30 19:43:11 +020036 enum gprs_cipher_direction direction);
37};
38
39/* register a cipher with the core (from a plugin) */
40int gprs_cipher_register(struct gprs_cipher_impl *ciph);
41
42/* load all available GPRS cipher plugins */
43int gprs_cipher_load(const char *path);
44
45/* function to be called by core code */
46int gprs_cipher_run(uint8_t *out, uint16_t len, enum gprs_ciph_algo algo,
Maxbf990bb2016-04-21 14:46:30 +020047 uint8_t *kc, uint32_t iv, enum gprs_cipher_direction dir);
Harald Welteb9ce51c2010-06-30 19:43:11 +020048
49/* Do we have an implementation for this cipher? */
50int gprs_cipher_supported(enum gprs_ciph_algo algo);
51
Maxbf990bb2016-04-21 14:46:30 +020052/* Return key length for supported cipher, in bytes */
53unsigned gprs_cipher_key_length(enum gprs_ciph_algo algo);
54
Harald Weltee335b912010-06-30 19:50:14 +020055/* GSM TS 04.64 / Section A.2.1 : Generation of 'input' */
56uint32_t gprs_cipher_gen_input_ui(uint32_t iov_ui, uint8_t sapi, uint32_t lfn, uint32_t oc);
57
58/* GSM TS 04.64 / Section A.2.1 : Generation of 'input' */
59uint32_t gprs_cipher_gen_input_i(uint32_t iov_i, uint32_t lfn, uint32_t oc);