Port fix for bug #419 from branch_1_1
[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_client_error = 14,
62   eapsim_max_subtype = 15
63 };
64
65 enum eapsim_clientstates {
66   eapsim_client_init = 0,
67   eapsim_client_start = 1,
68   eapsim_client_maxstates
69 };
70
71 /* server states
72  *
73  * in server_start, we send a EAP-SIM Start message.
74  *
75  */
76 enum eapsim_serverstates {
77   eapsim_server_start = 0,
78   eapsim_server_challenge=1,
79   eapsim_server_success=10,
80   eapsim_server_maxstates
81 };
82
83 #define PW_EAP_SIM_RAND                 1
84 #define PW_EAP_SIM_PADDING              6
85 #define PW_EAP_SIM_NONCE_MT             7
86 #define PW_EAP_SIM_PERMANENT_ID_REQ    10
87 #define PW_EAP_SIM_MAC                 11
88 #define PW_EAP_SIM_NOTIFICATION        12
89 #define PW_EAP_SIM_ANY_ID_REQ          13
90 #define PW_EAP_SIM_IDENTITY            14
91 #define PW_EAP_SIM_VERSION_LIST        15
92 #define PW_EAP_SIM_SELECTED_VERSION    16
93 #define PW_EAP_SIM_FULLAUTH_ID_REQ     17
94 #define PW_EAP_SIM_COUNTER             19
95 #define PW_EAP_SIM_COUNTER_TOO_SMALL   20
96 #define PW_EAP_SIM_NONCE_S             21
97 #define PW_EAP_SIM_IV                 129
98 #define PW_EAP_SIM_ENCR_DATA          130
99 #define PW_EAP_SIM_NEXT_PSEUDONUM     132
100 #define PW_EAP_SIM_NEXT_REAUTH_ID     133
101 #define PW_EAP_SIM_CHECKCODE          134
102
103 /*
104  * interfaces in eapsimlib.c
105  */
106 extern int map_eapsim_types(RADIUS_PACKET *r);
107 extern int map_eapsim_basictypes(RADIUS_PACKET *r, EAP_PACKET *ep);
108 extern int unmap_eapsim_types(RADIUS_PACKET *r);
109 extern const char *sim_state2name(enum eapsim_clientstates state, char *buf, int buflen);
110 extern const char *sim_subtype2name(enum eapsim_subtype subtype, char *buf, int buflen);
111 extern int unmap_eapsim_basictypes(RADIUS_PACKET *r,
112                                    uint8_t *attr, unsigned int attrlen);
113
114
115 /************************/
116 /*   CRYPTO FUNCTIONS   */
117 /************************/
118
119 /*
120  * key derivation functions/structures
121  *
122  */
123
124 #define EAPSIM_SRES_SIZE 4
125 #define EAPSIM_RAND_SIZE 16
126 #define EAPSIM_Kc_SIZE   8
127 #define EAPSIM_CALCMAC_SIZE 20
128 #define EAPSIM_NONCEMT_SIZE 16
129 #define EAPSIM_AUTH_SIZE    16
130
131 struct eapsim_keys {
132   /* inputs */
133   unsigned char identity[MAX_STRING_LEN];
134   unsigned int  identitylen;
135   unsigned char nonce_mt[EAPSIM_NONCEMT_SIZE];
136   unsigned char rand[3][EAPSIM_RAND_SIZE];
137   unsigned char sres[3][EAPSIM_SRES_SIZE];
138   unsigned char Kc[3][EAPSIM_Kc_SIZE];
139   unsigned char versionlist[MAX_STRING_LEN];
140   unsigned char versionlistlen;
141   unsigned char versionselect[2];
142
143   /* outputs */
144   unsigned char master_key[20];
145   unsigned char K_aut[EAPSIM_AUTH_SIZE];
146   unsigned char K_encr[16];
147   unsigned char msk[64];
148   unsigned char emsk[64];
149 };
150
151
152 /*
153  * interfaces in eapsimlib.c
154  */
155 extern int  eapsim_checkmac(VALUE_PAIR *rvps,
156                             uint8_t key[8],
157                             uint8_t *extra, int extralen,
158                             uint8_t calcmac[20]);
159
160 /*
161  * in eapcrypto.c
162  */
163 extern void eapsim_calculate_keys(struct eapsim_keys *ek);
164 extern void eapsim_dump_mk(struct eapsim_keys *ek);
165
166
167 #endif /* _EAP_SIM_H */