Sylvain Munaut | 12ba778 | 2014-06-16 10:13:40 +0200 | [diff] [blame] | 1 | #pragma once |
Harald Welte | d82e0eb | 2011-12-06 21:53:42 +0100 | [diff] [blame] | 2 | |
Harald Welte | 007a71e | 2012-07-18 19:47:56 +0200 | [diff] [blame] | 3 | /*! \addtogroup auth |
| 4 | * @{ |
| 5 | */ |
| 6 | |
| 7 | /*! \file auth.h */ |
| 8 | |
Harald Welte | d82e0eb | 2011-12-06 21:53:42 +0100 | [diff] [blame] | 9 | #include <stdint.h> |
| 10 | |
| 11 | #include <osmocom/core/linuxlist.h> |
| 12 | |
Harald Welte | 007a71e | 2012-07-18 19:47:56 +0200 | [diff] [blame] | 13 | /*! \brief Authentication Type (GSM/UMTS) */ |
Harald Welte | d82e0eb | 2011-12-06 21:53:42 +0100 | [diff] [blame] | 14 | enum osmo_sub_auth_type { |
| 15 | OSMO_AUTH_TYPE_NONE = 0x00, |
| 16 | OSMO_AUTH_TYPE_GSM = 0x01, |
| 17 | OSMO_AUTH_TYPE_UMTS = 0x02, |
| 18 | }; |
| 19 | |
| 20 | /*! \brief Authentication Algorithm */ |
| 21 | enum osmo_auth_algo { |
| 22 | OSMO_AUTH_ALG_NONE, |
| 23 | OSMO_AUTH_ALG_COMP128v1, |
| 24 | OSMO_AUTH_ALG_COMP128v2, |
| 25 | OSMO_AUTH_ALG_COMP128v3, |
| 26 | OSMO_AUTH_ALG_XOR, |
| 27 | OSMO_AUTH_ALG_MILENAGE, |
| 28 | _OSMO_AUTH_ALG_NUM, |
| 29 | }; |
| 30 | |
| 31 | /*! \brief permanent (secret) subscriber auth data */ |
| 32 | struct osmo_sub_auth_data { |
| 33 | enum osmo_sub_auth_type type; |
| 34 | enum osmo_auth_algo algo; |
| 35 | union { |
| 36 | struct { |
Harald Welte | 007a71e | 2012-07-18 19:47:56 +0200 | [diff] [blame] | 37 | uint8_t opc[16]; /*!< operator invariant value */ |
| 38 | uint8_t k[16]; /*!< secret key of the subscriber */ |
Harald Welte | d82e0eb | 2011-12-06 21:53:42 +0100 | [diff] [blame] | 39 | uint8_t amf[2]; |
Harald Welte | 007a71e | 2012-07-18 19:47:56 +0200 | [diff] [blame] | 40 | uint64_t sqn; /*!< sequence number */ |
| 41 | int opc_is_op; /*!< is the OPC field OPC (0) or OP (1) ? */ |
Harald Welte | d82e0eb | 2011-12-06 21:53:42 +0100 | [diff] [blame] | 42 | } umts; |
| 43 | struct { |
Harald Welte | 007a71e | 2012-07-18 19:47:56 +0200 | [diff] [blame] | 44 | uint8_t ki[16]; /*!< secret key */ |
Harald Welte | d82e0eb | 2011-12-06 21:53:42 +0100 | [diff] [blame] | 45 | } gsm; |
Harald Welte | aae2362 | 2011-12-07 11:35:02 +0100 | [diff] [blame] | 46 | } u; |
Harald Welte | d82e0eb | 2011-12-06 21:53:42 +0100 | [diff] [blame] | 47 | }; |
| 48 | |
| 49 | /* data structure describing a computed auth vector, generated by AuC */ |
| 50 | struct osmo_auth_vector { |
Harald Welte | 007a71e | 2012-07-18 19:47:56 +0200 | [diff] [blame] | 51 | uint8_t rand[16]; /*!< random challenge */ |
| 52 | uint8_t autn[16]; /*!< authentication nonce */ |
| 53 | uint8_t ck[16]; /*!< ciphering key */ |
| 54 | uint8_t ik[16]; /*!< integrity key */ |
| 55 | uint8_t res[16]; /*!< authentication result */ |
| 56 | uint8_t res_len; /*!< length (in bytes) of res */ |
| 57 | uint8_t kc[8]; /*!< Kc for GSM encryption (A5) */ |
| 58 | uint8_t sres[4]; /*!< authentication result for GSM */ |
Harald Welte | d82e0eb | 2011-12-06 21:53:42 +0100 | [diff] [blame] | 59 | uint32_t auth_types; /*!< bitmask of OSMO_AUTH_TYPE_* */ |
| 60 | }; |
| 61 | |
| 62 | /* \brief An implementation of an authentication algorithm */ |
| 63 | struct osmo_auth_impl { |
| 64 | struct llist_head list; |
Harald Welte | 007a71e | 2012-07-18 19:47:56 +0200 | [diff] [blame] | 65 | enum osmo_auth_algo algo; /*!< algorithm we implement */ |
| 66 | const char *name; /*!< name of the implementation */ |
| 67 | unsigned int priority; /*!< priority value (resp. othe implementations */ |
Harald Welte | d82e0eb | 2011-12-06 21:53:42 +0100 | [diff] [blame] | 68 | |
Harald Welte | 007a71e | 2012-07-18 19:47:56 +0200 | [diff] [blame] | 69 | /*! \brief callback for generate authentication vectors */ |
Harald Welte | d82e0eb | 2011-12-06 21:53:42 +0100 | [diff] [blame] | 70 | int (*gen_vec)(struct osmo_auth_vector *vec, |
| 71 | struct osmo_sub_auth_data *aud, |
| 72 | const uint8_t *_rand); |
| 73 | |
Harald Welte | 007a71e | 2012-07-18 19:47:56 +0200 | [diff] [blame] | 74 | /* \brief callback for generationg auth vectors + re-sync */ |
Harald Welte | d82e0eb | 2011-12-06 21:53:42 +0100 | [diff] [blame] | 75 | int (*gen_vec_auts)(struct osmo_auth_vector *vec, |
| 76 | struct osmo_sub_auth_data *aud, |
| 77 | const uint8_t *rand_auts, const uint8_t *auts, |
| 78 | const uint8_t *_rand); |
| 79 | }; |
| 80 | |
| 81 | int osmo_auth_gen_vec(struct osmo_auth_vector *vec, |
| 82 | struct osmo_sub_auth_data *aud, const uint8_t *_rand); |
| 83 | |
| 84 | int osmo_auth_gen_vec_auts(struct osmo_auth_vector *vec, |
| 85 | struct osmo_sub_auth_data *aud, |
| 86 | const uint8_t *rand_auts, const uint8_t *auts, |
| 87 | const uint8_t *_rand); |
| 88 | |
| 89 | int osmo_auth_register(struct osmo_auth_impl *impl); |
| 90 | |
| 91 | int osmo_auth_load(const char *path); |
| 92 | |
| 93 | int osmo_auth_supported(enum osmo_auth_algo algo); |
Max | ceae123 | 2016-06-27 18:12:49 +0200 | [diff] [blame] | 94 | void osmo_c4(uint8_t *ck, const uint8_t *kc); |
Harald Welte | a5ab162 | 2011-12-07 02:33:11 +0100 | [diff] [blame] | 95 | const char *osmo_auth_alg_name(enum osmo_auth_algo alg); |
| 96 | enum osmo_auth_algo osmo_auth_alg_parse(const char *name); |
| 97 | |
Harald Welte | 007a71e | 2012-07-18 19:47:56 +0200 | [diff] [blame] | 98 | /* @} */ |