xref: /freebsd/contrib/wpa/src/common/dpp_i.h (revision 1349891a0eed79625faafa5ad354d65ff9ea6012)
1 /*
2  * DPP module internal definitions
3  * Copyright (c) 2017, Qualcomm Atheros, Inc.
4  * Copyright (c) 2018-2020, The Linux Foundation
5  *
6  * This software may be distributed under the terms of the BSD license.
7  * See README for more details.
8  */
9 
10 #ifndef DPP_I_H
11 #define DPP_I_H
12 
13 #ifdef CONFIG_DPP
14 
15 struct dpp_global {
16 	void *msg_ctx;
17 	struct dl_list bootstrap; /* struct dpp_bootstrap_info */
18 	struct dl_list configurator; /* struct dpp_configurator */
19 #ifdef CONFIG_DPP2
20 	struct dl_list controllers; /* struct dpp_relay_controller */
21 	struct dpp_controller *controller;
22 	struct dl_list tcp_init; /* struct dpp_connection */
23 	void *cb_ctx;
24 	int (*process_conf_obj)(void *ctx, struct dpp_authentication *auth);
25 	void (*remove_bi)(void *ctx, struct dpp_bootstrap_info *bi);
26 #endif /* CONFIG_DPP2 */
27 };
28 
29 /* dpp.c */
30 
31 void dpp_build_attr_status(struct wpabuf *msg, enum dpp_status_error status);
32 void dpp_build_attr_r_bootstrap_key_hash(struct wpabuf *msg, const u8 *hash);
33 unsigned int dpp_next_id(struct dpp_global *dpp);
34 struct wpabuf * dpp_build_conn_status(enum dpp_status_error result,
35 				      const u8 *ssid, size_t ssid_len,
36 				      const char *channel_list);
37 struct json_token * dpp_parse_own_connector(const char *own_connector);
38 int dpp_connector_match_groups(struct json_token *own_root,
39 			       struct json_token *peer_root, bool reconfig);
40 int dpp_build_jwk(struct wpabuf *buf, const char *name, EVP_PKEY *key,
41 		  const char *kid, const struct dpp_curve_params *curve);
42 EVP_PKEY * dpp_parse_jwk(struct json_token *jwk,
43 			 const struct dpp_curve_params **key_curve);
44 int dpp_prepare_channel_list(struct dpp_authentication *auth,
45 			     unsigned int neg_freq,
46 			     struct hostapd_hw_modes *own_modes, u16 num_modes);
47 void dpp_auth_fail(struct dpp_authentication *auth, const char *txt);
48 int dpp_gen_uri(struct dpp_bootstrap_info *bi);
49 void dpp_write_adv_proto(struct wpabuf *buf);
50 void dpp_write_gas_query(struct wpabuf *buf, struct wpabuf *query);
51 
52 /* dpp_backup.c */
53 
54 void dpp_free_asymmetric_key(struct dpp_asymmetric_key *key);
55 struct wpabuf * dpp_build_enveloped_data(struct dpp_authentication *auth);
56 int dpp_conf_resp_env_data(struct dpp_authentication *auth,
57 			   const u8 *env_data, size_t env_data_len);
58 
59 /* dpp_crypto.c */
60 
61 struct dpp_signed_connector_info {
62 	unsigned char *payload;
63 	size_t payload_len;
64 };
65 
66 enum dpp_status_error
67 dpp_process_signed_connector(struct dpp_signed_connector_info *info,
68 			     EVP_PKEY *csign_pub, const char *connector);
69 enum dpp_status_error
70 dpp_check_signed_connector(struct dpp_signed_connector_info *info,
71 			   const u8 *csign_key, size_t csign_key_len,
72 			   const u8 *peer_connector, size_t peer_connector_len);
73 const struct dpp_curve_params * dpp_get_curve_name(const char *name);
74 const struct dpp_curve_params * dpp_get_curve_jwk_crv(const char *name);
75 const struct dpp_curve_params * dpp_get_curve_nid(int nid);
76 const struct dpp_curve_params * dpp_get_curve_ike_group(u16 group);
77 int dpp_bi_pubkey_hash(struct dpp_bootstrap_info *bi,
78 		       const u8 *data, size_t data_len);
79 struct wpabuf * dpp_get_pubkey_point(EVP_PKEY *pkey, int prefix);
80 EVP_PKEY * dpp_set_pubkey_point_group(const EC_GROUP *group,
81 				      const u8 *buf_x, const u8 *buf_y,
82 				      size_t len);
83 EVP_PKEY * dpp_set_pubkey_point(EVP_PKEY *group_key, const u8 *buf, size_t len);
84 int dpp_bn2bin_pad(const BIGNUM *bn, u8 *pos, size_t len);
85 int dpp_hkdf_expand(size_t hash_len, const u8 *secret, size_t secret_len,
86 		    const char *label, u8 *out, size_t outlen);
87 int dpp_hmac_vector(size_t hash_len, const u8 *key, size_t key_len,
88 		    size_t num_elem, const u8 *addr[], const size_t *len,
89 		    u8 *mac);
90 int dpp_ecdh(EVP_PKEY *own, EVP_PKEY *peer, u8 *secret, size_t *secret_len);
91 void dpp_debug_print_point(const char *title, const EC_GROUP *group,
92 			   const EC_POINT *point);
93 void dpp_debug_print_key(const char *title, EVP_PKEY *key);
94 int dpp_pbkdf2(size_t hash_len, const u8 *password, size_t password_len,
95 	       const u8 *salt, size_t salt_len, unsigned int iterations,
96 	       u8 *buf, size_t buflen);
97 int dpp_get_subject_public_key(struct dpp_bootstrap_info *bi,
98 			       const u8 *data, size_t data_len);
99 int dpp_bootstrap_key_hash(struct dpp_bootstrap_info *bi);
100 int dpp_keygen(struct dpp_bootstrap_info *bi, const char *curve,
101 	       const u8 *privkey, size_t privkey_len);
102 EVP_PKEY * dpp_set_keypair(const struct dpp_curve_params **curve,
103 			   const u8 *privkey, size_t privkey_len);
104 EVP_PKEY * dpp_gen_keypair(const struct dpp_curve_params *curve);
105 int dpp_derive_k1(const u8 *Mx, size_t Mx_len, u8 *k1, unsigned int hash_len);
106 int dpp_derive_k2(const u8 *Nx, size_t Nx_len, u8 *k2, unsigned int hash_len);
107 int dpp_derive_bk_ke(struct dpp_authentication *auth);
108 int dpp_gen_r_auth(struct dpp_authentication *auth, u8 *r_auth);
109 int dpp_gen_i_auth(struct dpp_authentication *auth, u8 *i_auth);
110 int dpp_auth_derive_l_responder(struct dpp_authentication *auth);
111 int dpp_auth_derive_l_initiator(struct dpp_authentication *auth);
112 int dpp_derive_pmk(const u8 *Nx, size_t Nx_len, u8 *pmk, unsigned int hash_len);
113 int dpp_derive_pmkid(const struct dpp_curve_params *curve,
114 		     EVP_PKEY *own_key, EVP_PKEY *peer_key, u8 *pmkid);
115 EC_POINT * dpp_pkex_derive_Qi(const struct dpp_curve_params *curve,
116 			      const u8 *mac_init, const char *code,
117 			      const char *identifier, BN_CTX *bnctx,
118 			      EC_GROUP **ret_group);
119 EC_POINT * dpp_pkex_derive_Qr(const struct dpp_curve_params *curve,
120 			      const u8 *mac_resp, const char *code,
121 			      const char *identifier, BN_CTX *bnctx,
122 			      EC_GROUP **ret_group);
123 int dpp_pkex_derive_z(const u8 *mac_init, const u8 *mac_resp,
124 		      const u8 *Mx, size_t Mx_len,
125 		      const u8 *Nx, size_t Nx_len,
126 		      const char *code,
127 		      const u8 *Kx, size_t Kx_len,
128 		      u8 *z, unsigned int hash_len);
129 int dpp_reconfig_derive_ke_responder(struct dpp_authentication *auth,
130 				     const u8 *net_access_key,
131 				     size_t net_access_key_len,
132 				     struct json_token *peer_net_access_key);
133 int dpp_reconfig_derive_ke_initiator(struct dpp_authentication *auth,
134 				     const u8 *r_proto, u16 r_proto_len,
135 				     struct json_token *net_access_key);
136 EC_POINT * dpp_decrypt_e_id(EVP_PKEY *ppkey, EVP_PKEY *a_nonce,
137 			    EVP_PKEY *e_prime_id);
138 char * dpp_sign_connector(struct dpp_configurator *conf,
139 			  const struct wpabuf *dppcon);
140 int dpp_test_gen_invalid_key(struct wpabuf *msg,
141 			     const struct dpp_curve_params *curve);
142 
143 struct dpp_reconfig_id {
144 	const EC_GROUP *group;
145 	EC_POINT *e_id; /* E-id */
146 	EVP_PKEY *csign;
147 	EVP_PKEY *a_nonce; /* A-NONCE */
148 	EVP_PKEY *e_prime_id; /* E'-id */
149 	EVP_PKEY *pp_key;
150 };
151 
152 /* dpp_tcp.c */
153 
154 void dpp_controller_conn_status_result_wait_timeout(void *eloop_ctx,
155 						    void *timeout_ctx);
156 void dpp_tcp_init_flush(struct dpp_global *dpp);
157 void dpp_relay_flush_controllers(struct dpp_global *dpp);
158 
159 #endif /* CONFIG_DPP */
160 #endif /* DPP_I_H */
161