1189251Ssam/*
2189251Ssam * EAP-FAST definitions (RFC 4851)
3189251Ssam * Copyright (c) 2004-2008, Jouni Malinen <j@w1.fi>
4189251Ssam *
5189251Ssam * This program is free software; you can redistribute it and/or modify
6189251Ssam * it under the terms of the GNU General Public License version 2 as
7189251Ssam * published by the Free Software Foundation.
8189251Ssam *
9189251Ssam * Alternatively, this software may be distributed under the terms of BSD
10189251Ssam * license.
11189251Ssam *
12189251Ssam * See README and COPYING for more details.
13189251Ssam */
14189251Ssam
15189251Ssam#ifndef EAP_FAST_H
16189251Ssam#define EAP_FAST_H
17189251Ssam
18189251Ssam#define EAP_FAST_VERSION 1
19189251Ssam#define EAP_FAST_KEY_LEN 64
20189251Ssam#define EAP_FAST_SIMCK_LEN 40
21189251Ssam#define EAP_FAST_SKS_LEN 40
22189251Ssam#define EAP_FAST_CMK_LEN 20
23189251Ssam
24189251Ssam#define TLS_EXT_PAC_OPAQUE 35
25189251Ssam
26189251Ssam/*
27209158Srpaulo * RFC 5422: Section 4.2.1 - Formats for PAC TLV Attributes / Type Field
28189251Ssam * Note: bit 0x8000 (Mandatory) and bit 0x4000 (Reserved) are also defined
29189251Ssam * in the general PAC TLV format (Section 4.2).
30189251Ssam */
31189251Ssam#define PAC_TYPE_PAC_KEY 1
32189251Ssam#define PAC_TYPE_PAC_OPAQUE 2
33189251Ssam#define PAC_TYPE_CRED_LIFETIME 3
34189251Ssam#define PAC_TYPE_A_ID 4
35189251Ssam#define PAC_TYPE_I_ID 5
36189251Ssam/*
37189251Ssam * 6 was previous assigned for SERVER_PROTECTED_DATA, but
38189251Ssam * draft-cam-winget-eap-fast-provisioning-02.txt changed this to Reserved.
39189251Ssam */
40189251Ssam#define PAC_TYPE_A_ID_INFO 7
41189251Ssam#define PAC_TYPE_PAC_ACKNOWLEDGEMENT 8
42189251Ssam#define PAC_TYPE_PAC_INFO 9
43189251Ssam#define PAC_TYPE_PAC_TYPE 10
44189251Ssam
45189251Ssam#ifdef _MSC_VER
46189251Ssam#pragma pack(push, 1)
47189251Ssam#endif /* _MSC_VER */
48189251Ssam
49189251Ssamstruct pac_tlv_hdr {
50189251Ssam	be16 type;
51189251Ssam	be16 len;
52189251Ssam} STRUCT_PACKED;
53189251Ssam
54189251Ssam#ifdef _MSC_VER
55189251Ssam#pragma pack(pop)
56189251Ssam#endif /* _MSC_VER */
57189251Ssam
58189251Ssam
59189251Ssam#define EAP_FAST_PAC_KEY_LEN 32
60189251Ssam
61209158Srpaulo/* RFC 5422: 4.2.6 PAC-Type TLV */
62189251Ssam#define PAC_TYPE_TUNNEL_PAC 1
63189251Ssam/* Application Specific Short Lived PACs (only in volatile storage) */
64189251Ssam/* User Authorization PAC */
65189251Ssam#define PAC_TYPE_USER_AUTHORIZATION 3
66189251Ssam/* Application Specific Long Lived PACs */
67189251Ssam/* Machine Authentication PAC */
68189251Ssam#define PAC_TYPE_MACHINE_AUTHENTICATION 2
69189251Ssam
70189251Ssam
71189251Ssam/*
72209158Srpaulo * RFC 5422:
73209158Srpaulo * Section 3.3 - Key Derivations Used in the EAP-FAST Provisioning Exchange
74189251Ssam */
75189251Ssamstruct eap_fast_key_block_provisioning {
76189251Ssam	/* Extra key material after TLS key_block */
77189251Ssam	u8 session_key_seed[EAP_FAST_SKS_LEN];
78189251Ssam	u8 server_challenge[16]; /* MSCHAPv2 ServerChallenge */
79189251Ssam	u8 client_challenge[16]; /* MSCHAPv2 ClientChallenge */
80189251Ssam};
81189251Ssam
82189251Ssam
83189251Ssamstruct wpabuf;
84189251Ssamstruct tls_connection;
85189251Ssam
86189251Ssamstruct eap_fast_tlv_parse {
87189251Ssam	u8 *eap_payload_tlv;
88189251Ssam	size_t eap_payload_tlv_len;
89189251Ssam	struct eap_tlv_crypto_binding_tlv *crypto_binding;
90189251Ssam	size_t crypto_binding_len;
91189251Ssam	int iresult;
92189251Ssam	int result;
93189251Ssam	int request_action;
94189251Ssam	u8 *pac;
95189251Ssam	size_t pac_len;
96189251Ssam};
97189251Ssam
98189251Ssamvoid eap_fast_put_tlv_hdr(struct wpabuf *buf, u16 type, u16 len);
99189251Ssamvoid eap_fast_put_tlv(struct wpabuf *buf, u16 type, const void *data,
100189251Ssam		      u16 len);
101189251Ssamvoid eap_fast_put_tlv_buf(struct wpabuf *buf, u16 type,
102189251Ssam			  const struct wpabuf *data);
103189251Ssamstruct wpabuf * eap_fast_tlv_eap_payload(struct wpabuf *buf);
104189251Ssamvoid eap_fast_derive_master_secret(const u8 *pac_key, const u8 *server_random,
105189251Ssam				   const u8 *client_random, u8 *master_secret);
106189251Ssamu8 * eap_fast_derive_key(void *ssl_ctx, struct tls_connection *conn,
107189251Ssam			 const char *label, size_t len);
108189251Ssamvoid eap_fast_derive_eap_msk(const u8 *simck, u8 *msk);
109189251Ssamvoid eap_fast_derive_eap_emsk(const u8 *simck, u8 *emsk);
110189251Ssamint eap_fast_parse_tlv(struct eap_fast_tlv_parse *tlv,
111189251Ssam		       int tlv_type, u8 *pos, int len);
112189251Ssam
113189251Ssam#endif /* EAP_FAST_H */
114