Harald Welte | d82e0eb | 2011-12-06 21:53:42 +0100 | [diff] [blame] | 1 | #ifndef _OSMOCRYPTO_AUTH_H |
| 2 | #define _OSMOCRYPTO_AUTH_H |
| 3 | |
| 4 | #include <stdint.h> |
| 5 | |
| 6 | #include <osmocom/core/linuxlist.h> |
| 7 | |
| 8 | /*! \brief Authentication Type */ |
| 9 | enum osmo_sub_auth_type { |
| 10 | OSMO_AUTH_TYPE_NONE = 0x00, |
| 11 | OSMO_AUTH_TYPE_GSM = 0x01, |
| 12 | OSMO_AUTH_TYPE_UMTS = 0x02, |
| 13 | }; |
| 14 | |
| 15 | /*! \brief Authentication Algorithm */ |
| 16 | enum osmo_auth_algo { |
| 17 | OSMO_AUTH_ALG_NONE, |
| 18 | OSMO_AUTH_ALG_COMP128v1, |
| 19 | OSMO_AUTH_ALG_COMP128v2, |
| 20 | OSMO_AUTH_ALG_COMP128v3, |
| 21 | OSMO_AUTH_ALG_XOR, |
| 22 | OSMO_AUTH_ALG_MILENAGE, |
| 23 | _OSMO_AUTH_ALG_NUM, |
| 24 | }; |
| 25 | |
| 26 | /*! \brief permanent (secret) subscriber auth data */ |
| 27 | struct osmo_sub_auth_data { |
| 28 | enum osmo_sub_auth_type type; |
| 29 | enum osmo_auth_algo algo; |
| 30 | union { |
| 31 | struct { |
| 32 | uint8_t opc[16]; |
| 33 | uint8_t k[16]; |
| 34 | uint8_t amf[2]; |
| 35 | uint64_t sqn; |
Harald Welte | a72e47b | 2012-03-21 09:03:16 +0100 | [diff] [blame] | 36 | int opc_is_op; |
Harald Welte | d82e0eb | 2011-12-06 21:53:42 +0100 | [diff] [blame] | 37 | } umts; |
| 38 | struct { |
| 39 | uint8_t ki[16]; |
| 40 | } gsm; |
Harald Welte | aae2362 | 2011-12-07 11:35:02 +0100 | [diff] [blame] | 41 | } u; |
Harald Welte | d82e0eb | 2011-12-06 21:53:42 +0100 | [diff] [blame] | 42 | }; |
| 43 | |
| 44 | /* data structure describing a computed auth vector, generated by AuC */ |
| 45 | struct osmo_auth_vector { |
| 46 | uint8_t rand[16]; |
| 47 | uint8_t autn[16]; |
| 48 | uint8_t ck[16]; |
| 49 | uint8_t ik[16]; |
| 50 | uint8_t res[16]; |
| 51 | uint8_t res_len; |
| 52 | uint8_t kc[8]; |
| 53 | uint8_t sres[4]; |
| 54 | uint32_t auth_types; /*!< bitmask of OSMO_AUTH_TYPE_* */ |
| 55 | }; |
| 56 | |
| 57 | /* \brief An implementation of an authentication algorithm */ |
| 58 | struct osmo_auth_impl { |
| 59 | struct llist_head list; |
| 60 | enum osmo_auth_algo algo; |
| 61 | const char *name; |
| 62 | unsigned int priority; |
| 63 | |
| 64 | int (*gen_vec)(struct osmo_auth_vector *vec, |
| 65 | struct osmo_sub_auth_data *aud, |
| 66 | const uint8_t *_rand); |
| 67 | |
| 68 | int (*gen_vec_auts)(struct osmo_auth_vector *vec, |
| 69 | struct osmo_sub_auth_data *aud, |
| 70 | const uint8_t *rand_auts, const uint8_t *auts, |
| 71 | const uint8_t *_rand); |
| 72 | }; |
| 73 | |
| 74 | int osmo_auth_gen_vec(struct osmo_auth_vector *vec, |
| 75 | struct osmo_sub_auth_data *aud, const uint8_t *_rand); |
| 76 | |
| 77 | int osmo_auth_gen_vec_auts(struct osmo_auth_vector *vec, |
| 78 | struct osmo_sub_auth_data *aud, |
| 79 | const uint8_t *rand_auts, const uint8_t *auts, |
| 80 | const uint8_t *_rand); |
| 81 | |
| 82 | int osmo_auth_register(struct osmo_auth_impl *impl); |
| 83 | |
| 84 | int osmo_auth_load(const char *path); |
| 85 | |
| 86 | int osmo_auth_supported(enum osmo_auth_algo algo); |
| 87 | |
Harald Welte | a5ab162 | 2011-12-07 02:33:11 +0100 | [diff] [blame] | 88 | const char *osmo_auth_alg_name(enum osmo_auth_algo alg); |
| 89 | enum osmo_auth_algo osmo_auth_alg_parse(const char *name); |
| 90 | |
Harald Welte | d82e0eb | 2011-12-06 21:53:42 +0100 | [diff] [blame] | 91 | #endif /* _OSMOCRYPTO_AUTH_H */ |