blob: 7064c9991efd8d285491bbd2365365d73ec37b9d [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 * @{
Neels Hofmeyr17518fe2017-06-20 04:35:06 +02005 * \file auth.h */
Harald Welte007a71e2012-07-18 19:47:56 +02006
Harald Welted82e0eb2011-12-06 21:53:42 +01007#include <stdint.h>
8
9#include <osmocom/core/linuxlist.h>
Neels Hofmeyr26e30b12017-10-07 04:41:22 +020010#include <osmocom/core/utils.h>
Harald Welted82e0eb2011-12-06 21:53:42 +010011
Max483cdff2017-08-28 10:38:59 +020012#define OSMO_A5_MAX_KEY_LEN_BYTES (128/8)
13
Neels Hofmeyr87e45502017-06-20 00:17:59 +020014/*! 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
Neels Hofmeyr26e30b12017-10-07 04:41:22 +020021extern const struct value_string osmo_sub_auth_type_names[];
22static inline const char *osmo_sub_auth_type_name(enum osmo_sub_auth_type val)
23{ return get_value_string(osmo_sub_auth_type_names, val); }
24
25/*! Authentication Algorithm.
26 * See also osmo_auth_alg_name() and osmo_auth_alg_parse(). */
Harald Welted82e0eb2011-12-06 21:53:42 +010027enum osmo_auth_algo {
28 OSMO_AUTH_ALG_NONE,
29 OSMO_AUTH_ALG_COMP128v1,
30 OSMO_AUTH_ALG_COMP128v2,
31 OSMO_AUTH_ALG_COMP128v3,
32 OSMO_AUTH_ALG_XOR,
33 OSMO_AUTH_ALG_MILENAGE,
34 _OSMO_AUTH_ALG_NUM,
35};
36
Neels Hofmeyr87e45502017-06-20 00:17:59 +020037/*! permanent (secret) subscriber auth data */
Harald Welted82e0eb2011-12-06 21:53:42 +010038struct osmo_sub_auth_data {
39 enum osmo_sub_auth_type type;
40 enum osmo_auth_algo algo;
41 union {
42 struct {
Harald Welte007a71e2012-07-18 19:47:56 +020043 uint8_t opc[16]; /*!< operator invariant value */
44 uint8_t k[16]; /*!< secret key of the subscriber */
Harald Welted82e0eb2011-12-06 21:53:42 +010045 uint8_t amf[2];
Neels Hofmeyr95500c82017-08-26 22:38:08 +020046 uint64_t sqn; /*!< sequence number (in: prev sqn; out: used sqn) */
Harald Welte007a71e2012-07-18 19:47:56 +020047 int opc_is_op; /*!< is the OPC field OPC (0) or OP (1) ? */
Neels Hofmeyrbb6f7b72017-03-13 17:27:17 +010048 unsigned int ind_bitlen; /*!< nr of bits not in SEQ, only SQN */
Neels Hofmeyr95500c82017-08-26 22:38:08 +020049 unsigned int ind; /*!< which IND slot to use an SQN from */
Neels Hofmeyr2066a422017-08-26 22:43:50 +020050 uint64_t sqn_ms; /*!< sqn from AUTS (output value only) */
Harald Welted82e0eb2011-12-06 21:53:42 +010051 } umts;
52 struct {
Max483cdff2017-08-28 10:38:59 +020053 uint8_t ki[OSMO_A5_MAX_KEY_LEN_BYTES]; /*!< secret key */
Harald Welted82e0eb2011-12-06 21:53:42 +010054 } gsm;
Harald Welteaae23622011-12-07 11:35:02 +010055 } u;
Harald Welted82e0eb2011-12-06 21:53:42 +010056};
57
58/* data structure describing a computed auth vector, generated by AuC */
59struct osmo_auth_vector {
Harald Welte007a71e2012-07-18 19:47:56 +020060 uint8_t rand[16]; /*!< random challenge */
61 uint8_t autn[16]; /*!< authentication nonce */
62 uint8_t ck[16]; /*!< ciphering key */
63 uint8_t ik[16]; /*!< integrity key */
64 uint8_t res[16]; /*!< authentication result */
65 uint8_t res_len; /*!< length (in bytes) of res */
66 uint8_t kc[8]; /*!< Kc for GSM encryption (A5) */
67 uint8_t sres[4]; /*!< authentication result for GSM */
Harald Welted82e0eb2011-12-06 21:53:42 +010068 uint32_t auth_types; /*!< bitmask of OSMO_AUTH_TYPE_* */
69};
70
Neels Hofmeyr87e45502017-06-20 00:17:59 +020071/* An implementation of an authentication algorithm */
Harald Welted82e0eb2011-12-06 21:53:42 +010072struct osmo_auth_impl {
73 struct llist_head list;
Harald Welte007a71e2012-07-18 19:47:56 +020074 enum osmo_auth_algo algo; /*!< algorithm we implement */
75 const char *name; /*!< name of the implementation */
76 unsigned int priority; /*!< priority value (resp. othe implementations */
Harald Welted82e0eb2011-12-06 21:53:42 +010077
Neels Hofmeyr87e45502017-06-20 00:17:59 +020078 /*! callback for generate authentication vectors */
Harald Welted82e0eb2011-12-06 21:53:42 +010079 int (*gen_vec)(struct osmo_auth_vector *vec,
80 struct osmo_sub_auth_data *aud,
81 const uint8_t *_rand);
82
Neels Hofmeyr87e45502017-06-20 00:17:59 +020083 /* callback for generationg auth vectors + re-sync */
Harald Welted82e0eb2011-12-06 21:53:42 +010084 int (*gen_vec_auts)(struct osmo_auth_vector *vec,
85 struct osmo_sub_auth_data *aud,
Neels Hofmeyr03ab9a62017-02-03 05:00:24 +010086 const uint8_t *auts, const uint8_t *rand_auts,
Harald Welted82e0eb2011-12-06 21:53:42 +010087 const uint8_t *_rand);
88};
89
90int osmo_auth_gen_vec(struct osmo_auth_vector *vec,
91 struct osmo_sub_auth_data *aud, const uint8_t *_rand);
92
93int osmo_auth_gen_vec_auts(struct osmo_auth_vector *vec,
94 struct osmo_sub_auth_data *aud,
Neels Hofmeyr03ab9a62017-02-03 05:00:24 +010095 const uint8_t *auts, const uint8_t *rand_auts,
Harald Welted82e0eb2011-12-06 21:53:42 +010096 const uint8_t *_rand);
97
98int osmo_auth_register(struct osmo_auth_impl *impl);
99
100int osmo_auth_load(const char *path);
101
102int osmo_auth_supported(enum osmo_auth_algo algo);
Maxceae1232016-06-27 18:12:49 +0200103void osmo_c4(uint8_t *ck, const uint8_t *kc);
Harald Weltea5ab1622011-12-07 02:33:11 +0100104const char *osmo_auth_alg_name(enum osmo_auth_algo alg);
105enum osmo_auth_algo osmo_auth_alg_parse(const char *name);
106
Harald Welte007a71e2012-07-18 19:47:56 +0200107/* @} */