1189251Ssam/*
2189251Ssam * EAP server/peer: EAP-PSK shared routines
3189251Ssam * Copyright (c) 2004-2007, Jouni Malinen <j@w1.fi>
4189251Ssam *
5252726Srpaulo * This software may be distributed under the terms of the BSD license.
6252726Srpaulo * See README for more details.
7189251Ssam */
8189251Ssam
9189251Ssam#ifndef EAP_PSK_COMMON_H
10189251Ssam#define EAP_PSK_COMMON_H
11189251Ssam
12189251Ssam
13189251Ssam#define EAP_PSK_RAND_LEN 16
14189251Ssam#define EAP_PSK_MAC_LEN 16
15189251Ssam#define EAP_PSK_TEK_LEN 16
16189251Ssam#define EAP_PSK_PSK_LEN 16
17189251Ssam#define EAP_PSK_AK_LEN 16
18189251Ssam#define EAP_PSK_KDK_LEN 16
19189251Ssam
20189251Ssam#define EAP_PSK_R_FLAG_CONT 1
21189251Ssam#define EAP_PSK_R_FLAG_DONE_SUCCESS 2
22189251Ssam#define EAP_PSK_R_FLAG_DONE_FAILURE 3
23189251Ssam#define EAP_PSK_E_FLAG 0x20
24189251Ssam
25189251Ssam#define EAP_PSK_FLAGS_GET_T(flags) (((flags) & 0xc0) >> 6)
26189251Ssam#define EAP_PSK_FLAGS_SET_T(t) ((u8) (t) << 6)
27189251Ssam
28189251Ssam#ifdef _MSC_VER
29189251Ssam#pragma pack(push, 1)
30189251Ssam#endif /* _MSC_VER */
31189251Ssam
32189251Ssam/* EAP-PSK First Message (AS -> Supplicant) */
33189251Ssamstruct eap_psk_hdr_1 {
34189251Ssam	u8 flags;
35189251Ssam	u8 rand_s[EAP_PSK_RAND_LEN];
36189251Ssam	/* Followed by variable length ID_S */
37189251Ssam} STRUCT_PACKED;
38189251Ssam
39189251Ssam/* EAP-PSK Second Message (Supplicant -> AS) */
40189251Ssamstruct eap_psk_hdr_2 {
41189251Ssam	u8 flags;
42189251Ssam	u8 rand_s[EAP_PSK_RAND_LEN];
43189251Ssam	u8 rand_p[EAP_PSK_RAND_LEN];
44189251Ssam	u8 mac_p[EAP_PSK_MAC_LEN];
45189251Ssam	/* Followed by variable length ID_P */
46189251Ssam} STRUCT_PACKED;
47189251Ssam
48189251Ssam/* EAP-PSK Third Message (AS -> Supplicant) */
49189251Ssamstruct eap_psk_hdr_3 {
50189251Ssam	u8 flags;
51189251Ssam	u8 rand_s[EAP_PSK_RAND_LEN];
52189251Ssam	u8 mac_s[EAP_PSK_MAC_LEN];
53189251Ssam	/* Followed by variable length PCHANNEL */
54189251Ssam} STRUCT_PACKED;
55189251Ssam
56189251Ssam/* EAP-PSK Fourth Message (Supplicant -> AS) */
57189251Ssamstruct eap_psk_hdr_4 {
58189251Ssam	u8 flags;
59189251Ssam	u8 rand_s[EAP_PSK_RAND_LEN];
60189251Ssam	/* Followed by variable length PCHANNEL */
61189251Ssam} STRUCT_PACKED;
62189251Ssam
63189251Ssam#ifdef _MSC_VER
64189251Ssam#pragma pack(pop)
65189251Ssam#endif /* _MSC_VER */
66189251Ssam
67189251Ssam
68189251Ssamint __must_check eap_psk_key_setup(const u8 *psk, u8 *ak, u8 *kdk);
69189251Ssamint __must_check eap_psk_derive_keys(const u8 *kdk, const u8 *rand_p, u8 *tek,
70189251Ssam				     u8 *msk, u8 *emsk);
71189251Ssam
72189251Ssam#endif /* EAP_PSK_COMMON_H */
73