blob: 5c45a5d61eccdac98d05e7d73ab9a53ab0b222cb [file] [log] [blame]
Piotr Krysik9e2e8352018-02-27 12:16:25 +01001#pragma once
2
3/*! \defgroup auth GSM/GPRS/3G Authentication
4 * @{
5 * \file auth.h */
6
7#include <stdint.h>
8
9#include <osmocom/core/linuxlist.h>
10#include <osmocom/core/utils.h>
11
12#define OSMO_A5_MAX_KEY_LEN_BYTES (128/8)
13#define OSMO_MILENAGE_IND_BITLEN_MAX 28
14
15/*! Authentication Type (GSM/UMTS) */
16enum osmo_sub_auth_type {
17 OSMO_AUTH_TYPE_NONE = 0x00,
18 OSMO_AUTH_TYPE_GSM = 0x01,
19 OSMO_AUTH_TYPE_UMTS = 0x02,
20};
21
22extern const struct value_string osmo_sub_auth_type_names[];
23/*static inline const char *osmo_sub_auth_type_name(enum osmo_sub_auth_type val)
24{ return get_value_string(osmo_sub_auth_type_names, val); }
25*/
26
27/*! Authentication Algorithm.
28 * See also osmo_auth_alg_name() and osmo_auth_alg_parse(). */
29enum osmo_auth_algo {
30 OSMO_AUTH_ALG_NONE,
31 OSMO_AUTH_ALG_COMP128v1,
32 OSMO_AUTH_ALG_COMP128v2,
33 OSMO_AUTH_ALG_COMP128v3,
34 OSMO_AUTH_ALG_XOR,
35 OSMO_AUTH_ALG_MILENAGE,
36 _OSMO_AUTH_ALG_NUM,
37};
38
39/*! permanent (secret) subscriber auth data */
40struct osmo_sub_auth_data {
41 enum osmo_sub_auth_type type;
42 enum osmo_auth_algo algo;
43 union {
44 struct {
45 uint8_t opc[16]; /*!< operator invariant value */
46 uint8_t k[16]; /*!< secret key of the subscriber */
47 uint8_t amf[2];
48 uint64_t sqn; /*!< sequence number (in: prev sqn; out: used sqn) */
49 int opc_is_op; /*!< is the OPC field OPC (0) or OP (1) ? */
50 unsigned int ind_bitlen; /*!< nr of bits not in SEQ, only SQN */
51 unsigned int ind; /*!< which IND slot to use an SQN from */
52 uint64_t sqn_ms; /*!< sqn from AUTS (output value only) */
53 } umts;
54 struct {
55 uint8_t ki[OSMO_A5_MAX_KEY_LEN_BYTES]; /*!< secret key */
56 } gsm;
57 } u;
58};
59
60/* data structure describing a computed auth vector, generated by AuC */
61struct osmo_auth_vector {
62 uint8_t rand[16]; /*!< random challenge */
63 uint8_t autn[16]; /*!< authentication nonce */
64 uint8_t ck[16]; /*!< ciphering key */
65 uint8_t ik[16]; /*!< integrity key */
66 uint8_t res[16]; /*!< authentication result */
67 uint8_t res_len; /*!< length (in bytes) of res */
68 uint8_t kc[8]; /*!< Kc for GSM encryption (A5) */
69 uint8_t sres[4]; /*!< authentication result for GSM */
70 uint32_t auth_types; /*!< bitmask of OSMO_AUTH_TYPE_* */
71};
72
73/* An implementation of an authentication algorithm */
74struct osmo_auth_impl {
75 struct llist_head list;
76 enum osmo_auth_algo algo; /*!< algorithm we implement */
77 const char *name; /*!< name of the implementation */
78 unsigned int priority; /*!< priority value (resp. othe implementations */
79
80 /*! callback for generate authentication vectors */
81 int (*gen_vec)(struct osmo_auth_vector *vec,
82 struct osmo_sub_auth_data *aud,
83 const uint8_t *_rand);
84
85 /* callback for generationg auth vectors + re-sync */
86 int (*gen_vec_auts)(struct osmo_auth_vector *vec,
87 struct osmo_sub_auth_data *aud,
88 const uint8_t *auts, const uint8_t *rand_auts,
89 const uint8_t *_rand);
90};
91
92int osmo_auth_gen_vec(struct osmo_auth_vector *vec,
93 struct osmo_sub_auth_data *aud, const uint8_t *_rand);
94
95int osmo_auth_gen_vec_auts(struct osmo_auth_vector *vec,
96 struct osmo_sub_auth_data *aud,
97 const uint8_t *auts, const uint8_t *rand_auts,
98 const uint8_t *_rand);
99
100int osmo_auth_register(struct osmo_auth_impl *impl);
101
102int osmo_auth_load(const char *path);
103
104int osmo_auth_supported(enum osmo_auth_algo algo);
105void osmo_c4(uint8_t *ck, const uint8_t *kc);
106const char *osmo_auth_alg_name(enum osmo_auth_algo alg);
107//enum osmo_auth_algo osmo_auth_alg_parse(const char *name);
108
109void osmo_auth_c3(uint8_t kc[], const uint8_t ck[], const uint8_t ik[]);
110
111/* @} */