blob: 2f88a3a45c0e9f16ae92ae6176d2f7b3a8c28f26 [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>
10
Neels Hofmeyr87e45502017-06-20 00:17:59 +020011/*! Authentication Type (GSM/UMTS) */
Harald Welted82e0eb2011-12-06 21:53:42 +010012enum osmo_sub_auth_type {
13 OSMO_AUTH_TYPE_NONE = 0x00,
14 OSMO_AUTH_TYPE_GSM = 0x01,
15 OSMO_AUTH_TYPE_UMTS = 0x02,
16};
17
Neels Hofmeyr87e45502017-06-20 00:17:59 +020018/*! Authentication Algorithm */
Harald Welted82e0eb2011-12-06 21:53:42 +010019enum osmo_auth_algo {
20 OSMO_AUTH_ALG_NONE,
21 OSMO_AUTH_ALG_COMP128v1,
22 OSMO_AUTH_ALG_COMP128v2,
23 OSMO_AUTH_ALG_COMP128v3,
24 OSMO_AUTH_ALG_XOR,
25 OSMO_AUTH_ALG_MILENAGE,
26 _OSMO_AUTH_ALG_NUM,
27};
28
Neels Hofmeyr87e45502017-06-20 00:17:59 +020029/*! permanent (secret) subscriber auth data */
Harald Welted82e0eb2011-12-06 21:53:42 +010030struct osmo_sub_auth_data {
31 enum osmo_sub_auth_type type;
32 enum osmo_auth_algo algo;
33 union {
34 struct {
Harald Welte007a71e2012-07-18 19:47:56 +020035 uint8_t opc[16]; /*!< operator invariant value */
36 uint8_t k[16]; /*!< secret key of the subscriber */
Harald Welted82e0eb2011-12-06 21:53:42 +010037 uint8_t amf[2];
Harald Welte007a71e2012-07-18 19:47:56 +020038 uint64_t sqn; /*!< sequence number */
39 int opc_is_op; /*!< is the OPC field OPC (0) or OP (1) ? */
Neels Hofmeyrbb6f7b72017-03-13 17:27:17 +010040 unsigned int ind_bitlen; /*!< nr of bits not in SEQ, only SQN */
41 unsigned int ind; /*!< SQN slot, i.e. (SEQ << ind_bitlen) + ind */
Harald Welted82e0eb2011-12-06 21:53:42 +010042 } umts;
43 struct {
Harald Welte007a71e2012-07-18 19:47:56 +020044 uint8_t ki[16]; /*!< secret key */
Harald Welted82e0eb2011-12-06 21:53:42 +010045 } gsm;
Harald Welteaae23622011-12-07 11:35:02 +010046 } u;
Harald Welted82e0eb2011-12-06 21:53:42 +010047};
48
49/* data structure describing a computed auth vector, generated by AuC */
50struct osmo_auth_vector {
Harald Welte007a71e2012-07-18 19:47:56 +020051 uint8_t rand[16]; /*!< random challenge */
52 uint8_t autn[16]; /*!< authentication nonce */
53 uint8_t ck[16]; /*!< ciphering key */
54 uint8_t ik[16]; /*!< integrity key */
55 uint8_t res[16]; /*!< authentication result */
56 uint8_t res_len; /*!< length (in bytes) of res */
57 uint8_t kc[8]; /*!< Kc for GSM encryption (A5) */
58 uint8_t sres[4]; /*!< authentication result for GSM */
Harald Welted82e0eb2011-12-06 21:53:42 +010059 uint32_t auth_types; /*!< bitmask of OSMO_AUTH_TYPE_* */
60};
61
Neels Hofmeyr87e45502017-06-20 00:17:59 +020062/* An implementation of an authentication algorithm */
Harald Welted82e0eb2011-12-06 21:53:42 +010063struct osmo_auth_impl {
64 struct llist_head list;
Harald Welte007a71e2012-07-18 19:47:56 +020065 enum osmo_auth_algo algo; /*!< algorithm we implement */
66 const char *name; /*!< name of the implementation */
67 unsigned int priority; /*!< priority value (resp. othe implementations */
Harald Welted82e0eb2011-12-06 21:53:42 +010068
Neels Hofmeyr87e45502017-06-20 00:17:59 +020069 /*! callback for generate authentication vectors */
Harald Welted82e0eb2011-12-06 21:53:42 +010070 int (*gen_vec)(struct osmo_auth_vector *vec,
71 struct osmo_sub_auth_data *aud,
72 const uint8_t *_rand);
73
Neels Hofmeyr87e45502017-06-20 00:17:59 +020074 /* callback for generationg auth vectors + re-sync */
Harald Welted82e0eb2011-12-06 21:53:42 +010075 int (*gen_vec_auts)(struct osmo_auth_vector *vec,
76 struct osmo_sub_auth_data *aud,
Neels Hofmeyr03ab9a62017-02-03 05:00:24 +010077 const uint8_t *auts, const uint8_t *rand_auts,
Harald Welted82e0eb2011-12-06 21:53:42 +010078 const uint8_t *_rand);
79};
80
81int osmo_auth_gen_vec(struct osmo_auth_vector *vec,
82 struct osmo_sub_auth_data *aud, const uint8_t *_rand);
83
84int osmo_auth_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
89int osmo_auth_register(struct osmo_auth_impl *impl);
90
91int osmo_auth_load(const char *path);
92
93int osmo_auth_supported(enum osmo_auth_algo algo);
Maxceae1232016-06-27 18:12:49 +020094void osmo_c4(uint8_t *ck, const uint8_t *kc);
Harald Weltea5ab1622011-12-07 02:33:11 +010095const char *osmo_auth_alg_name(enum osmo_auth_algo alg);
96enum osmo_auth_algo osmo_auth_alg_parse(const char *name);
97
Harald Welte007a71e2012-07-18 19:47:56 +020098/* @} */