Sylvain Munaut | 12ba778 | 2014-06-16 10:13:40 +0200 | [diff] [blame] | 1 | #pragma once |
Harald Welte | b9ce51c | 2010-06-30 19:43:11 +0200 | [diff] [blame] | 2 | |
Pablo Neira Ayuso | 8341934 | 2011-03-22 16:36:13 +0100 | [diff] [blame] | 3 | #include <osmocom/core/linuxlist.h> |
Harald Welte | b9ce51c | 2010-06-30 19:43:11 +0200 | [diff] [blame] | 4 | |
| 5 | #define GSM0464_CIPH_MAX_BLOCK 1523 |
| 6 | |
| 7 | enum gprs_ciph_algo { |
| 8 | GPRS_ALGO_GEA0, |
| 9 | GPRS_ALGO_GEA1, |
| 10 | GPRS_ALGO_GEA2, |
| 11 | GPRS_ALGO_GEA3, |
Max | bf990bb | 2016-04-21 14:46:30 +0200 | [diff] [blame] | 12 | GPRS_ALGO_GEA4, |
Harald Welte | b9ce51c | 2010-06-30 19:43:11 +0200 | [diff] [blame] | 13 | _GPRS_ALGO_NUM |
| 14 | }; |
| 15 | |
| 16 | enum gprs_cipher_direction { |
| 17 | GPRS_CIPH_MS2SGSN, |
| 18 | GPRS_CIPH_SGSN2MS, |
| 19 | }; |
| 20 | |
| 21 | /* An implementation of a GPRS cipher */ |
| 22 | struct gprs_cipher_impl { |
| 23 | struct llist_head list; |
| 24 | enum gprs_ciph_algo algo; |
| 25 | const char *name; |
| 26 | unsigned int priority; |
| 27 | |
| 28 | /* As specified in 04.64 Annex A. Uses Kc, IV and direction |
| 29 | * to generate the 1523 bytes cipher stream that need to be |
| 30 | * XORed wit the plaintext for encrypt / ciphertext for decrypt */ |
Max | bf990bb | 2016-04-21 14:46:30 +0200 | [diff] [blame] | 31 | int (*run)(uint8_t *out, uint16_t len, uint8_t *kc, uint32_t iv, |
Harald Welte | b9ce51c | 2010-06-30 19:43:11 +0200 | [diff] [blame] | 32 | enum gprs_cipher_direction direction); |
| 33 | }; |
| 34 | |
| 35 | /* register a cipher with the core (from a plugin) */ |
| 36 | int gprs_cipher_register(struct gprs_cipher_impl *ciph); |
| 37 | |
| 38 | /* load all available GPRS cipher plugins */ |
| 39 | int gprs_cipher_load(const char *path); |
| 40 | |
| 41 | /* function to be called by core code */ |
| 42 | int gprs_cipher_run(uint8_t *out, uint16_t len, enum gprs_ciph_algo algo, |
Max | bf990bb | 2016-04-21 14:46:30 +0200 | [diff] [blame] | 43 | uint8_t *kc, uint32_t iv, enum gprs_cipher_direction dir); |
Harald Welte | b9ce51c | 2010-06-30 19:43:11 +0200 | [diff] [blame] | 44 | |
| 45 | /* Do we have an implementation for this cipher? */ |
| 46 | int gprs_cipher_supported(enum gprs_ciph_algo algo); |
| 47 | |
Max | bf990bb | 2016-04-21 14:46:30 +0200 | [diff] [blame] | 48 | /* Return key length for supported cipher, in bytes */ |
| 49 | unsigned gprs_cipher_key_length(enum gprs_ciph_algo algo); |
| 50 | |
Harald Welte | e335b91 | 2010-06-30 19:50:14 +0200 | [diff] [blame] | 51 | /* GSM TS 04.64 / Section A.2.1 : Generation of 'input' */ |
| 52 | uint32_t gprs_cipher_gen_input_ui(uint32_t iov_ui, uint8_t sapi, uint32_t lfn, uint32_t oc); |
| 53 | |
| 54 | /* GSM TS 04.64 / Section A.2.1 : Generation of 'input' */ |
| 55 | uint32_t gprs_cipher_gen_input_i(uint32_t iov_i, uint32_t lfn, uint32_t oc); |