blob: 8f74353bebf76ba3985005c3f20cb1a33dc81762 [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
Sunil Ravi89eba102022-09-13 21:04:37 -070014#define SAE_PMK_LEN_MAX 64
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080015#define SAE_PMKID_LEN 16
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080016#define SAE_MAX_PRIME_LEN 512
17#define SAE_MAX_ECC_PRIME_LEN 66
Hai Shalomc3565922019-10-28 11:58:20 -070018#define SAE_MAX_HASH_LEN 64
19#define SAE_COMMIT_MAX_LEN (2 + 3 * SAE_MAX_PRIME_LEN + 255)
Hai Shalom899fcc72020-10-19 14:38:18 -070020#ifdef CONFIG_SAE_PK
21#define SAE_CONFIRM_MAX_LEN ((2 + SAE_MAX_HASH_LEN) + 1500)
22#else /* CONFIG_SAE_PK */
Hai Shalomc3565922019-10-28 11:58:20 -070023#define SAE_CONFIRM_MAX_LEN (2 + SAE_MAX_HASH_LEN)
Hai Shalom899fcc72020-10-19 14:38:18 -070024#endif /* CONFIG_SAE_PK */
25#define SAE_PK_M_LEN 16
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080026
Dmitry Shmidt41712582015-06-29 11:02:15 -070027/* Special value returned by sae_parse_commit() */
28#define SAE_SILENTLY_DISCARD 65535
29
Hai Shalom899fcc72020-10-19 14:38:18 -070030struct sae_pk {
31 struct wpabuf *m;
32 struct crypto_ec_key *key;
33 int group;
34 struct wpabuf *pubkey; /* DER encoded subjectPublicKey */
35#ifdef CONFIG_TESTING_OPTIONS
36 struct crypto_ec_key *sign_key_override;
37#endif /* CONFIG_TESTING_OPTIONS */
38};
39
40
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080041struct sae_temporary_data {
Hai Shalomc3565922019-10-28 11:58:20 -070042 u8 kck[SAE_MAX_HASH_LEN];
43 size_t kck_len;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080044 struct crypto_bignum *own_commit_scalar;
45 struct crypto_bignum *own_commit_element_ffc;
46 struct crypto_ec_point *own_commit_element_ecc;
47 struct crypto_bignum *peer_commit_element_ffc;
48 struct crypto_ec_point *peer_commit_element_ecc;
49 struct crypto_ec_point *pwe_ecc;
50 struct crypto_bignum *pwe_ffc;
51 struct crypto_bignum *sae_rand;
52 struct crypto_ec *ec;
53 int prime_len;
Hai Shalomc3565922019-10-28 11:58:20 -070054 int order_len;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080055 const struct dh_group *dh;
56 const struct crypto_bignum *prime;
57 const struct crypto_bignum *order;
58 struct crypto_bignum *prime_buf;
59 struct crypto_bignum *order_buf;
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -080060 struct wpabuf *anti_clogging_token;
Roshan Pius3a1667e2018-07-03 15:17:14 -070061 char *pw_id;
Sunil Ravi79e6c4f2025-01-04 00:47:06 +000062 char *parsed_pw_id;
Hai Shalom021b0b52019-04-10 11:17:58 -070063 int vlan_id;
64 u8 bssid[ETH_ALEN];
Hai Shalomc3565922019-10-28 11:58:20 -070065 struct wpabuf *own_rejected_groups;
66 struct wpabuf *peer_rejected_groups;
Hai Shalomc3565922019-10-28 11:58:20 -070067 unsigned int own_addr_higher:1;
Hai Shalom899fcc72020-10-19 14:38:18 -070068
69#ifdef CONFIG_SAE_PK
70 u8 kek[SAE_MAX_HASH_LEN];
71 size_t kek_len;
72 const struct sae_pk *ap_pk;
73 u8 own_addr[ETH_ALEN];
74 u8 peer_addr[ETH_ALEN];
75 u8 fingerprint[SAE_MAX_HASH_LEN];
76 size_t fingerprint_bytes;
77 size_t fingerprint_bits;
78 size_t lambda;
79 unsigned int sec;
80 u8 ssid[32];
81 size_t ssid_len;
82#ifdef CONFIG_TESTING_OPTIONS
83 bool omit_pk_elem;
84#endif /* CONFIG_TESTING_OPTIONS */
85#endif /* CONFIG_SAE_PK */
Sunil Ravi7f769292024-07-23 22:21:32 +000086
87 struct os_reltime disabled_until;
Hai Shalomc3565922019-10-28 11:58:20 -070088};
89
90struct sae_pt {
91 struct sae_pt *next;
92 int group;
93 struct crypto_ec *ec;
94 struct crypto_ec_point *ecc_pt;
95
96 const struct dh_group *dh;
97 struct crypto_bignum *ffc_pt;
Hai Shalom899fcc72020-10-19 14:38:18 -070098#ifdef CONFIG_SAE_PK
99 u8 ssid[32];
100 size_t ssid_len;
101#endif /* CONFIG_SAE_PK */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700102};
103
104enum sae_state {
105 SAE_NOTHING, SAE_COMMITTED, SAE_CONFIRMED, SAE_ACCEPTED
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800106};
107
108struct sae_data {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700109 enum sae_state state;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800110 u16 send_confirm;
Sunil Ravi89eba102022-09-13 21:04:37 -0700111 u8 pmk[SAE_PMK_LEN_MAX];
112 size_t pmk_len;
113 int akmp; /* WPA_KEY_MGMT_* used in key derivation */
114 u32 own_akm_suite_selector;
115 u32 peer_akm_suite_selector;
Dmitry Shmidtd97138d2015-12-28 13:27:49 -0800116 u8 pmkid[SAE_PMKID_LEN];
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800117 struct crypto_bignum *peer_commit_scalar;
Hai Shalomfdcde762020-04-02 11:19:20 -0700118 struct crypto_bignum *peer_commit_scalar_accepted;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800119 int group;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700120 unsigned int sync; /* protocol instance variable: Sync */
121 u16 rc; /* protocol instance variable: Rc (received send-confirm) */
Hai Shalom899fcc72020-10-19 14:38:18 -0700122 unsigned int h2e:1;
123 unsigned int pk:1;
Sunil Ravi79e6c4f2025-01-04 00:47:06 +0000124 unsigned int no_pw_id:1;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800125 struct sae_temporary_data *tmp;
126};
127
128int sae_set_group(struct sae_data *sae, int group);
129void sae_clear_temp_data(struct sae_data *sae);
130void sae_clear_data(struct sae_data *sae);
131
132int sae_prepare_commit(const u8 *addr1, const u8 *addr2,
133 const u8 *password, size_t password_len,
Hai Shaloma20dcd72022-02-04 13:43:00 -0800134 struct sae_data *sae);
Hai Shalomc3565922019-10-28 11:58:20 -0700135int sae_prepare_commit_pt(struct sae_data *sae, const struct sae_pt *pt,
136 const u8 *addr1, const u8 *addr2,
Hai Shalom899fcc72020-10-19 14:38:18 -0700137 int *rejected_groups, const struct sae_pk *pk);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800138int sae_process_commit(struct sae_data *sae);
Hai Shalomfdcde762020-04-02 11:19:20 -0700139int sae_write_commit(struct sae_data *sae, struct wpabuf *buf,
140 const struct wpabuf *token, const char *identifier);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800141u16 sae_parse_commit(struct sae_data *sae, const u8 *data, size_t len,
Hai Shalomc3565922019-10-28 11:58:20 -0700142 const u8 **token, size_t *token_len, int *allowed_groups,
Sunil Ravi38ad1ed2023-01-17 23:58:31 +0000143 int h2e, int *ie_offset);
Hai Shalom899fcc72020-10-19 14:38:18 -0700144int sae_write_confirm(struct sae_data *sae, struct wpabuf *buf);
Sunil Ravi38ad1ed2023-01-17 23:58:31 +0000145int sae_check_confirm(struct sae_data *sae, const u8 *data, size_t len,
146 int *ie_offset);
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800147u16 sae_group_allowed(struct sae_data *sae, int *allowed_groups, u16 group);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700148const char * sae_state_txt(enum sae_state state);
Hai Shalom899fcc72020-10-19 14:38:18 -0700149size_t sae_ecc_prime_len_2_hash_len(size_t prime_len);
150size_t sae_ffc_prime_len_2_hash_len(size_t prime_len);
Sunil Ravi79e6c4f2025-01-04 00:47:06 +0000151struct sae_pt * sae_derive_pt(const int *groups,
152 const u8 *ssid, size_t ssid_len,
Hai Shalomc3565922019-10-28 11:58:20 -0700153 const u8 *password, size_t password_len,
154 const char *identifier);
155struct crypto_ec_point *
156sae_derive_pwe_from_pt_ecc(const struct sae_pt *pt,
157 const u8 *addr1, const u8 *addr2);
158struct crypto_bignum *
159sae_derive_pwe_from_pt_ffc(const struct sae_pt *pt,
160 const u8 *addr1, const u8 *addr2);
161void sae_deinit_pt(struct sae_pt *pt);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800162
Hai Shalom899fcc72020-10-19 14:38:18 -0700163/* sae_pk.c */
164#ifdef CONFIG_SAE_PK
165bool sae_pk_valid_password(const char *pw);
166#else /* CONFIG_SAE_PK */
167static inline bool sae_pk_valid_password(const char *pw)
168{
169 return false;
170}
171#endif /* CONFIG_SAE_PK */
172char * sae_pk_base32_encode(const u8 *src, size_t len_bits);
173u8 * sae_pk_base32_decode(const char *src, size_t len, size_t *out_len);
174int sae_pk_set_password(struct sae_data *sae, const char *password);
175void sae_deinit_pk(struct sae_pk *pk);
176struct sae_pk * sae_parse_pk(const char *val);
177int sae_write_confirm_pk(struct sae_data *sae, struct wpabuf *buf);
178int sae_check_confirm_pk(struct sae_data *sae, const u8 *ies, size_t ies_len);
179int sae_hash(size_t hash_len, const u8 *data, size_t len, u8 *hash);
180u32 sae_pk_get_be19(const u8 *buf);
181void sae_pk_buf_shift_left_19(u8 *buf, size_t len);
182
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800183#endif /* SAE_H */