libosmogsm  0.11.0-dirty
Osmocom GSM library
include/osmocom/crypt/auth.h
Go to the documentation of this file.
00001 #pragma once
00002 
00007 #include <stdint.h>
00008 
00009 #include <osmocom/core/linuxlist.h>
00010 #include <osmocom/core/utils.h>
00011 
00012 #define OSMO_A5_MAX_KEY_LEN_BYTES (128/8)
00013 #define OSMO_MILENAGE_IND_BITLEN_MAX 28
00014 
00016 enum osmo_sub_auth_type {
00017         OSMO_AUTH_TYPE_NONE     = 0x00,
00018         OSMO_AUTH_TYPE_GSM      = 0x01,
00019         OSMO_AUTH_TYPE_UMTS     = 0x02,
00020 };
00021 
00022 extern const struct value_string osmo_sub_auth_type_names[];
00023 static inline const char *osmo_sub_auth_type_name(enum osmo_sub_auth_type val)
00024 { return get_value_string(osmo_sub_auth_type_names, val); }
00025 
00028 enum osmo_auth_algo {
00029         OSMO_AUTH_ALG_NONE,
00030         OSMO_AUTH_ALG_COMP128v1,
00031         OSMO_AUTH_ALG_COMP128v2,
00032         OSMO_AUTH_ALG_COMP128v3,
00033         OSMO_AUTH_ALG_XOR,
00034         OSMO_AUTH_ALG_MILENAGE,
00035         _OSMO_AUTH_ALG_NUM,
00036 };
00037 
00039 struct osmo_sub_auth_data {
00040         enum osmo_sub_auth_type type;
00041         enum osmo_auth_algo algo;
00042         union {
00043                 struct {
00044                         uint8_t opc[16]; 
00045                         uint8_t k[16];  
00046                         uint8_t amf[2];
00047                         uint64_t sqn;   
00048                         int opc_is_op;  
00049                         unsigned int ind_bitlen; 
00050                         unsigned int ind; 
00051                         uint64_t sqn_ms; 
00052                 } umts;
00053                 struct {
00054                         uint8_t ki[OSMO_A5_MAX_KEY_LEN_BYTES];  
00055                 } gsm;
00056         } u;
00057 };
00058 
00059 /* data structure describing a computed auth vector, generated by AuC */
00060 struct osmo_auth_vector {
00061         uint8_t rand[16];       
00062         uint8_t autn[16];       
00063         uint8_t ck[16];         
00064         uint8_t ik[16];         
00065         uint8_t res[16];        
00066         uint8_t res_len;        
00067         uint8_t kc[8];          
00068         uint8_t sres[4];        
00069         uint32_t auth_types;    
00070 };
00071 
00072 /* An implementation of an authentication algorithm */
00073 struct osmo_auth_impl {
00074         struct llist_head list;
00075         enum osmo_auth_algo algo; 
00076         const char *name;       
00077         unsigned int priority;  
00080         int (*gen_vec)(struct osmo_auth_vector *vec,
00081                         struct osmo_sub_auth_data *aud,
00082                         const uint8_t *_rand);
00083 
00084         /* callback for generationg auth vectors + re-sync */
00085         int (*gen_vec_auts)(struct osmo_auth_vector *vec,
00086                             struct osmo_sub_auth_data *aud,
00087                             const uint8_t *auts, const uint8_t *rand_auts,
00088                             const uint8_t *_rand);
00089 };
00090 
00091 int osmo_auth_gen_vec(struct osmo_auth_vector *vec,
00092                       struct osmo_sub_auth_data *aud, const uint8_t *_rand);
00093 
00094 int osmo_auth_gen_vec_auts(struct osmo_auth_vector *vec,
00095                            struct osmo_sub_auth_data *aud,
00096                            const uint8_t *auts, const uint8_t *rand_auts,
00097                            const uint8_t *_rand);
00098 
00099 int osmo_auth_register(struct osmo_auth_impl *impl);
00100 
00101 int osmo_auth_load(const char *path);
00102 
00103 int osmo_auth_supported(enum osmo_auth_algo algo);
00104 void osmo_c4(uint8_t *ck, const uint8_t *kc);
00105 const char *osmo_auth_alg_name(enum osmo_auth_algo alg);
00106 enum osmo_auth_algo osmo_auth_alg_parse(const char *name);
00107 
00108 void osmo_auth_c3(uint8_t kc[], const uint8_t ck[], const uint8_t ik[]);
00109 
00110 /* @} */
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines