libosmogsm 1.13.1.1-afb4 Osmocom GSM library

auth.h
Go to the documentation of this file.
1#pragma once
2
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
16 enum osmo_sub_auth_type {
17 OSMO_AUTH_TYPE_NONE = 0x00,
18 OSMO_AUTH_TYPE_GSM = 0x01,
19 OSMO_AUTH_TYPE_UMTS = 0x02,
20};
21
22 extern 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
28 enum osmo_auth_algo {
29 OSMO_AUTH_ALG_NONE,
30 OSMO_AUTH_ALG_COMP128v1,
31 OSMO_AUTH_ALG_COMP128v2,
32 OSMO_AUTH_ALG_COMP128v3,
33 OSMO_AUTH_ALG_XOR_3G,
34 OSMO_AUTH_ALG_MILENAGE,
35 OSMO_AUTH_ALG_XOR_2G,
36 OSMO_AUTH_ALG_TUAK,
37 _OSMO_AUTH_ALG_NUM,
38};
39/* Backwards-compatibility. We used to call XOR-3G just "XOR" which became ambiguous when
40 * we started to add XOR-2G support. */
41#define OSMO_AUTH_ALG_XOR OSMO_AUTH_ALG_XOR_3G
42
44 struct osmo_sub_auth_data2 {
45 enum osmo_sub_auth_type type;
46 enum osmo_auth_algo algo;
47 union {
48 struct {
49 /* See 3GPP TS 33.102 Section 9.3.7 Length of authentication parameters */
50 uint8_t opc[32];
51 uint8_t opc_len;
52 uint8_t k[32];
53 uint8_t k_len;
54 uint8_t amf[2];
55 uint64_t sqn;
56 int opc_is_op;
57 unsigned int ind_bitlen;
58 unsigned int ind;
59 uint64_t sqn_ms;
60 } umts;
61 struct {
62 uint8_t ki[OSMO_A5_MAX_KEY_LEN_BYTES];
63 } gsm;
64 } u;
65};
66
67/* deprecated older structure without support for 32-byte K/OP[c] */
68 struct osmo_sub_auth_data {
69 enum osmo_sub_auth_type type;
70 enum osmo_auth_algo algo;
71 union {
72 struct {
73 uint8_t opc[16];
74 uint8_t k[OSMO_A5_MAX_KEY_LEN_BYTES];
75 uint8_t amf[2];
76 uint64_t sqn;
77 int opc_is_op;
78 unsigned int ind_bitlen;
79 unsigned int ind;
80 uint64_t sqn_ms;
81 } umts;
82 struct {
83 uint8_t ki[OSMO_A5_MAX_KEY_LEN_BYTES];
84 } gsm;
85 } u;
86};
87
88/* data structure describing a computed auth vector, generated by AuC */
89 struct osmo_auth_vector {
90 uint8_t rand[16];
91 uint8_t autn[16];
92 uint8_t ck[OSMO_A5_MAX_KEY_LEN_BYTES];
93 uint8_t ik[OSMO_A5_MAX_KEY_LEN_BYTES];
94 uint8_t res[16];
95 uint8_t res_len;
96 uint8_t kc[8];
97 uint8_t sres[4];
98 uint32_t auth_types;
99};
100
101/* An implementation of an authentication algorithm */
102 struct osmo_auth_impl {
103 struct llist_head list;
104 enum osmo_auth_algo algo;
105 const char *name;
106 unsigned int priority;
109 int (*gen_vec)(struct osmo_auth_vector *vec,
110 struct osmo_sub_auth_data2 *aud,
111 const uint8_t *_rand);
112
114 int (*gen_vec_auts)(struct osmo_auth_vector *vec,
115 struct osmo_sub_auth_data2 *aud,
116 const uint8_t *auts, const uint8_t *rand_auts,
117 const uint8_t *_rand);
118};
119
120 int osmo_auth_gen_vec(struct osmo_auth_vector *vec,
121 struct osmo_sub_auth_data *aud, const uint8_t *_rand)
122 OSMO_DEPRECATED_OUTSIDE("Use osmo_auth_gen_vec2 instead");
123
124 int osmo_auth_gen_vec2(struct osmo_auth_vector *vec,
125 struct osmo_sub_auth_data2 *aud, const uint8_t *_rand);
126
127 int osmo_auth_gen_vec_auts(struct osmo_auth_vector *vec,
128 struct osmo_sub_auth_data *aud,
129 const uint8_t *auts, const uint8_t *rand_auts,
130 const uint8_t *_rand)
131 OSMO_DEPRECATED_OUTSIDE("Use osmo_auth_gen_vec_auts2 instead");
132
133 int osmo_auth_gen_vec_auts2(struct osmo_auth_vector *vec,
134 struct osmo_sub_auth_data2 *aud,
135 const uint8_t *auts, const uint8_t *rand_auts,
136 const uint8_t *_rand);
137
138 int osmo_auth_register(struct osmo_auth_impl *impl);
139
140 int osmo_auth_load(const char *path);
141
142 int osmo_auth_supported(enum osmo_auth_algo algo);
143 void osmo_c4(uint8_t *ck, const uint8_t *kc);
144 const char *osmo_auth_alg_name(enum osmo_auth_algo alg);
145 enum osmo_auth_algo osmo_auth_alg_parse(const char *name);
146
147 void osmo_auth_c3(uint8_t kc[], const uint8_t ck[], const uint8_t ik[]);
148 void osmo_auth_c2(uint8_t sres[4], const uint8_t *res, size_t res_len, uint8_t sres_deriv_func);
149
150/* @} */
osmo_auth_impl::algo
enum osmo_auth_algo algo
algorithm we implement
Definition: auth.h:104
osmo_auth_register
int osmo_auth_register(struct osmo_auth_impl *impl)
Register an authentication algorithm implementation with the core.
Definition: auth_core.c:77
osmo_auth_supported
int osmo_auth_supported(enum osmo_auth_algo algo)
Determine if a given authentication algorithm is supported.
Definition: auth_core.c:115
osmo_auth_impl::list
struct llist_head list
Definition: auth.h:103
osmo_sub_auth_type_name
static const char * osmo_sub_auth_type_name(enum osmo_sub_auth_type val)
Definition: auth.h:23
osmo_auth_gen_vec
int osmo_auth_gen_vec(struct osmo_auth_vector *vec, struct osmo_sub_auth_data *aud, const uint8_t *_rand) OSMO_DEPRECATED_OUTSIDE("Use osmo_auth_gen_vec2 instead")
Generate authentication vector.
Definition: auth_core.c:217
osmo_sub_auth_data2::amf
uint8_t amf[2]
Definition: auth.h:54
osmo_sub_auth_data::umts
struct osmo_sub_auth_data::@128::@129 umts
osmo_sub_auth_data2::type
enum osmo_sub_auth_type type
Definition: auth.h:45
osmo_sub_auth_data2::opc
uint8_t opc[32]
operator invariant value
Definition: auth.h:50
osmo_auth_gen_vec2
int osmo_auth_gen_vec2(struct osmo_auth_vector *vec, struct osmo_sub_auth_data2 *aud, const uint8_t *_rand)
Generate authentication vector.
Definition: auth_core.c:186
osmo_sub_auth_data2::ki
uint8_t ki[OSMO_A5_MAX_KEY_LEN_BYTES]
secret key
Definition: auth.h:62
osmo_sub_auth_data::amf
uint8_t amf[2]
Definition: auth.h:75
osmo_sub_auth_data::gsm
struct osmo_sub_auth_data::@128::@130 gsm
osmo_auth_alg_parse
enum osmo_auth_algo osmo_auth_alg_parse(const char *name)
Parse human-readable name of authentication algorithm.
Definition: auth_core.c:342
osmo_auth_c3
void osmo_auth_c3(uint8_t kc[], const uint8_t ck[], const uint8_t ik[])
Definition: auth_core.c:360
osmo_sub_auth_data2::ind
unsigned int ind
which IND slot to use an SQN from
Definition: auth.h:58
osmo_auth_gen_vec_auts2
int osmo_auth_gen_vec_auts2(struct osmo_auth_vector *vec, struct osmo_sub_auth_data2 *aud, const uint8_t *auts, const uint8_t *rand_auts, const uint8_t *_rand)
Generate authentication vector and re-sync sequence.
Definition: auth_core.c:261
osmo_auth_impl::priority
unsigned int priority
priority value (resp.
Definition: auth.h:106
osmo_sub_auth_data::opc
uint8_t opc[16]
operator invariant value
Definition: auth.h:73
osmo_auth_algo
osmo_auth_algo
Authentication Algorithm.
Definition: auth.h:28
osmo_sub_auth_data::ind
unsigned int ind
which IND slot to use an SQN from
Definition: auth.h:79
osmo_sub_auth_data2::u
union osmo_sub_auth_data2::@125 u
osmo_auth_vector::kc
uint8_t kc[8]
Kc for GSM encryption (A5)
Definition: auth.h:96
osmo_sub_auth_data::u
union osmo_sub_auth_data::@128 u
osmo_sub_auth_data2::umts
struct osmo_sub_auth_data2::@125::@126 umts
osmo_sub_auth_data2::k_len
uint8_t k_len
K length (in bytes): 16 or 32.
Definition: auth.h:53
osmo_sub_auth_data::opc_is_op
int opc_is_op
is the OPC field OPC (0) or OP (1) ?
Definition: auth.h:77
osmo_auth_load
int osmo_auth_load(const char *path)
Load all available authentication plugins from the given path.
Definition: auth_core.c:98
osmo_sub_auth_data::sqn
uint64_t sqn
sequence number (in: prev sqn; out: used sqn)
Definition: auth.h:76
osmo_sub_auth_data::type
enum osmo_sub_auth_type type
Definition: auth.h:69
osmo_auth_impl::gen_vec
int(* gen_vec)(struct osmo_auth_vector *vec, struct osmo_sub_auth_data2 *aud, const uint8_t *_rand)
callback for generate authentication vectors
Definition: auth.h:109
OSMO_A5_MAX_KEY_LEN_BYTES
#define OSMO_A5_MAX_KEY_LEN_BYTES
Definition: auth.h:12
osmo_auth_impl::name
const char * name
name of the implementation
Definition: auth.h:105
osmo_sub_auth_data2::ind_bitlen
unsigned int ind_bitlen
nr of bits not in SEQ, only SQN
Definition: auth.h:57
osmo_sub_auth_type_names
const struct value_string osmo_sub_auth_type_names[]
Definition: auth_core.c:347
osmo_auth_alg_name
const char * osmo_auth_alg_name(enum osmo_auth_algo alg)
Get human-readable name of authentication algorithm.
Definition: auth_core.c:336
osmo_auth_vector::sres
uint8_t sres[4]
authentication result for GSM
Definition: auth.h:97
osmo_sub_auth_data2::gsm
struct osmo_sub_auth_data2::@125::@127 gsm
osmo_sub_auth_data2::sqn
uint64_t sqn
sequence number (in: prev sqn; out: used sqn)
Definition: auth.h:55
osmo_sub_auth_data2::k
uint8_t k[32]
secret key of the subscriber
Definition: auth.h:52
osmo_auth_vector::res
uint8_t res[16]
authentication result
Definition: auth.h:94
osmo_auth_impl::gen_vec_auts
int(* gen_vec_auts)(struct osmo_auth_vector *vec, struct osmo_sub_auth_data2 *aud, const uint8_t *auts, const uint8_t *rand_auts, const uint8_t *_rand)
callback for generating auth vectors + re-sync
Definition: auth.h:114
osmo_c4
void osmo_c4(uint8_t *ck, const uint8_t *kc)
Definition: auth_core.c:139
osmo_sub_auth_type
osmo_sub_auth_type
Authentication Type (GSM/UMTS)
Definition: auth.h:16
osmo_auth_gen_vec_auts
int osmo_auth_gen_vec_auts(struct osmo_auth_vector *vec, struct osmo_sub_auth_data *aud, const uint8_t *auts, const uint8_t *rand_auts, const uint8_t *_rand) OSMO_DEPRECATED_OUTSIDE("Use osmo_auth_gen_vec_auts2 instead")
Generate authentication vector and re-sync sequence.
Definition: auth_core.c:296
osmo_auth_vector::ik
uint8_t ik[OSMO_A5_MAX_KEY_LEN_BYTES]
integrity key
Definition: auth.h:93
osmo_auth_vector::res_len
uint8_t res_len
length (in bytes) of res: 4..16 bytes
Definition: auth.h:95
osmo_sub_auth_data2::opc_len
uint8_t opc_len
OPc length (in bytes): 16 or 32.
Definition: auth.h:51
osmo_sub_auth_data::ki
uint8_t ki[OSMO_A5_MAX_KEY_LEN_BYTES]
secret key
Definition: auth.h:83
osmo_sub_auth_data2::algo
enum osmo_auth_algo algo
Definition: auth.h:46
osmo_sub_auth_data::sqn_ms
uint64_t sqn_ms
sqn from AUTS (output value only)
Definition: auth.h:80
osmo_sub_auth_data2::sqn_ms
uint64_t sqn_ms
sqn from AUTS (output value only)
Definition: auth.h:59
osmo_sub_auth_data::k
uint8_t k[OSMO_A5_MAX_KEY_LEN_BYTES]
secret key of the subscriber
Definition: auth.h:74
osmo_auth_vector::rand
uint8_t rand[16]
random challenge
Definition: auth.h:90
osmo_sub_auth_data::ind_bitlen
unsigned int ind_bitlen
nr of bits not in SEQ, only SQN
Definition: auth.h:78
osmo_auth_vector::auth_types
uint32_t auth_types
bitmask of OSMO_AUTH_TYPE_*
Definition: auth.h:98
osmo_sub_auth_data2::opc_is_op
int opc_is_op
is the OPC field OPC (0) or OP (1) ?
Definition: auth.h:56
osmo_auth_vector::ck
uint8_t ck[OSMO_A5_MAX_KEY_LEN_BYTES]
ciphering key
Definition: auth.h:92
osmo_auth_c2
void osmo_auth_c2(uint8_t sres[4], const uint8_t *res, size_t res_len, uint8_t sres_deriv_func)
Derive GSM SRES from UMTS [X]RES (auth function c2 from 3GPP TS 33.103 Section 6.8....
Definition: auth_core.c:373
osmo_sub_auth_data::algo
enum osmo_auth_algo algo
Definition: auth.h:70
osmo_auth_vector::autn
uint8_t autn[16]
authentication nonce
Definition: auth.h:91
OSMO_AUTH_ALG_COMP128v2
@ OSMO_AUTH_ALG_COMP128v2
Definition: auth.h:31
OSMO_AUTH_ALG_NONE
@ OSMO_AUTH_ALG_NONE
Definition: auth.h:29
OSMO_AUTH_ALG_COMP128v1
@ OSMO_AUTH_ALG_COMP128v1
Definition: auth.h:30
OSMO_AUTH_ALG_TUAK
@ OSMO_AUTH_ALG_TUAK
Definition: auth.h:36
OSMO_AUTH_ALG_XOR_3G
@ OSMO_AUTH_ALG_XOR_3G
Definition: auth.h:33
OSMO_AUTH_ALG_COMP128v3
@ OSMO_AUTH_ALG_COMP128v3
Definition: auth.h:32
OSMO_AUTH_ALG_XOR_2G
@ OSMO_AUTH_ALG_XOR_2G
Definition: auth.h:35
_OSMO_AUTH_ALG_NUM
@ _OSMO_AUTH_ALG_NUM
Definition: auth.h:37
OSMO_AUTH_ALG_MILENAGE
@ OSMO_AUTH_ALG_MILENAGE
Definition: auth.h:34
OSMO_AUTH_TYPE_UMTS
@ OSMO_AUTH_TYPE_UMTS
Definition: auth.h:19
OSMO_AUTH_TYPE_GSM
@ OSMO_AUTH_TYPE_GSM
Definition: auth.h:18
OSMO_AUTH_TYPE_NONE
@ OSMO_AUTH_TYPE_NONE
Definition: auth.h:17
OSMO_DEPRECATED_OUTSIDE
#define OSMO_DEPRECATED_OUTSIDE(text)
get_value_string
const char * get_value_string(const struct value_string *vs, uint32_t val)
sres
uint8_t sres[4]
Definition: gsm_04_08.h:0
linuxlist.h
llist_head
osmo_auth_impl
Definition: auth.h:102
osmo_auth_vector
Definition: auth.h:89
osmo_sub_auth_data2
permanent (secret) subscriber auth data
Definition: auth.h:44
osmo_sub_auth_data
Definition: auth.h:68
value_string
utils.h