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