1 /*
2  * eap_sim.h    Header file containing the EAP-SIM types
3  *
4  * Version:     $Id: 74dda258d0a4061bafd4648219684fc573769430 $
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 RCSIDH(eap_sim_h, "$Id: 74dda258d0a4061bafd4648219684fc573769430 $")
28 
29 #include "eap_types.h"
30 
31 #define EAP_SIM_VERSION 0x0001
32 
33 enum eapsim_subtype {
34 	EAPSIM_START		= 10,
35 	EAPSIM_CHALLENGE	= 11,
36 	EAPSIM_NOTIFICATION	= 12,
37 	EAPSIM_REAUTH		= 13,
38 	EAPSIM_CLIENT_ERROR	= 14,
39 	EAPSIM_MAX_SUBTYPE	= 15
40 };
41 
42 enum eapsim_clientstates {
43 	EAPSIM_CLIENT_INIT	= 0,
44 	EAPSIM_CLIENT_START	= 1,
45 	EAPSIM_CLIENT_MAXSTATES
46 };
47 
48 /* server states
49  *
50  * in server_start, we send a EAP-SIM Start message.
51  *
52  */
53 enum eapsim_serverstates {
54 	EAPSIM_SERVER_START	= 0,
55 	EAPSIM_SERVER_CHALLENGE	= 1,
56 	EAPSIM_SERVER_SUCCESS	= 10,
57 	EAPSIM_SERVER_MAXSTATES
58 };
59 
60 
61 /*
62  * interfaces in eapsimlib.c
63  */
64 int map_eapsim_basictypes(RADIUS_PACKET *r, eap_packet_t *ep);
65 char const *sim_state2name(enum eapsim_clientstates state, char *buf, int buflen);
66 char const *sim_subtype2name(enum eapsim_subtype subtype, char *buf, int buflen);
67 int unmap_eapsim_basictypes(RADIUS_PACKET *r, uint8_t *attr, unsigned int attrlen);
68 
69 
70 /************************/
71 /*   CRYPTO FUNCTIONS   */
72 /************************/
73 
74 /*
75  * key derivation functions/structures
76  *
77  */
78 
79 #define EAPSIM_SRES_SIZE	4
80 #define EAPSIM_RAND_SIZE	16
81 #define EAPSIM_KC_SIZE		8
82 #define EAPSIM_CALCMAC_SIZE	20
83 #define EAPSIM_NONCEMT_SIZE	16
84 #define EAPSIM_AUTH_SIZE	16
85 
86 struct eapsim_keys {
87 	/* inputs */
88 	uint8_t identity[MAX_STRING_LEN];
89 	unsigned int  identitylen;
90 	uint8_t nonce_mt[EAPSIM_NONCEMT_SIZE];
91 	uint8_t rand[3][EAPSIM_RAND_SIZE];
92 	uint8_t sres[3][EAPSIM_SRES_SIZE];
93 	uint8_t Kc[3][EAPSIM_KC_SIZE];
94 	uint8_t versionlist[MAX_STRING_LEN];
95 	uint8_t versionlistlen;
96 	uint8_t versionselect[2];
97 
98 	/* outputs */
99 	uint8_t master_key[20];
100 	uint8_t K_aut[EAPSIM_AUTH_SIZE];
101 	uint8_t K_encr[16];
102 	uint8_t msk[64];
103 	uint8_t emsk[64];
104 };
105 
106 
107 /*
108  * interfaces in eapsimlib.c
109  */
110 int eapsim_checkmac(TALLOC_CTX *ctx, VALUE_PAIR *rvps,
111 		    uint8_t key[8],
112 		    uint8_t *extra, int extralen,
113 		    uint8_t calcmac[20]);
114 
115 /*
116  * in eapcrypto.c
117  */
118 void eapsim_calculate_keys(struct eapsim_keys *ek);
119 void eapsim_dump_mk(struct eapsim_keys *ek);
120 
121 
122 #endif /* _EAP_SIM_H */
123