1526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt/*
2526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * IKEv2 initiator (RFC 4306) for EAP-IKEV2
3526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * Copyright (c) 2007, Jouni Malinen <j@w1.fi>
4526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt *
5526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * This program is free software; you can redistribute it and/or modify
6526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * it under the terms of the GNU General Public License version 2 as
7526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * published by the Free Software Foundation.
8526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt *
9526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * Alternatively, this software may be distributed under the terms of BSD
10526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * license.
11526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt *
12526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt * See README and COPYING for more details.
13526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt */
14526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt
15526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt#ifndef IKEV2_H
16526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt#define IKEV2_H
17526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt
18526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt#include "eap_common/ikev2_common.h"
19526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt
20526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidtstruct ikev2_proposal_data {
21526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt	u8 proposal_num;
22526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt	int integ;
23526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt	int prf;
24526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt	int encr;
25526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt	int dh;
26526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt};
27526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt
28526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt
29526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidtstruct ikev2_initiator_data {
30526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt	enum { SA_INIT, SA_AUTH, CHILD_SA, IKEV2_DONE } state;
31526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt	u8 i_spi[IKEV2_SPI_LEN];
32526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt	u8 r_spi[IKEV2_SPI_LEN];
33526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt	u8 i_nonce[IKEV2_NONCE_MAX_LEN];
34526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt	size_t i_nonce_len;
35526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt	u8 r_nonce[IKEV2_NONCE_MAX_LEN];
36526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt	size_t r_nonce_len;
37526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt	struct wpabuf *r_dh_public;
38526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt	struct wpabuf *i_dh_private;
39526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt	struct ikev2_proposal_data proposal;
40526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt	const struct dh_group *dh;
41526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt	struct ikev2_keys keys;
42526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt	u8 *IDi;
43526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt	size_t IDi_len;
44526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt	u8 *IDr;
45526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt	size_t IDr_len;
46526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt	u8 IDr_type;
47526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt	struct wpabuf *r_sign_msg;
48526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt	struct wpabuf *i_sign_msg;
49526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt	u8 *shared_secret;
50526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt	size_t shared_secret_len;
51526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt	enum { PEER_AUTH_CERT, PEER_AUTH_SECRET } peer_auth;
52526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt	u8 *key_pad;
53526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt	size_t key_pad_len;
54526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt
55526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt	const u8 * (*get_shared_secret)(void *ctx, const u8 *IDr,
56526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt					size_t IDr_len, size_t *secret_len);
57526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt	void *cb_ctx;
58526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt	int unknown_user;
59526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt};
60526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt
61526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt
62526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidtvoid ikev2_initiator_deinit(struct ikev2_initiator_data *data);
63526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidtint ikev2_initiator_process(struct ikev2_initiator_data *data,
64526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt			    const struct wpabuf *buf);
65526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidtstruct wpabuf * ikev2_initiator_build(struct ikev2_initiator_data *data);
66526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt
67526fc2a7dc09b4450086cdec313a5c44d36b10fdDmitry Shmidt#endif /* IKEV2_H */
68