blob: 940b07b13e818981a692c54e8968d4d1ef83f7ea [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>
Harald Welteb9ce51c2010-06-30 19:43:11 +02004
5#define GSM0464_CIPH_MAX_BLOCK 1523
6
7enum gprs_ciph_algo {
8 GPRS_ALGO_GEA0,
9 GPRS_ALGO_GEA1,
10 GPRS_ALGO_GEA2,
11 GPRS_ALGO_GEA3,
12 _GPRS_ALGO_NUM
13};
14
15enum gprs_cipher_direction {
16 GPRS_CIPH_MS2SGSN,
17 GPRS_CIPH_SGSN2MS,
18};
19
20/* An implementation of a GPRS cipher */
21struct gprs_cipher_impl {
22 struct llist_head list;
23 enum gprs_ciph_algo algo;
24 const char *name;
25 unsigned int priority;
26
27 /* As specified in 04.64 Annex A. Uses Kc, IV and direction
28 * to generate the 1523 bytes cipher stream that need to be
29 * XORed wit the plaintext for encrypt / ciphertext for decrypt */
30 int (*run)(uint8_t *out, uint16_t len, uint64_t kc, uint32_t iv,
31 enum gprs_cipher_direction direction);
32};
33
34/* register a cipher with the core (from a plugin) */
35int gprs_cipher_register(struct gprs_cipher_impl *ciph);
36
37/* load all available GPRS cipher plugins */
38int gprs_cipher_load(const char *path);
39
40/* function to be called by core code */
41int gprs_cipher_run(uint8_t *out, uint16_t len, enum gprs_ciph_algo algo,
42 uint64_t kc, uint32_t iv, enum gprs_cipher_direction dir);
43
44/* Do we have an implementation for this cipher? */
45int gprs_cipher_supported(enum gprs_ciph_algo algo);
46
Harald Weltee335b912010-06-30 19:50:14 +020047/* GSM TS 04.64 / Section A.2.1 : Generation of 'input' */
48uint32_t gprs_cipher_gen_input_ui(uint32_t iov_ui, uint8_t sapi, uint32_t lfn, uint32_t oc);
49
50/* GSM TS 04.64 / Section A.2.1 : Generation of 'input' */
51uint32_t gprs_cipher_gen_input_i(uint32_t iov_i, uint32_t lfn, uint32_t oc);