blob: 7a27f3b38d30370e57d6d6be614ecbc74a41ebd2 [file] [log] [blame]
Sylvain Munaut12ba7782014-06-16 10:13:40 +02001#pragma once
Harald Welted82e0eb2011-12-06 21:53:42 +01002
Harald Welte007a71e2012-07-18 19:47:56 +02003/*! \addtogroup auth
4 * @{
5 */
6
7/*! \file auth.h */
8
Harald Welted82e0eb2011-12-06 21:53:42 +01009#include <stdint.h>
10
11#include <osmocom/core/linuxlist.h>
12
Harald Welte007a71e2012-07-18 19:47:56 +020013/*! \brief Authentication Type (GSM/UMTS) */
Harald Welted82e0eb2011-12-06 21:53:42 +010014enum osmo_sub_auth_type {
15 OSMO_AUTH_TYPE_NONE = 0x00,
16 OSMO_AUTH_TYPE_GSM = 0x01,
17 OSMO_AUTH_TYPE_UMTS = 0x02,
18};
19
20/*! \brief Authentication Algorithm */
21enum osmo_auth_algo {
22 OSMO_AUTH_ALG_NONE,
23 OSMO_AUTH_ALG_COMP128v1,
24 OSMO_AUTH_ALG_COMP128v2,
25 OSMO_AUTH_ALG_COMP128v3,
26 OSMO_AUTH_ALG_XOR,
27 OSMO_AUTH_ALG_MILENAGE,
28 _OSMO_AUTH_ALG_NUM,
29};
30
31/*! \brief permanent (secret) subscriber auth data */
32struct osmo_sub_auth_data {
33 enum osmo_sub_auth_type type;
34 enum osmo_auth_algo algo;
35 union {
36 struct {
Harald Welte007a71e2012-07-18 19:47:56 +020037 uint8_t opc[16]; /*!< operator invariant value */
38 uint8_t k[16]; /*!< secret key of the subscriber */
Harald Welted82e0eb2011-12-06 21:53:42 +010039 uint8_t amf[2];
Harald Welte007a71e2012-07-18 19:47:56 +020040 uint64_t sqn; /*!< sequence number */
41 int opc_is_op; /*!< is the OPC field OPC (0) or OP (1) ? */
Neels Hofmeyrbb6f7b72017-03-13 17:27:17 +010042 unsigned int ind_bitlen; /*!< nr of bits not in SEQ, only SQN */
43 unsigned int ind; /*!< SQN slot, i.e. (SEQ << ind_bitlen) + ind */
Harald Welted82e0eb2011-12-06 21:53:42 +010044 } umts;
45 struct {
Harald Welte007a71e2012-07-18 19:47:56 +020046 uint8_t ki[16]; /*!< secret key */
Harald Welted82e0eb2011-12-06 21:53:42 +010047 } gsm;
Harald Welteaae23622011-12-07 11:35:02 +010048 } u;
Harald Welted82e0eb2011-12-06 21:53:42 +010049};
50
51/* data structure describing a computed auth vector, generated by AuC */
52struct osmo_auth_vector {
Harald Welte007a71e2012-07-18 19:47:56 +020053 uint8_t rand[16]; /*!< random challenge */
54 uint8_t autn[16]; /*!< authentication nonce */
55 uint8_t ck[16]; /*!< ciphering key */
56 uint8_t ik[16]; /*!< integrity key */
57 uint8_t res[16]; /*!< authentication result */
58 uint8_t res_len; /*!< length (in bytes) of res */
59 uint8_t kc[8]; /*!< Kc for GSM encryption (A5) */
60 uint8_t sres[4]; /*!< authentication result for GSM */
Harald Welted82e0eb2011-12-06 21:53:42 +010061 uint32_t auth_types; /*!< bitmask of OSMO_AUTH_TYPE_* */
62};
63
64/* \brief An implementation of an authentication algorithm */
65struct osmo_auth_impl {
66 struct llist_head list;
Harald Welte007a71e2012-07-18 19:47:56 +020067 enum osmo_auth_algo algo; /*!< algorithm we implement */
68 const char *name; /*!< name of the implementation */
69 unsigned int priority; /*!< priority value (resp. othe implementations */
Harald Welted82e0eb2011-12-06 21:53:42 +010070
Harald Welte007a71e2012-07-18 19:47:56 +020071 /*! \brief callback for generate authentication vectors */
Harald Welted82e0eb2011-12-06 21:53:42 +010072 int (*gen_vec)(struct osmo_auth_vector *vec,
73 struct osmo_sub_auth_data *aud,
74 const uint8_t *_rand);
75
Harald Welte007a71e2012-07-18 19:47:56 +020076 /* \brief callback for generationg auth vectors + re-sync */
Harald Welted82e0eb2011-12-06 21:53:42 +010077 int (*gen_vec_auts)(struct osmo_auth_vector *vec,
78 struct osmo_sub_auth_data *aud,
Neels Hofmeyr03ab9a62017-02-03 05:00:24 +010079 const uint8_t *auts, const uint8_t *rand_auts,
Harald Welted82e0eb2011-12-06 21:53:42 +010080 const uint8_t *_rand);
81};
82
83int osmo_auth_gen_vec(struct osmo_auth_vector *vec,
84 struct osmo_sub_auth_data *aud, const uint8_t *_rand);
85
86int osmo_auth_gen_vec_auts(struct osmo_auth_vector *vec,
87 struct osmo_sub_auth_data *aud,
Neels Hofmeyr03ab9a62017-02-03 05:00:24 +010088 const uint8_t *auts, const uint8_t *rand_auts,
Harald Welted82e0eb2011-12-06 21:53:42 +010089 const uint8_t *_rand);
90
91int osmo_auth_register(struct osmo_auth_impl *impl);
92
93int osmo_auth_load(const char *path);
94
95int osmo_auth_supported(enum osmo_auth_algo algo);
Maxceae1232016-06-27 18:12:49 +020096void osmo_c4(uint8_t *ck, const uint8_t *kc);
Harald Weltea5ab1622011-12-07 02:33:11 +010097const char *osmo_auth_alg_name(enum osmo_auth_algo alg);
98enum osmo_auth_algo osmo_auth_alg_parse(const char *name);
99
Harald Welte007a71e2012-07-18 19:47:56 +0200100/* @} */