xref: /freebsd/contrib/wpa/src/common/sae.h (revision b0d29bc47dba79f6f38e67eabadfb4b32ffd9390)
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 
9 #ifndef SAE_H
10 #define SAE_H
11 
12 #define SAE_KCK_LEN 32
13 #define SAE_PMK_LEN 32
14 #define SAE_PMKID_LEN 16
15 #define SAE_KEYSEED_KEY_LEN 32
16 #define SAE_MAX_PRIME_LEN 512
17 #define SAE_MAX_ECC_PRIME_LEN 66
18 #define SAE_COMMIT_MAX_LEN (2 + 3 * SAE_MAX_PRIME_LEN)
19 #define SAE_CONFIRM_MAX_LEN (2 + SAE_MAX_PRIME_LEN)
20 
21 /* Special value returned by sae_parse_commit() */
22 #define SAE_SILENTLY_DISCARD 65535
23 
24 struct sae_temporary_data {
25 	u8 kck[SAE_KCK_LEN];
26 	struct crypto_bignum *own_commit_scalar;
27 	struct crypto_bignum *own_commit_element_ffc;
28 	struct crypto_ec_point *own_commit_element_ecc;
29 	struct crypto_bignum *peer_commit_element_ffc;
30 	struct crypto_ec_point *peer_commit_element_ecc;
31 	struct crypto_ec_point *pwe_ecc;
32 	struct crypto_bignum *pwe_ffc;
33 	struct crypto_bignum *sae_rand;
34 	struct crypto_ec *ec;
35 	int prime_len;
36 	int order_len;
37 	const struct dh_group *dh;
38 	const struct crypto_bignum *prime;
39 	const struct crypto_bignum *order;
40 	struct crypto_bignum *prime_buf;
41 	struct crypto_bignum *order_buf;
42 	struct wpabuf *anti_clogging_token;
43 	char *pw_id;
44 	int vlan_id;
45 	u8 bssid[ETH_ALEN];
46 };
47 
48 enum sae_state {
49 	SAE_NOTHING, SAE_COMMITTED, SAE_CONFIRMED, SAE_ACCEPTED
50 };
51 
52 struct sae_data {
53 	enum sae_state state;
54 	u16 send_confirm;
55 	u8 pmk[SAE_PMK_LEN];
56 	u8 pmkid[SAE_PMKID_LEN];
57 	struct crypto_bignum *peer_commit_scalar;
58 	int group;
59 	unsigned int sync; /* protocol instance variable: Sync */
60 	u16 rc; /* protocol instance variable: Rc (received send-confirm) */
61 	struct sae_temporary_data *tmp;
62 };
63 
64 int sae_set_group(struct sae_data *sae, int group);
65 void sae_clear_temp_data(struct sae_data *sae);
66 void sae_clear_data(struct sae_data *sae);
67 
68 int sae_prepare_commit(const u8 *addr1, const u8 *addr2,
69 		       const u8 *password, size_t password_len,
70 		       const char *identifier, struct sae_data *sae);
71 int sae_process_commit(struct sae_data *sae);
72 void sae_write_commit(struct sae_data *sae, struct wpabuf *buf,
73 		      const struct wpabuf *token, const char *identifier);
74 u16 sae_parse_commit(struct sae_data *sae, const u8 *data, size_t len,
75 		     const u8 **token, size_t *token_len, int *allowed_groups);
76 void sae_write_confirm(struct sae_data *sae, struct wpabuf *buf);
77 int sae_check_confirm(struct sae_data *sae, const u8 *data, size_t len);
78 u16 sae_group_allowed(struct sae_data *sae, int *allowed_groups, u16 group);
79 const char * sae_state_txt(enum sae_state state);
80 
81 #endif /* SAE_H */
82