use new RCSID macro to prevent Id keyword from being optimized out
[freeradius.git] / src / modules / rlm_eap / libeap / eap_sim.h
1 /*
2  * eap_sim.h    Header file containing the EAP-SIM types
3  *
4  * Version:     $Id$
5  *
6  *   This program is free software; you can redistribute it and/or modify
7  *   it under the terms of the GNU General Public License as published by
8  *   the Free Software Foundation; either version 2 of the License, or
9  *   (at your option) any later version.
10  *
11  *   This program is distributed in the hope that it will be useful,
12  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *   GNU General Public License for more details.
15  *
16  *   You should have received a copy of the GNU General Public License
17  *   along with this program; if not, write to the Free Software
18  *   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  *
20  * Copyright 2003  Michael Richardson <mcr@sandelman.ottawa.on.ca>
21  * Copyright 2006  The FreeRADIUS server project
22  *
23  */
24 #ifndef _EAP_SIM_H
25 #define _EAP_SIM_H
26
27 #include <freeradius-devel/ident.h>
28 RCSIDH(eap_sim_h, "$Id$")
29
30 #include "eap_types.h"
31
32 #define EAP_SIM_VERSION 0x0001
33
34 /* base for dictionary values */
35 #define ATTRIBUTE_EAP_SIM_BASE      (6*256)
36
37 #define ATTRIBUTE_EAP_SIM_SUBTYPE       1200
38 #define ATTRIBUTE_EAP_SIM_RAND1         1201
39 #define ATTRIBUTE_EAP_SIM_RAND2         1202
40 #define ATTRIBUTE_EAP_SIM_RAND3         1203
41                                         
42 #define ATTRIBUTE_EAP_SIM_SRES1         1204
43 #define ATTRIBUTE_EAP_SIM_SRES2         1205
44 #define ATTRIBUTE_EAP_SIM_SRES3         1206
45                                         
46 #define ATTRIBUTE_EAP_SIM_STATE         1207
47 #define ATTRIBUTE_EAP_SIM_IMSI          1208
48 #define ATTRIBUTE_EAP_SIM_HMAC          1209
49 #define ATTRIBUTE_EAP_SIM_KEY           1210
50 #define ATTRIBUTE_EAP_SIM_EXTRA         1211
51                                         
52 #define ATTRIBUTE_EAP_SIM_KC1           1212
53 #define ATTRIBUTE_EAP_SIM_KC2           1213
54 #define ATTRIBUTE_EAP_SIM_KC3           1214
55
56 enum eapsim_subtype {
57   eapsim_start       = 10,
58   eapsim_challenge   = 11,
59   eapsim_notification= 12,
60   eapsim_reauth      = 13,
61   eapsim_max_subtype = 14
62 };
63
64 enum eapsim_clientstates {
65   eapsim_client_init = 0,
66   eapsim_client_start = 1,
67   eapsim_client_maxstates
68 };
69
70 /* server states
71  *
72  * in server_start, we send a EAP-SIM Start message.
73  *
74  */
75 enum eapsim_serverstates {
76   eapsim_server_start = 0,
77   eapsim_server_challenge=1,
78   eapsim_server_success=10,
79   eapsim_server_maxstates
80 };
81
82 #define PW_EAP_SIM_RAND                 1
83 #define PW_EAP_SIM_PADDING              6
84 #define PW_EAP_SIM_NONCE_MT             7
85 #define PW_EAP_SIM_PERMANENT_ID_REQ    10
86 #define PW_EAP_SIM_MAC                 11
87 #define PW_EAP_SIM_NOTIFICATION        12
88 #define PW_EAP_SIM_ANY_ID_REQ          13
89 #define PW_EAP_SIM_IDENTITY            14
90 #define PW_EAP_SIM_VERSION_LIST        15
91 #define PW_EAP_SIM_SELECTED_VERSION    16
92 #define PW_EAP_SIM_FULLAUTH_ID_REQ     17
93 #define PW_EAP_SIM_COUNTER             19
94 #define PW_EAP_SIM_COUNTER_TOO_SMALL   20
95 #define PW_EAP_SIM_NONCE_S             21
96 #define PW_EAP_SIM_IV                 129
97 #define PW_EAP_SIM_ENCR_DATA          130
98 #define PW_EAP_SIM_NEXT_PSEUDONUM     132
99 #define PW_EAP_SIM_NEXT_REAUTH_ID     133
100 #define PW_EAP_SIM_CHECKCODE          134
101
102 /*
103  * interfaces in eapsimlib.c
104  */
105 extern int map_eapsim_types(RADIUS_PACKET *r);
106 extern int map_eapsim_basictypes(RADIUS_PACKET *r, EAP_PACKET *ep);
107 extern int unmap_eapsim_types(RADIUS_PACKET *r);
108 extern const char *sim_state2name(enum eapsim_clientstates state, char *buf, int buflen);
109 extern const char *sim_subtype2name(enum eapsim_subtype subtype, char *buf, int buflen);
110 extern int unmap_eapsim_basictypes(RADIUS_PACKET *r,
111                                    uint8_t *attr, unsigned int attrlen);
112
113
114 /************************/
115 /*   CRYPTO FUNCTIONS   */
116 /************************/
117
118 /*
119  * key derivation functions/structures
120  *
121  */
122
123 #define EAPSIM_SRES_SIZE 4
124 #define EAPSIM_RAND_SIZE 16
125 #define EAPSIM_Kc_SIZE   8
126 #define EAPSIM_CALCMAC_SIZE 20
127 #define EAPSIM_NONCEMT_SIZE 16
128 #define EAPSIM_AUTH_SIZE    16
129
130 struct eapsim_keys {
131   /* inputs */
132   unsigned char identity[MAX_STRING_LEN];
133   unsigned int  identitylen;
134   unsigned char nonce_mt[EAPSIM_NONCEMT_SIZE];
135   unsigned char rand[3][EAPSIM_RAND_SIZE];
136   unsigned char sres[3][EAPSIM_SRES_SIZE];
137   unsigned char Kc[3][EAPSIM_Kc_SIZE];
138   unsigned char versionlist[MAX_STRING_LEN];
139   unsigned char versionlistlen;
140   unsigned char versionselect[2];
141
142   /* outputs */
143   unsigned char master_key[20];
144   unsigned char K_aut[EAPSIM_AUTH_SIZE];
145   unsigned char K_encr[16];
146   unsigned char msk[64];
147   unsigned char emsk[64];
148 };
149
150
151 /*
152  * interfaces in eapsimlib.c
153  */
154 extern int  eapsim_checkmac(VALUE_PAIR *rvps,
155                             uint8_t key[8],
156                             uint8_t *extra, int extralen,
157                             uint8_t calcmac[20]);
158
159 /*
160  * in eapcrypto.c
161  */
162 extern void eapsim_calculate_keys(struct eapsim_keys *ek);
163 extern void eapsim_dump_mk(struct eapsim_keys *ek);
164
165
166 #endif /* _EAP_SIM_H */