blob: 67b320097be5b4dcce0724d409ed39f83ff27199 [file] [log] [blame]
Harald Welted82e0eb2011-12-06 21:53:42 +01001#ifndef _OSMOCRYPTO_AUTH_H
2#define _OSMOCRYPTO_AUTH_H
3
4#include <stdint.h>
5
6#include <osmocom/core/linuxlist.h>
7
8/*! \brief Authentication Type */
9enum osmo_sub_auth_type {
10 OSMO_AUTH_TYPE_NONE = 0x00,
11 OSMO_AUTH_TYPE_GSM = 0x01,
12 OSMO_AUTH_TYPE_UMTS = 0x02,
13};
14
15/*! \brief Authentication Algorithm */
16enum osmo_auth_algo {
17 OSMO_AUTH_ALG_NONE,
18 OSMO_AUTH_ALG_COMP128v1,
19 OSMO_AUTH_ALG_COMP128v2,
20 OSMO_AUTH_ALG_COMP128v3,
21 OSMO_AUTH_ALG_XOR,
22 OSMO_AUTH_ALG_MILENAGE,
23 _OSMO_AUTH_ALG_NUM,
24};
25
26/*! \brief permanent (secret) subscriber auth data */
27struct osmo_sub_auth_data {
28 enum osmo_sub_auth_type type;
29 enum osmo_auth_algo algo;
30 union {
31 struct {
32 uint8_t opc[16];
33 uint8_t k[16];
34 uint8_t amf[2];
35 uint64_t sqn;
Harald Weltea72e47b2012-03-21 09:03:16 +010036 int opc_is_op;
Harald Welted82e0eb2011-12-06 21:53:42 +010037 } umts;
38 struct {
39 uint8_t ki[16];
40 } gsm;
Harald Welteaae23622011-12-07 11:35:02 +010041 } u;
Harald Welted82e0eb2011-12-06 21:53:42 +010042};
43
44/* data structure describing a computed auth vector, generated by AuC */
45struct osmo_auth_vector {
46 uint8_t rand[16];
47 uint8_t autn[16];
48 uint8_t ck[16];
49 uint8_t ik[16];
50 uint8_t res[16];
51 uint8_t res_len;
52 uint8_t kc[8];
53 uint8_t sres[4];
54 uint32_t auth_types; /*!< bitmask of OSMO_AUTH_TYPE_* */
55};
56
57/* \brief An implementation of an authentication algorithm */
58struct osmo_auth_impl {
59 struct llist_head list;
60 enum osmo_auth_algo algo;
61 const char *name;
62 unsigned int priority;
63
64 int (*gen_vec)(struct osmo_auth_vector *vec,
65 struct osmo_sub_auth_data *aud,
66 const uint8_t *_rand);
67
68 int (*gen_vec_auts)(struct osmo_auth_vector *vec,
69 struct osmo_sub_auth_data *aud,
70 const uint8_t *rand_auts, const uint8_t *auts,
71 const uint8_t *_rand);
72};
73
74int osmo_auth_gen_vec(struct osmo_auth_vector *vec,
75 struct osmo_sub_auth_data *aud, const uint8_t *_rand);
76
77int osmo_auth_gen_vec_auts(struct osmo_auth_vector *vec,
78 struct osmo_sub_auth_data *aud,
79 const uint8_t *rand_auts, const uint8_t *auts,
80 const uint8_t *_rand);
81
82int osmo_auth_register(struct osmo_auth_impl *impl);
83
84int osmo_auth_load(const char *path);
85
86int osmo_auth_supported(enum osmo_auth_algo algo);
87
Harald Weltea5ab1622011-12-07 02:33:11 +010088const char *osmo_auth_alg_name(enum osmo_auth_algo alg);
89enum osmo_auth_algo osmo_auth_alg_parse(const char *name);
90
Harald Welted82e0eb2011-12-06 21:53:42 +010091#endif /* _OSMOCRYPTO_AUTH_H */