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