1 /*
2  * Simultaneous authentication of equals
3  * Copyright (c) 2012-2013, Jouni Malinen <j@w1.fi>
4  *
5  * This software may be distributed under the terms of the BSD license.
6  * See README for more details.
7  */
8 #ifdef CONFIG_WPA3_SAE
9 
10 #ifndef SAE_H
11 #define SAE_H
12 
13 #include "esp_err.h"
14 #include "utils/includes.h"
15 #include "utils/common.h"
16 #include "utils/wpa_debug.h"
17 
18 #define SAE_KCK_LEN 32
19 #define SAE_PMK_LEN 32
20 #define SAE_PMKID_LEN 16
21 #define SAE_KEYSEED_KEY_LEN 32
22 #define SAE_MAX_PRIME_LEN 512
23 #define SAE_MAX_ECC_PRIME_LEN 66
24 #define SAE_COMMIT_MAX_LEN (2 + 3 * SAE_MAX_PRIME_LEN)
25 #define SAE_CONFIRM_MAX_LEN (2 + SAE_MAX_PRIME_LEN)
26 
27 /* Special value returned by sae_parse_commit() */
28 #define SAE_SILENTLY_DISCARD 65535
29 
30 struct sae_temporary_data {
31 	u8 kck[SAE_KCK_LEN];
32 	struct crypto_bignum *own_commit_scalar;
33 	struct crypto_bignum *own_commit_element_ffc;
34 	struct crypto_ec_point *own_commit_element_ecc;
35 	struct crypto_bignum *peer_commit_element_ffc;
36 	struct crypto_ec_point *peer_commit_element_ecc;
37 	struct crypto_ec_point *pwe_ecc;
38 	struct crypto_bignum *pwe_ffc;
39 	struct crypto_bignum *sae_rand;
40 	struct crypto_ec *ec;
41 	int prime_len;
42 	const struct dh_group *dh;
43 	const struct crypto_bignum *prime;
44 	const struct crypto_bignum *order;
45 	struct crypto_bignum *prime_buf;
46 	struct crypto_bignum *order_buf;
47 	char *pw_id;
48 };
49 
50 enum {
51 	SAE_MSG_COMMIT = 1,
52 	SAE_MSG_CONFIRM = 2,
53 };
54 
55 enum sae_state {
56 	SAE_NOTHING, SAE_COMMITTED, SAE_CONFIRMED, SAE_ACCEPTED
57 };
58 
59 struct sae_data {
60 	enum sae_state state;
61 	u16 send_confirm;
62 	u8 pmk[SAE_PMK_LEN];
63 	u8 pmkid[SAE_PMKID_LEN];
64 	struct crypto_bignum *peer_commit_scalar;
65 	int group;
66 	unsigned int sync; /* protocol instance variable: Sync */
67 	u16 rc; /* protocol instance variable: Rc (received send-confirm) */
68 	struct sae_temporary_data *tmp;
69 };
70 
71 int sae_set_group(struct sae_data *sae, int group);
72 void sae_clear_temp_data(struct sae_data *sae);
73 void sae_clear_data(struct sae_data *sae);
74 
75 int sae_prepare_commit(const u8 *addr1, const u8 *addr2,
76 		       const u8 *password, size_t password_len,
77 		       const char *identifier, struct sae_data *sae);
78 int sae_process_commit(struct sae_data *sae);
79 int sae_write_commit(struct sae_data *sae, struct wpabuf *buf,
80 		      const struct wpabuf *token, const char *identifier);
81 u16 sae_parse_commit(struct sae_data *sae, const u8 *data, size_t len,
82 		     const u8 **token, size_t *token_len, int *allowed_groups);
83 int sae_write_confirm(struct sae_data *sae, struct wpabuf *buf);
84 int sae_check_confirm(struct sae_data *sae, const u8 *data, size_t len);
85 u16 sae_group_allowed(struct sae_data *sae, int *allowed_groups, u16 group);
86 const char * sae_state_txt(enum sae_state state);
87 
88 #endif /* SAE_H */
89 #endif /* CONFIG_WPA3_SAE */
90