70ca3d14046bb30d7748f6f66ab3b1b258e2a4cc
[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 RCSIDH(eap_sim_h, "$Id$")
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 extern int map_eapsim_basictypes(RADIUS_PACKET *r, eap_packet_t *ep);
65 extern char const *sim_state2name(enum eapsim_clientstates state, char *buf, int buflen);
66 extern char const *sim_subtype2name(enum eapsim_subtype subtype, char *buf, int buflen);
67 extern int unmap_eapsim_basictypes(RADIUS_PACKET *r,
68                                    uint8_t *attr, unsigned int attrlen);
69
70
71 /************************/
72 /*   CRYPTO FUNCTIONS   */
73 /************************/
74
75 /*
76  * key derivation functions/structures
77  *
78  */
79
80 #define EAPSIM_SRES_SIZE 4
81 #define EAPSIM_RAND_SIZE 16
82 #define EAPSIM_KC_SIZE   8
83 #define EAPSIM_CALCMAC_SIZE 20
84 #define EAPSIM_NONCEMT_SIZE 16
85 #define EAPSIM_AUTH_SIZE    16
86
87 struct eapsim_keys {
88   /* inputs */
89   unsigned char identity[MAX_STRING_LEN];
90   unsigned int  identitylen;
91   unsigned char nonce_mt[EAPSIM_NONCEMT_SIZE];
92   unsigned char rand[3][EAPSIM_RAND_SIZE];
93   unsigned char sres[3][EAPSIM_SRES_SIZE];
94   unsigned char Kc[3][EAPSIM_KC_SIZE];
95   unsigned char versionlist[MAX_STRING_LEN];
96   unsigned char versionlistlen;
97   unsigned char versionselect[2];
98
99   /* outputs */
100   unsigned char master_key[20];
101   unsigned char K_aut[EAPSIM_AUTH_SIZE];
102   unsigned char K_encr[16];
103   unsigned char msk[64];
104   unsigned char emsk[64];
105 };
106
107
108 /*
109  * interfaces in eapsimlib.c
110  */
111 extern int  eapsim_checkmac(TALLOC_CTX *ctx, VALUE_PAIR *rvps,
112                             uint8_t key[8],
113                             uint8_t *extra, int extralen,
114                             uint8_t calcmac[20]);
115
116 /*
117  * in eapcrypto.c
118  */
119 extern void eapsim_calculate_keys(struct eapsim_keys *ek);
120 extern void eapsim_dump_mk(struct eapsim_keys *ek);
121
122
123 #endif /* _EAP_SIM_H */