blob: 7966d70e4e934e5df77c546358d1f95d1050fb31 [file] [log] [blame]
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001/*
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
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080015#define SAE_MAX_PRIME_LEN 512
16#define SAE_MAX_ECC_PRIME_LEN 66
Hai Shalomc3565922019-10-28 11:58:20 -070017#define SAE_MAX_HASH_LEN 64
18#define SAE_COMMIT_MAX_LEN (2 + 3 * SAE_MAX_PRIME_LEN + 255)
19#define SAE_CONFIRM_MAX_LEN (2 + SAE_MAX_HASH_LEN)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080020
Dmitry Shmidt41712582015-06-29 11:02:15 -070021/* Special value returned by sae_parse_commit() */
22#define SAE_SILENTLY_DISCARD 65535
23
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080024struct sae_temporary_data {
Hai Shalomc3565922019-10-28 11:58:20 -070025 u8 kck[SAE_MAX_HASH_LEN];
26 size_t kck_len;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080027 struct crypto_bignum *own_commit_scalar;
28 struct crypto_bignum *own_commit_element_ffc;
29 struct crypto_ec_point *own_commit_element_ecc;
30 struct crypto_bignum *peer_commit_element_ffc;
31 struct crypto_ec_point *peer_commit_element_ecc;
32 struct crypto_ec_point *pwe_ecc;
33 struct crypto_bignum *pwe_ffc;
34 struct crypto_bignum *sae_rand;
35 struct crypto_ec *ec;
36 int prime_len;
Hai Shalomc3565922019-10-28 11:58:20 -070037 int order_len;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080038 const struct dh_group *dh;
39 const struct crypto_bignum *prime;
40 const struct crypto_bignum *order;
41 struct crypto_bignum *prime_buf;
42 struct crypto_bignum *order_buf;
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -080043 struct wpabuf *anti_clogging_token;
Roshan Pius3a1667e2018-07-03 15:17:14 -070044 char *pw_id;
Hai Shalom021b0b52019-04-10 11:17:58 -070045 int vlan_id;
46 u8 bssid[ETH_ALEN];
Hai Shalomc3565922019-10-28 11:58:20 -070047 struct wpabuf *own_rejected_groups;
48 struct wpabuf *peer_rejected_groups;
49 unsigned int h2e:1;
50 unsigned int own_addr_higher:1;
51};
52
53struct sae_pt {
54 struct sae_pt *next;
55 int group;
56 struct crypto_ec *ec;
57 struct crypto_ec_point *ecc_pt;
58
59 const struct dh_group *dh;
60 struct crypto_bignum *ffc_pt;
Roshan Pius3a1667e2018-07-03 15:17:14 -070061};
62
63enum sae_state {
64 SAE_NOTHING, SAE_COMMITTED, SAE_CONFIRMED, SAE_ACCEPTED
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080065};
66
67struct sae_data {
Roshan Pius3a1667e2018-07-03 15:17:14 -070068 enum sae_state state;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080069 u16 send_confirm;
70 u8 pmk[SAE_PMK_LEN];
Dmitry Shmidtd97138d2015-12-28 13:27:49 -080071 u8 pmkid[SAE_PMKID_LEN];
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080072 struct crypto_bignum *peer_commit_scalar;
Hai Shalomfdcde762020-04-02 11:19:20 -070073 struct crypto_bignum *peer_commit_scalar_accepted;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080074 int group;
Roshan Pius3a1667e2018-07-03 15:17:14 -070075 unsigned int sync; /* protocol instance variable: Sync */
76 u16 rc; /* protocol instance variable: Rc (received send-confirm) */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080077 struct sae_temporary_data *tmp;
78};
79
80int sae_set_group(struct sae_data *sae, int group);
81void sae_clear_temp_data(struct sae_data *sae);
82void sae_clear_data(struct sae_data *sae);
83
84int sae_prepare_commit(const u8 *addr1, const u8 *addr2,
85 const u8 *password, size_t password_len,
Roshan Pius3a1667e2018-07-03 15:17:14 -070086 const char *identifier, struct sae_data *sae);
Hai Shalomc3565922019-10-28 11:58:20 -070087int sae_prepare_commit_pt(struct sae_data *sae, const struct sae_pt *pt,
88 const u8 *addr1, const u8 *addr2,
89 int *rejected_groups);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080090int sae_process_commit(struct sae_data *sae);
Hai Shalomfdcde762020-04-02 11:19:20 -070091int sae_write_commit(struct sae_data *sae, struct wpabuf *buf,
92 const struct wpabuf *token, const char *identifier);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080093u16 sae_parse_commit(struct sae_data *sae, const u8 *data, size_t len,
Hai Shalomc3565922019-10-28 11:58:20 -070094 const u8 **token, size_t *token_len, int *allowed_groups,
95 int h2e);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080096void sae_write_confirm(struct sae_data *sae, struct wpabuf *buf);
97int sae_check_confirm(struct sae_data *sae, const u8 *data, size_t len);
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -080098u16 sae_group_allowed(struct sae_data *sae, int *allowed_groups, u16 group);
Roshan Pius3a1667e2018-07-03 15:17:14 -070099const char * sae_state_txt(enum sae_state state);
Hai Shalomc3565922019-10-28 11:58:20 -0700100struct sae_pt * sae_derive_pt(int *groups, const u8 *ssid, size_t ssid_len,
101 const u8 *password, size_t password_len,
102 const char *identifier);
103struct crypto_ec_point *
104sae_derive_pwe_from_pt_ecc(const struct sae_pt *pt,
105 const u8 *addr1, const u8 *addr2);
106struct crypto_bignum *
107sae_derive_pwe_from_pt_ffc(const struct sae_pt *pt,
108 const u8 *addr1, const u8 *addr2);
109void sae_deinit_pt(struct sae_pt *pt);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800110
111#endif /* SAE_H */