import from HEAD:
[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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  * Copyright 2003  Michael Richardson <mcr@sandelman.ottawa.on.ca>
21  *
22  */
23 #ifndef _EAP_SIM_H
24 #define _EAP_SIM_H
25
26 #include "eap_types.h"
27
28 #define EAP_SIM_VERSION 0x0001
29
30 /* base for dictionary values */
31 #define ATTRIBUTE_EAP_SIM_BASE      (6*256)
32
33 #define ATTRIBUTE_EAP_SIM_SUBTYPE       1200
34 #define ATTRIBUTE_EAP_SIM_RAND1         1201
35 #define ATTRIBUTE_EAP_SIM_RAND2         1202
36 #define ATTRIBUTE_EAP_SIM_RAND3         1203
37                                         
38 #define ATTRIBUTE_EAP_SIM_SRES1         1204
39 #define ATTRIBUTE_EAP_SIM_SRES2         1205
40 #define ATTRIBUTE_EAP_SIM_SRES3         1206
41                                         
42 #define ATTRIBUTE_EAP_SIM_STATE         1207
43 #define ATTRIBUTE_EAP_SIM_IMSI          1208
44 #define ATTRIBUTE_EAP_SIM_HMAC          1209
45 #define ATTRIBUTE_EAP_SIM_KEY           1210
46 #define ATTRIBUTE_EAP_SIM_EXTRA         1211
47                                         
48 #define ATTRIBUTE_EAP_SIM_KC1           1212
49 #define ATTRIBUTE_EAP_SIM_KC2           1213
50 #define ATTRIBUTE_EAP_SIM_KC3           1214
51
52 enum eapsim_subtype {
53   eapsim_start       = 10,
54   eapsim_challenge   = 11,
55   eapsim_notification= 12,
56   eapsim_reauth      = 13,
57   eapsim_client_error = 14,
58   eapsim_max_subtype = 15
59 };
60
61 enum eapsim_clientstates {
62   eapsim_client_init = 0,
63   eapsim_client_start = 1,
64   eapsim_client_maxstates
65 };
66
67 /* server states
68  *
69  * in server_start, we send a EAP-SIM Start message.
70  *
71  */
72 enum eapsim_serverstates {
73   eapsim_server_start = 0,
74   eapsim_server_challenge=1,
75   eapsim_server_success=10,
76   eapsim_server_maxstates
77 };
78
79 #define PW_EAP_SIM_RAND                 1
80 #define PW_EAP_SIM_PADDING              6
81 #define PW_EAP_SIM_NONCE_MT             7
82 #define PW_EAP_SIM_PERMANENT_ID_REQ    10
83 #define PW_EAP_SIM_MAC                 11
84 #define PW_EAP_SIM_NOTIFICATION        12
85 #define PW_EAP_SIM_ANY_ID_REQ          13
86 #define PW_EAP_SIM_IDENTITY            14
87 #define PW_EAP_SIM_VERSION_LIST        15
88 #define PW_EAP_SIM_SELECTED_VERSION    16
89 #define PW_EAP_SIM_FULLAUTH_ID_REQ     17
90 #define PW_EAP_SIM_COUNTER             19
91 #define PW_EAP_SIM_COUNTER_TOO_SMALL   20
92 #define PW_EAP_SIM_NONCE_S             21
93 #define PW_EAP_SIM_IV                 129
94 #define PW_EAP_SIM_ENCR_DATA          130
95 #define PW_EAP_SIM_NEXT_PSEUDONUM     132
96 #define PW_EAP_SIM_NEXT_REAUTH_ID     133
97 #define PW_EAP_SIM_CHECKCODE          134
98
99 /*
100  * interfaces in eapsimlib.c
101  */
102 extern int map_eapsim_types(RADIUS_PACKET *r);
103 extern int map_eapsim_basictypes(RADIUS_PACKET *r, EAP_PACKET *ep);
104 extern int unmap_eapsim_types(RADIUS_PACKET *r);
105 extern const char *sim_state2name(enum eapsim_clientstates state, char *buf, int buflen);
106 extern const char *sim_subtype2name(enum eapsim_subtype subtype, char *buf, int buflen);
107 extern int unmap_eapsim_basictypes(RADIUS_PACKET *r,
108                                    uint8_t *attr, unsigned int attrlen);
109
110
111 /************************/
112 /*   CRYPTO FUNCTIONS   */
113 /************************/
114
115 /*
116  * key derivation functions/structures
117  *
118  */
119
120 #define EAPSIM_SRES_SIZE 4
121 #define EAPSIM_RAND_SIZE 16
122 #define EAPSIM_Kc_SIZE   8
123 #define EAPSIM_CALCMAC_SIZE 20
124 #define EAPSIM_NONCEMT_SIZE 16
125 #define EAPSIM_AUTH_SIZE    16
126
127 struct eapsim_keys {
128   /* inputs */
129   unsigned char identity[MAX_STRING_LEN];
130   unsigned int  identitylen;
131   unsigned char nonce_mt[EAPSIM_NONCEMT_SIZE];
132   unsigned char rand[3][EAPSIM_RAND_SIZE];
133   unsigned char sres[3][EAPSIM_SRES_SIZE];
134   unsigned char Kc[3][EAPSIM_Kc_SIZE];
135   unsigned char versionlist[MAX_STRING_LEN];
136   unsigned char versionlistlen;
137   unsigned char versionselect[2];
138
139   /* outputs */
140   unsigned char master_key[20];
141   unsigned char K_aut[EAPSIM_AUTH_SIZE];
142   unsigned char K_encr[16];
143   unsigned char msk[64];
144   unsigned char emsk[64];
145 };
146
147
148 /*
149  * interfaces in eapsimlib.c
150  */
151 extern int  eapsim_checkmac(VALUE_PAIR *rvps,
152                             uint8_t key[8],
153                             uint8_t *extra, int extralen,
154                             uint8_t calcmac[20]);
155
156 /*
157  * in eapcrypto.c
158  */
159 extern void eapsim_calculate_keys(struct eapsim_keys *ek);
160 extern void eapsim_dump_mk(struct eapsim_keys *ek);
161
162
163 #endif /* _EAP_SIM_H */