blob: 871e7c87fefbfc4c5378ef2185a31b5677696829 [file] [log] [blame]
Harald Welted82e0eb2011-12-06 21:53:42 +01001#ifndef _OSMOCRYPTO_AUTH_H
2#define _OSMOCRYPTO_AUTH_H
3
Harald Welte007a71e2012-07-18 19:47:56 +02004/*! \addtogroup auth
5 * @{
6 */
7
8/*! \file auth.h */
9
Harald Welted82e0eb2011-12-06 21:53:42 +010010#include <stdint.h>
11
12#include <osmocom/core/linuxlist.h>
13
Harald Welte007a71e2012-07-18 19:47:56 +020014/*! \brief Authentication Type (GSM/UMTS) */
Harald Welted82e0eb2011-12-06 21:53:42 +010015enum osmo_sub_auth_type {
16 OSMO_AUTH_TYPE_NONE = 0x00,
17 OSMO_AUTH_TYPE_GSM = 0x01,
18 OSMO_AUTH_TYPE_UMTS = 0x02,
19};
20
21/*! \brief Authentication Algorithm */
22enum osmo_auth_algo {
23 OSMO_AUTH_ALG_NONE,
24 OSMO_AUTH_ALG_COMP128v1,
25 OSMO_AUTH_ALG_COMP128v2,
26 OSMO_AUTH_ALG_COMP128v3,
27 OSMO_AUTH_ALG_XOR,
28 OSMO_AUTH_ALG_MILENAGE,
29 _OSMO_AUTH_ALG_NUM,
30};
31
32/*! \brief permanent (secret) subscriber auth data */
33struct osmo_sub_auth_data {
34 enum osmo_sub_auth_type type;
35 enum osmo_auth_algo algo;
36 union {
37 struct {
Harald Welte007a71e2012-07-18 19:47:56 +020038 uint8_t opc[16]; /*!< operator invariant value */
39 uint8_t k[16]; /*!< secret key of the subscriber */
Harald Welted82e0eb2011-12-06 21:53:42 +010040 uint8_t amf[2];
Harald Welte007a71e2012-07-18 19:47:56 +020041 uint64_t sqn; /*!< sequence number */
42 int opc_is_op; /*!< is the OPC field OPC (0) or OP (1) ? */
Harald Welted82e0eb2011-12-06 21:53:42 +010043 } umts;
44 struct {
Harald Welte007a71e2012-07-18 19:47:56 +020045 uint8_t ki[16]; /*!< secret key */
Harald Welted82e0eb2011-12-06 21:53:42 +010046 } gsm;
Harald Welteaae23622011-12-07 11:35:02 +010047 } u;
Harald Welted82e0eb2011-12-06 21:53:42 +010048};
49
50/* data structure describing a computed auth vector, generated by AuC */
51struct osmo_auth_vector {
Harald Welte007a71e2012-07-18 19:47:56 +020052 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 Welted82e0eb2011-12-06 21:53:42 +010060 uint32_t auth_types; /*!< bitmask of OSMO_AUTH_TYPE_* */
61};
62
63/* \brief An implementation of an authentication algorithm */
64struct osmo_auth_impl {
65 struct llist_head list;
Harald Welte007a71e2012-07-18 19:47:56 +020066 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 Welted82e0eb2011-12-06 21:53:42 +010069
Harald Welte007a71e2012-07-18 19:47:56 +020070 /*! \brief callback for generate authentication vectors */
Harald Welted82e0eb2011-12-06 21:53:42 +010071 int (*gen_vec)(struct osmo_auth_vector *vec,
72 struct osmo_sub_auth_data *aud,
73 const uint8_t *_rand);
74
Harald Welte007a71e2012-07-18 19:47:56 +020075 /* \brief callback for generationg auth vectors + re-sync */
Harald Welted82e0eb2011-12-06 21:53:42 +010076 int (*gen_vec_auts)(struct osmo_auth_vector *vec,
77 struct osmo_sub_auth_data *aud,
78 const uint8_t *rand_auts, const uint8_t *auts,
79 const uint8_t *_rand);
80};
81
82int osmo_auth_gen_vec(struct osmo_auth_vector *vec,
83 struct osmo_sub_auth_data *aud, const uint8_t *_rand);
84
85int osmo_auth_gen_vec_auts(struct osmo_auth_vector *vec,
86 struct osmo_sub_auth_data *aud,
87 const uint8_t *rand_auts, const uint8_t *auts,
88 const uint8_t *_rand);
89
90int osmo_auth_register(struct osmo_auth_impl *impl);
91
92int osmo_auth_load(const char *path);
93
94int osmo_auth_supported(enum osmo_auth_algo algo);
95
Harald Weltea5ab1622011-12-07 02:33:11 +010096const char *osmo_auth_alg_name(enum osmo_auth_algo alg);
97enum osmo_auth_algo osmo_auth_alg_parse(const char *name);
98
Harald Welted82e0eb2011-12-06 21:53:42 +010099#endif /* _OSMOCRYPTO_AUTH_H */
Harald Welte007a71e2012-07-18 19:47:56 +0200100
101/* @} */