libosmogsm
0.11.0-dirty
Osmocom GSM library
|
00001 00003 #pragma once 00004 00005 #include <osmocom/core/linuxlist.h> 00006 #include <osmocom/core/utils.h> 00007 00008 #include <stdint.h> 00009 00010 #define GSM0464_CIPH_MAX_BLOCK 1523 00011 00012 /* 3GPP TS 24.008 ยง 10.5.5.3 */ 00013 enum gprs_ciph_algo { 00014 GPRS_ALGO_GEA0 = 0, 00015 GPRS_ALGO_GEA1 = 1, 00016 GPRS_ALGO_GEA2 = 2, 00017 GPRS_ALGO_GEA3 = 3, 00018 GPRS_ALGO_GEA4 = 4, 00019 _GPRS_ALGO_NUM 00020 }; 00021 00022 /* 3GPP TS 04.64 Table A.1: */ 00023 enum gprs_cipher_direction { 00024 GPRS_CIPH_MS2SGSN = 0, 00025 GPRS_CIPH_SGSN2MS = 1, 00026 }; 00027 00028 extern const struct value_string gprs_cipher_names[]; 00029 00030 /* An implementation of a GPRS cipher */ 00031 struct gprs_cipher_impl { 00032 struct llist_head list; 00033 enum gprs_ciph_algo algo; 00034 const char *name; 00035 unsigned int priority; 00036 00037 /* As specified in 04.64 Annex A. Uses Kc, IV and direction 00038 * to generate the 1523 bytes cipher stream that need to be 00039 * XORed wit the plaintext for encrypt / ciphertext for decrypt */ 00040 int (*run)(uint8_t *out, uint16_t len, uint8_t *kc, uint32_t iv, 00041 enum gprs_cipher_direction direction); 00042 }; 00043 00044 /* register a cipher with the core (from a plugin) */ 00045 int gprs_cipher_register(struct gprs_cipher_impl *ciph); 00046 00047 /* load all available GPRS cipher plugins */ 00048 int gprs_cipher_load(const char *path); 00049 00050 /* function to be called by core code */ 00051 int gprs_cipher_run(uint8_t *out, uint16_t len, enum gprs_ciph_algo algo, 00052 uint8_t *kc, uint32_t iv, enum gprs_cipher_direction dir); 00053 00054 /* Do we have an implementation for this cipher? */ 00055 int gprs_cipher_supported(enum gprs_ciph_algo algo); 00056 00057 /* Return key length for supported cipher, in bytes */ 00058 unsigned gprs_cipher_key_length(enum gprs_ciph_algo algo); 00059 00060 /* GSM TS 04.64 / Section A.2.1 : Generation of 'input' */ 00061 uint32_t gprs_cipher_gen_input_ui(uint32_t iov_ui, uint8_t sapi, uint32_t lfn, uint32_t oc); 00062 00063 /* GSM TS 04.64 / Section A.2.1 : Generation of 'input' */ 00064 uint32_t gprs_cipher_gen_input_i(uint32_t iov_i, uint32_t lfn, uint32_t oc);