2014-06-16 08:13:40 +00:00
|
|
|
#pragma once
|
2011-12-06 20:53:42 +00:00
|
|
|
|
2012-07-18 17:47:56 +00:00
|
|
|
/*! \addtogroup auth
|
|
|
|
* @{
|
2017-06-20 02:35:06 +00:00
|
|
|
* \file auth.h */
|
2012-07-18 17:47:56 +00:00
|
|
|
|
2011-12-06 20:53:42 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include <osmocom/core/linuxlist.h>
|
2017-10-07 02:41:22 +00:00
|
|
|
#include <osmocom/core/utils.h>
|
2011-12-06 20:53:42 +00:00
|
|
|
|
2017-08-28 08:38:59 +00:00
|
|
|
#define OSMO_A5_MAX_KEY_LEN_BYTES (128/8)
|
|
|
|
|
2017-06-19 22:17:59 +00:00
|
|
|
/*! Authentication Type (GSM/UMTS) */
|
2011-12-06 20:53:42 +00:00
|
|
|
enum osmo_sub_auth_type {
|
|
|
|
OSMO_AUTH_TYPE_NONE = 0x00,
|
|
|
|
OSMO_AUTH_TYPE_GSM = 0x01,
|
|
|
|
OSMO_AUTH_TYPE_UMTS = 0x02,
|
|
|
|
};
|
|
|
|
|
2017-10-07 02:41:22 +00:00
|
|
|
extern const struct value_string osmo_sub_auth_type_names[];
|
|
|
|
static inline const char *osmo_sub_auth_type_name(enum osmo_sub_auth_type val)
|
|
|
|
{ return get_value_string(osmo_sub_auth_type_names, val); }
|
|
|
|
|
|
|
|
/*! Authentication Algorithm.
|
|
|
|
* See also osmo_auth_alg_name() and osmo_auth_alg_parse(). */
|
2011-12-06 20:53:42 +00:00
|
|
|
enum osmo_auth_algo {
|
|
|
|
OSMO_AUTH_ALG_NONE,
|
|
|
|
OSMO_AUTH_ALG_COMP128v1,
|
|
|
|
OSMO_AUTH_ALG_COMP128v2,
|
|
|
|
OSMO_AUTH_ALG_COMP128v3,
|
|
|
|
OSMO_AUTH_ALG_XOR,
|
|
|
|
OSMO_AUTH_ALG_MILENAGE,
|
|
|
|
_OSMO_AUTH_ALG_NUM,
|
|
|
|
};
|
|
|
|
|
2017-06-19 22:17:59 +00:00
|
|
|
/*! permanent (secret) subscriber auth data */
|
2011-12-06 20:53:42 +00:00
|
|
|
struct osmo_sub_auth_data {
|
|
|
|
enum osmo_sub_auth_type type;
|
|
|
|
enum osmo_auth_algo algo;
|
|
|
|
union {
|
|
|
|
struct {
|
2012-07-18 17:47:56 +00:00
|
|
|
uint8_t opc[16]; /*!< operator invariant value */
|
|
|
|
uint8_t k[16]; /*!< secret key of the subscriber */
|
2011-12-06 20:53:42 +00:00
|
|
|
uint8_t amf[2];
|
2017-08-26 20:38:08 +00:00
|
|
|
uint64_t sqn; /*!< sequence number (in: prev sqn; out: used sqn) */
|
2012-07-18 17:47:56 +00:00
|
|
|
int opc_is_op; /*!< is the OPC field OPC (0) or OP (1) ? */
|
2017-03-13 16:27:17 +00:00
|
|
|
unsigned int ind_bitlen; /*!< nr of bits not in SEQ, only SQN */
|
2017-08-26 20:38:08 +00:00
|
|
|
unsigned int ind; /*!< which IND slot to use an SQN from */
|
2017-08-26 20:43:50 +00:00
|
|
|
uint64_t sqn_ms; /*!< sqn from AUTS (output value only) */
|
2011-12-06 20:53:42 +00:00
|
|
|
} umts;
|
|
|
|
struct {
|
2017-08-28 08:38:59 +00:00
|
|
|
uint8_t ki[OSMO_A5_MAX_KEY_LEN_BYTES]; /*!< secret key */
|
2011-12-06 20:53:42 +00:00
|
|
|
} gsm;
|
2011-12-07 10:35:02 +00:00
|
|
|
} u;
|
2011-12-06 20:53:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* data structure describing a computed auth vector, generated by AuC */
|
|
|
|
struct osmo_auth_vector {
|
2012-07-18 17:47:56 +00:00
|
|
|
uint8_t rand[16]; /*!< random challenge */
|
|
|
|
uint8_t autn[16]; /*!< authentication nonce */
|
|
|
|
uint8_t ck[16]; /*!< ciphering key */
|
|
|
|
uint8_t ik[16]; /*!< integrity key */
|
|
|
|
uint8_t res[16]; /*!< authentication result */
|
|
|
|
uint8_t res_len; /*!< length (in bytes) of res */
|
|
|
|
uint8_t kc[8]; /*!< Kc for GSM encryption (A5) */
|
|
|
|
uint8_t sres[4]; /*!< authentication result for GSM */
|
2011-12-06 20:53:42 +00:00
|
|
|
uint32_t auth_types; /*!< bitmask of OSMO_AUTH_TYPE_* */
|
|
|
|
};
|
|
|
|
|
2017-06-19 22:17:59 +00:00
|
|
|
/* An implementation of an authentication algorithm */
|
2011-12-06 20:53:42 +00:00
|
|
|
struct osmo_auth_impl {
|
|
|
|
struct llist_head list;
|
2012-07-18 17:47:56 +00:00
|
|
|
enum osmo_auth_algo algo; /*!< algorithm we implement */
|
|
|
|
const char *name; /*!< name of the implementation */
|
|
|
|
unsigned int priority; /*!< priority value (resp. othe implementations */
|
2011-12-06 20:53:42 +00:00
|
|
|
|
2017-06-19 22:17:59 +00:00
|
|
|
/*! callback for generate authentication vectors */
|
2011-12-06 20:53:42 +00:00
|
|
|
int (*gen_vec)(struct osmo_auth_vector *vec,
|
|
|
|
struct osmo_sub_auth_data *aud,
|
|
|
|
const uint8_t *_rand);
|
|
|
|
|
2017-06-19 22:17:59 +00:00
|
|
|
/* callback for generationg auth vectors + re-sync */
|
2011-12-06 20:53:42 +00:00
|
|
|
int (*gen_vec_auts)(struct osmo_auth_vector *vec,
|
|
|
|
struct osmo_sub_auth_data *aud,
|
osmo_auth*: fix ordering of function args
milenage_gen_vec() has parameter ordering of (..., auts, rand_auts, rand).
osmo_auth_gen_vec_auts() has (..., rand_auts, auts, rand), but actually feeds
args in the same order, so that its rand_auts becomes auts, and its auts
becomes rand_auts.
Interestingly enough, API user osmo-gen-vec.c also adheres to this misordering
and in turn passes auts for osmo_auth_gen_vec_auts()'s rand_auts and vice
versa, so that it matches milenage_gen_vec().
So both the implementation (milenage_*) and the API user use the same ordering,
just osmo_auth_gen_vec_auts() and osmo_auth_impl{ .gen_vec_auts() } in-between
have the argument names swapped.
Any current user of this API would need to adhere to this swapping or will not
get successful AUTS resolution to a SQN. So the least impact fix is to rename
the args without any actual functional change.
So swap the names rand_auts and auts for osmo_auth_gen_vec_auts() and
osmo_auth_impl{ .gen_vec_auts() }. (Also adjust API doc ordering)
Change-Id: I0dcbd49759fc32d3b8974102dbd1d6703364ebf4
2017-02-03 04:00:24 +00:00
|
|
|
const uint8_t *auts, const uint8_t *rand_auts,
|
2011-12-06 20:53:42 +00:00
|
|
|
const uint8_t *_rand);
|
|
|
|
};
|
|
|
|
|
|
|
|
int osmo_auth_gen_vec(struct osmo_auth_vector *vec,
|
|
|
|
struct osmo_sub_auth_data *aud, const uint8_t *_rand);
|
|
|
|
|
|
|
|
int osmo_auth_gen_vec_auts(struct osmo_auth_vector *vec,
|
|
|
|
struct osmo_sub_auth_data *aud,
|
osmo_auth*: fix ordering of function args
milenage_gen_vec() has parameter ordering of (..., auts, rand_auts, rand).
osmo_auth_gen_vec_auts() has (..., rand_auts, auts, rand), but actually feeds
args in the same order, so that its rand_auts becomes auts, and its auts
becomes rand_auts.
Interestingly enough, API user osmo-gen-vec.c also adheres to this misordering
and in turn passes auts for osmo_auth_gen_vec_auts()'s rand_auts and vice
versa, so that it matches milenage_gen_vec().
So both the implementation (milenage_*) and the API user use the same ordering,
just osmo_auth_gen_vec_auts() and osmo_auth_impl{ .gen_vec_auts() } in-between
have the argument names swapped.
Any current user of this API would need to adhere to this swapping or will not
get successful AUTS resolution to a SQN. So the least impact fix is to rename
the args without any actual functional change.
So swap the names rand_auts and auts for osmo_auth_gen_vec_auts() and
osmo_auth_impl{ .gen_vec_auts() }. (Also adjust API doc ordering)
Change-Id: I0dcbd49759fc32d3b8974102dbd1d6703364ebf4
2017-02-03 04:00:24 +00:00
|
|
|
const uint8_t *auts, const uint8_t *rand_auts,
|
2011-12-06 20:53:42 +00:00
|
|
|
const uint8_t *_rand);
|
|
|
|
|
|
|
|
int osmo_auth_register(struct osmo_auth_impl *impl);
|
|
|
|
|
|
|
|
int osmo_auth_load(const char *path);
|
|
|
|
|
|
|
|
int osmo_auth_supported(enum osmo_auth_algo algo);
|
2016-06-27 16:12:49 +00:00
|
|
|
void osmo_c4(uint8_t *ck, const uint8_t *kc);
|
2011-12-07 01:33:11 +00:00
|
|
|
const char *osmo_auth_alg_name(enum osmo_auth_algo alg);
|
|
|
|
enum osmo_auth_algo osmo_auth_alg_parse(const char *name);
|
|
|
|
|
2012-07-18 17:47:56 +00:00
|
|
|
/* @} */
|