xref: /freebsd-src/contrib/wpa/src/common/dpp_i.h (revision a90b9d0159070121c221b966469c3e36d912bf82)
1c1d255d3SCy Schubert /*
2c1d255d3SCy Schubert  * DPP module internal definitions
3c1d255d3SCy Schubert  * Copyright (c) 2017, Qualcomm Atheros, Inc.
4c1d255d3SCy Schubert  * Copyright (c) 2018-2020, The Linux Foundation
5*a90b9d01SCy Schubert  * Copyright (c) 2021-2022, Qualcomm Innovation Center, Inc.
6c1d255d3SCy Schubert  *
7c1d255d3SCy Schubert  * This software may be distributed under the terms of the BSD license.
8c1d255d3SCy Schubert  * See README for more details.
9c1d255d3SCy Schubert  */
10c1d255d3SCy Schubert 
11c1d255d3SCy Schubert #ifndef DPP_I_H
12c1d255d3SCy Schubert #define DPP_I_H
13c1d255d3SCy Schubert 
14c1d255d3SCy Schubert #ifdef CONFIG_DPP
15c1d255d3SCy Schubert 
16c1d255d3SCy Schubert struct dpp_global {
17c1d255d3SCy Schubert 	void *msg_ctx;
18c1d255d3SCy Schubert 	struct dl_list bootstrap; /* struct dpp_bootstrap_info */
19c1d255d3SCy Schubert 	struct dl_list configurator; /* struct dpp_configurator */
20c1d255d3SCy Schubert #ifdef CONFIG_DPP2
21c1d255d3SCy Schubert 	struct dl_list controllers; /* struct dpp_relay_controller */
22*a90b9d01SCy Schubert 	struct dpp_relay_controller *tmp_controller;
23c1d255d3SCy Schubert 	struct dpp_controller *controller;
24c1d255d3SCy Schubert 	struct dl_list tcp_init; /* struct dpp_connection */
25*a90b9d01SCy Schubert 	int relay_sock;
26*a90b9d01SCy Schubert 	void *relay_msg_ctx;
27*a90b9d01SCy Schubert 	void *relay_cb_ctx;
28*a90b9d01SCy Schubert 	void (*relay_tx)(void *ctx, const u8 *addr, unsigned int freq,
29*a90b9d01SCy Schubert 			 const u8 *msg, size_t len);
30*a90b9d01SCy Schubert 	void (*relay_gas_resp_tx)(void *ctx, const u8 *addr, u8 dialog_token,
31*a90b9d01SCy Schubert 				  int prot, struct wpabuf *buf);
32c1d255d3SCy Schubert 	void *cb_ctx;
33c1d255d3SCy Schubert 	int (*process_conf_obj)(void *ctx, struct dpp_authentication *auth);
34*a90b9d01SCy Schubert 	bool (*tcp_msg_sent)(void *ctx, struct dpp_authentication *auth);
35c1d255d3SCy Schubert 	void (*remove_bi)(void *ctx, struct dpp_bootstrap_info *bi);
36c1d255d3SCy Schubert #endif /* CONFIG_DPP2 */
37c1d255d3SCy Schubert };
38c1d255d3SCy Schubert 
39c1d255d3SCy Schubert /* dpp.c */
40c1d255d3SCy Schubert 
41c1d255d3SCy Schubert void dpp_build_attr_status(struct wpabuf *msg, enum dpp_status_error status);
42c1d255d3SCy Schubert void dpp_build_attr_r_bootstrap_key_hash(struct wpabuf *msg, const u8 *hash);
43c1d255d3SCy Schubert unsigned int dpp_next_id(struct dpp_global *dpp);
44c1d255d3SCy Schubert struct wpabuf * dpp_build_conn_status(enum dpp_status_error result,
45c1d255d3SCy Schubert 				      const u8 *ssid, size_t ssid_len,
46c1d255d3SCy Schubert 				      const char *channel_list);
47c1d255d3SCy Schubert struct json_token * dpp_parse_own_connector(const char *own_connector);
48c1d255d3SCy Schubert int dpp_connector_match_groups(struct json_token *own_root,
49c1d255d3SCy Schubert 			       struct json_token *peer_root, bool reconfig);
504b72b91aSCy Schubert int dpp_build_jwk(struct wpabuf *buf, const char *name,
514b72b91aSCy Schubert 		  struct crypto_ec_key *key, const char *kid,
524b72b91aSCy Schubert 		  const struct dpp_curve_params *curve);
534b72b91aSCy Schubert struct crypto_ec_key * dpp_parse_jwk(struct json_token *jwk,
54c1d255d3SCy Schubert 				     const struct dpp_curve_params **key_curve);
55c1d255d3SCy Schubert int dpp_prepare_channel_list(struct dpp_authentication *auth,
56c1d255d3SCy Schubert 			     unsigned int neg_freq,
57c1d255d3SCy Schubert 			     struct hostapd_hw_modes *own_modes, u16 num_modes);
58c1d255d3SCy Schubert void dpp_auth_fail(struct dpp_authentication *auth, const char *txt);
59c1d255d3SCy Schubert int dpp_gen_uri(struct dpp_bootstrap_info *bi);
60c1d255d3SCy Schubert void dpp_write_adv_proto(struct wpabuf *buf);
61c1d255d3SCy Schubert void dpp_write_gas_query(struct wpabuf *buf, struct wpabuf *query);
62c1d255d3SCy Schubert 
63c1d255d3SCy Schubert /* dpp_backup.c */
64c1d255d3SCy Schubert 
65c1d255d3SCy Schubert void dpp_free_asymmetric_key(struct dpp_asymmetric_key *key);
66c1d255d3SCy Schubert struct wpabuf * dpp_build_enveloped_data(struct dpp_authentication *auth);
67c1d255d3SCy Schubert int dpp_conf_resp_env_data(struct dpp_authentication *auth,
68c1d255d3SCy Schubert 			   const u8 *env_data, size_t env_data_len);
69c1d255d3SCy Schubert 
70c1d255d3SCy Schubert /* dpp_crypto.c */
71c1d255d3SCy Schubert 
72c1d255d3SCy Schubert struct dpp_signed_connector_info {
73c1d255d3SCy Schubert 	unsigned char *payload;
74c1d255d3SCy Schubert 	size_t payload_len;
75c1d255d3SCy Schubert };
76c1d255d3SCy Schubert 
77c1d255d3SCy Schubert enum dpp_status_error
78c1d255d3SCy Schubert dpp_process_signed_connector(struct dpp_signed_connector_info *info,
794b72b91aSCy Schubert 			     struct crypto_ec_key *csign_pub,
804b72b91aSCy Schubert 			     const char *connector);
81c1d255d3SCy Schubert enum dpp_status_error
82c1d255d3SCy Schubert dpp_check_signed_connector(struct dpp_signed_connector_info *info,
83c1d255d3SCy Schubert 			   const u8 *csign_key, size_t csign_key_len,
84c1d255d3SCy Schubert 			   const u8 *peer_connector, size_t peer_connector_len);
85c1d255d3SCy Schubert const struct dpp_curve_params * dpp_get_curve_name(const char *name);
86c1d255d3SCy Schubert const struct dpp_curve_params * dpp_get_curve_jwk_crv(const char *name);
87c1d255d3SCy Schubert const struct dpp_curve_params * dpp_get_curve_ike_group(u16 group);
88c1d255d3SCy Schubert int dpp_bi_pubkey_hash(struct dpp_bootstrap_info *bi,
89c1d255d3SCy Schubert 		       const u8 *data, size_t data_len);
904b72b91aSCy Schubert struct crypto_ec_key * dpp_set_pubkey_point(struct crypto_ec_key *group_key,
914b72b91aSCy Schubert 					    const u8 *buf, size_t len);
92c1d255d3SCy Schubert int dpp_hkdf_expand(size_t hash_len, const u8 *secret, size_t secret_len,
93c1d255d3SCy Schubert 		    const char *label, u8 *out, size_t outlen);
94c1d255d3SCy Schubert int dpp_hmac_vector(size_t hash_len, const u8 *key, size_t key_len,
95c1d255d3SCy Schubert 		    size_t num_elem, const u8 *addr[], const size_t *len,
96c1d255d3SCy Schubert 		    u8 *mac);
974b72b91aSCy Schubert int dpp_ecdh(struct crypto_ec_key *own, struct crypto_ec_key *peer,
984b72b91aSCy Schubert 	     u8 *secret, size_t *secret_len);
994b72b91aSCy Schubert void dpp_debug_print_key(const char *title, struct crypto_ec_key *key);
100c1d255d3SCy Schubert int dpp_pbkdf2(size_t hash_len, const u8 *password, size_t password_len,
101c1d255d3SCy Schubert 	       const u8 *salt, size_t salt_len, unsigned int iterations,
102c1d255d3SCy Schubert 	       u8 *buf, size_t buflen);
103c1d255d3SCy Schubert int dpp_get_subject_public_key(struct dpp_bootstrap_info *bi,
104c1d255d3SCy Schubert 			       const u8 *data, size_t data_len);
105c1d255d3SCy Schubert int dpp_bootstrap_key_hash(struct dpp_bootstrap_info *bi);
106c1d255d3SCy Schubert int dpp_keygen(struct dpp_bootstrap_info *bi, const char *curve,
107c1d255d3SCy Schubert 	       const u8 *privkey, size_t privkey_len);
1084b72b91aSCy Schubert struct crypto_ec_key * dpp_gen_keypair(const struct dpp_curve_params *curve);
109c1d255d3SCy Schubert int dpp_derive_k1(const u8 *Mx, size_t Mx_len, u8 *k1, unsigned int hash_len);
110c1d255d3SCy Schubert int dpp_derive_k2(const u8 *Nx, size_t Nx_len, u8 *k2, unsigned int hash_len);
111c1d255d3SCy Schubert int dpp_derive_bk_ke(struct dpp_authentication *auth);
112c1d255d3SCy Schubert int dpp_gen_r_auth(struct dpp_authentication *auth, u8 *r_auth);
113c1d255d3SCy Schubert int dpp_gen_i_auth(struct dpp_authentication *auth, u8 *i_auth);
114c1d255d3SCy Schubert int dpp_auth_derive_l_responder(struct dpp_authentication *auth);
115c1d255d3SCy Schubert int dpp_auth_derive_l_initiator(struct dpp_authentication *auth);
116c1d255d3SCy Schubert int dpp_derive_pmk(const u8 *Nx, size_t Nx_len, u8 *pmk, unsigned int hash_len);
117c1d255d3SCy Schubert int dpp_derive_pmkid(const struct dpp_curve_params *curve,
1184b72b91aSCy Schubert 		     struct crypto_ec_key *own_key,
1194b72b91aSCy Schubert 		     struct crypto_ec_key *peer_key, u8 *pmkid);
1204b72b91aSCy Schubert struct crypto_ec_point *
1214b72b91aSCy Schubert dpp_pkex_derive_Qi(const struct dpp_curve_params *curve, const u8 *mac_init,
122*a90b9d01SCy Schubert 		   const char *code, size_t code_len, const char *identifier,
1234b72b91aSCy Schubert 		   struct crypto_ec **ret_ec);
1244b72b91aSCy Schubert struct crypto_ec_point *
1254b72b91aSCy Schubert dpp_pkex_derive_Qr(const struct dpp_curve_params *curve, const u8 *mac_resp,
126*a90b9d01SCy Schubert 		   const char *code, size_t code_len, const char *identifier,
1274b72b91aSCy Schubert 		   struct crypto_ec **ret_ec);
128c1d255d3SCy Schubert int dpp_pkex_derive_z(const u8 *mac_init, const u8 *mac_resp,
12932a95656SCy Schubert 		      u8 ver_init, u8 ver_resp,
130c1d255d3SCy Schubert 		      const u8 *Mx, size_t Mx_len,
131c1d255d3SCy Schubert 		      const u8 *Nx, size_t Nx_len,
132*a90b9d01SCy Schubert 		      const char *code, size_t code_len,
133c1d255d3SCy Schubert 		      const u8 *Kx, size_t Kx_len,
134c1d255d3SCy Schubert 		      u8 *z, unsigned int hash_len);
135c1d255d3SCy Schubert int dpp_reconfig_derive_ke_responder(struct dpp_authentication *auth,
136c1d255d3SCy Schubert 				     const u8 *net_access_key,
137c1d255d3SCy Schubert 				     size_t net_access_key_len,
138c1d255d3SCy Schubert 				     struct json_token *peer_net_access_key);
139c1d255d3SCy Schubert int dpp_reconfig_derive_ke_initiator(struct dpp_authentication *auth,
140c1d255d3SCy Schubert 				     const u8 *r_proto, u16 r_proto_len,
141c1d255d3SCy Schubert 				     struct json_token *net_access_key);
1424b72b91aSCy Schubert struct crypto_ec_point * dpp_decrypt_e_id(struct crypto_ec_key *ppkey,
1434b72b91aSCy Schubert 					  struct crypto_ec_key *a_nonce,
1444b72b91aSCy Schubert 					  struct crypto_ec_key *e_prime_id);
145*a90b9d01SCy Schubert int dpp_derive_auth_i(struct dpp_authentication *auth, u8 *auth_i);
146c1d255d3SCy Schubert char * dpp_sign_connector(struct dpp_configurator *conf,
147c1d255d3SCy Schubert 			  const struct wpabuf *dppcon);
148c1d255d3SCy Schubert int dpp_test_gen_invalid_key(struct wpabuf *msg,
149c1d255d3SCy Schubert 			     const struct dpp_curve_params *curve);
150c1d255d3SCy Schubert 
151c1d255d3SCy Schubert struct dpp_reconfig_id {
1524b72b91aSCy Schubert 	struct crypto_ec *ec;
1534b72b91aSCy Schubert 	struct crypto_ec_point *e_id; /* E-id */
1544b72b91aSCy Schubert 	struct crypto_ec_key *csign;
1554b72b91aSCy Schubert 	struct crypto_ec_key *a_nonce; /* A-NONCE */
1564b72b91aSCy Schubert 	struct crypto_ec_key *e_prime_id; /* E'-id */
1574b72b91aSCy Schubert 	struct crypto_ec_key *pp_key;
158c1d255d3SCy Schubert };
159c1d255d3SCy Schubert 
160c1d255d3SCy Schubert /* dpp_tcp.c */
161c1d255d3SCy Schubert 
162c1d255d3SCy Schubert void dpp_controller_conn_status_result_wait_timeout(void *eloop_ctx,
163c1d255d3SCy Schubert 						    void *timeout_ctx);
164c1d255d3SCy Schubert void dpp_tcp_init_flush(struct dpp_global *dpp);
165c1d255d3SCy Schubert void dpp_relay_flush_controllers(struct dpp_global *dpp);
166c1d255d3SCy Schubert 
167c1d255d3SCy Schubert #endif /* CONFIG_DPP */
168c1d255d3SCy Schubert #endif /* DPP_I_H */
169