Skip to content

Commit beda284

Browse files
Aditi-Lonkarespressif-bot
authored andcommitted
feat(esp_wifi): Add esp-idf specific changes
Added esp-idf implementation specific changes on top of the upstream updates.
1 parent fbde07c commit beda284

File tree

7 files changed

+356
-386
lines changed

7 files changed

+356
-386
lines changed

components/wpa_supplicant/esp_supplicant/src/crypto/crypto_mbedtls-ec.c

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -501,8 +501,8 @@ static struct crypto_ec_key *crypto_alloc_key(void)
501501
return (struct crypto_ec_key *)key;
502502
}
503503

504-
struct crypto_ec_key * crypto_ec_set_pubkey_point(const struct crypto_ec_group *group,
505-
const u8 *buf, size_t len)
504+
struct crypto_ec_key * crypto_ec_key_set_pub(const struct crypto_ec_group *group,
505+
const u8 *buf, size_t len)
506506
{
507507
mbedtls_ecp_point *point = NULL;
508508
struct crypto_ec_key *pkey = NULL;
@@ -557,13 +557,6 @@ struct crypto_ec_key * crypto_ec_set_pubkey_point(const struct crypto_ec_group *
557557
return pkey;
558558
}
559559

560-
void crypto_ec_free_key(struct crypto_ec_key *key)
561-
{
562-
mbedtls_pk_context *pkey = (mbedtls_pk_context *)key;
563-
mbedtls_pk_free(pkey);
564-
os_free(key);
565-
}
566-
567560
struct crypto_ec_point *crypto_ec_key_get_public_key(struct crypto_ec_key *key)
568561
{
569562
mbedtls_pk_context *pkey = (mbedtls_pk_context *)key;
@@ -820,44 +813,52 @@ int crypto_ecdsa_get_sign(unsigned char *hash,
820813
return ret;
821814
}
822815

823-
int crypto_edcsa_sign_verify(const unsigned char *hash,
824-
const struct crypto_bignum *r, const struct crypto_bignum *s, struct crypto_ec_key *csign, int hlen)
816+
int crypto_ec_key_verify_signature_r_s(struct crypto_ec_key *csign,
817+
const unsigned char *hash, int hlen,
818+
const u8 *r, size_t r_len,
819+
const u8 *s, size_t s_len)
825820
{
826821
/* (mbedtls_ecdsa_context *) */
827822
mbedtls_ecp_keypair *ecp_kp = mbedtls_pk_ec(*(mbedtls_pk_context *)csign);
828823
if (!ecp_kp) {
829824
return -1;
830825
}
831826

827+
struct crypto_bignum *rb = NULL, *sb = NULL;
828+
rb = crypto_bignum_init_set(r, r_len);
829+
sb = crypto_bignum_init_set(s, s_len);
830+
832831
mbedtls_ecp_group *ecp_kp_grp = &ecp_kp->MBEDTLS_PRIVATE(grp);
833832
mbedtls_ecp_point *ecp_kp_q = &ecp_kp->MBEDTLS_PRIVATE(Q);
834833
int ret = mbedtls_ecdsa_verify(ecp_kp_grp, hash, hlen,
835-
ecp_kp_q, (mbedtls_mpi *)r, (mbedtls_mpi *)s);
834+
ecp_kp_q, (mbedtls_mpi *)rb, (mbedtls_mpi *)sb);
836835
if (ret != 0) {
837836
wpa_printf(MSG_ERROR, "ecdsa verification failed");
837+
crypto_bignum_deinit(rb, 0);
838+
crypto_bignum_deinit(sb, 0);
838839
return ret;
839840
}
840841

841842
return ret;
842843
}
843844

844-
void crypto_ec_key_debug_print(const char *title, struct crypto_ec_key *key)
845+
void crypto_ec_key_debug_print(struct crypto_ec_key *key, const char *title)
845846
{
846847
#ifdef DEBUG_PRINT
847848
mbedtls_pk_context *pkey = (mbedtls_pk_context *)key;
848849
mbedtls_ecp_keypair *ecp = mbedtls_pk_ec(*pkey);
849850
u8 x[32], y[32], d[32];
850-
wpa_printf(MSG_ERROR, "curve: %s",
851+
wpa_printf(MSG_INFO, "curve: %s",
851852
mbedtls_ecp_curve_info_from_grp_id(ecp->MBEDTLS_PRIVATE(grp).id)->name);
852853
int len = mbedtls_mpi_size((mbedtls_mpi *)crypto_ec_get_prime((struct crypto_ec *)crypto_ec_get_group_from_key(key)));
853854

854-
wpa_printf(MSG_ERROR, "prime len is %d", len);
855+
wpa_printf(MSG_INFO, "prime len is %d", len);
855856
crypto_ec_point_to_bin((struct crypto_ec *)crypto_ec_get_group_from_key(key), crypto_ec_key_get_public_key(key), x, y);
856857
crypto_bignum_to_bin(crypto_ec_key_get_private_key(key),
857-
d, len, len);
858+
d, len, len);
858859
wpa_hexdump(MSG_INFO, "Q_x:", x, 32);
859860
wpa_hexdump(MSG_INFO, "Q_y:", y, 32);
860-
wpa_hexdump(MSG_INFO, "d: ", d , 32);
861+
wpa_hexdump(MSG_INFO, "d: ", d, 32);
861862
#endif
862863
}
863864

@@ -1036,6 +1037,23 @@ int crypto_ec_write_pub_key(struct crypto_ec_key *key, unsigned char **key_buf)
10361037
return len;
10371038
}
10381039

1040+
struct wpabuf * crypto_ec_key_get_subject_public_key(struct crypto_ec_key *key)
1041+
{
1042+
unsigned char *der = NULL;
1043+
struct wpabuf *ret = NULL;
1044+
int der_len;
1045+
1046+
der_len = crypto_ec_write_pub_key(key, &der);
1047+
if (!der) {
1048+
wpa_printf(MSG_ERROR, "failed to get der for bootstrapping key\n");
1049+
return NULL;
1050+
}
1051+
ret = wpabuf_alloc_copy(der, der_len);
1052+
1053+
os_free(der);
1054+
return ret;
1055+
}
1056+
10391057
int crypto_mbedtls_get_grp_id(int group)
10401058
{
10411059
switch (group) {
@@ -1188,7 +1206,7 @@ struct wpabuf * crypto_ecdh_set_peerkey(struct crypto_ecdh *ecdh, int inc_y,
11881206
os_memcpy(buf, px, len);
11891207
os_memcpy(buf + len, py, len);
11901208

1191-
pkey = crypto_ec_set_pubkey_point((struct crypto_ec_group*)ACCESS_ECDH(&ctx, grp), buf, len);
1209+
pkey = crypto_ec_key_set_pub((struct crypto_ec_group*)ACCESS_ECDH(&ctx, grp), buf, len);
11921210
if (!pkey) {
11931211
wpa_printf(MSG_ERROR, "Failed to set point for peer's public key");
11941212
goto cleanup;
@@ -1228,7 +1246,7 @@ struct wpabuf * crypto_ecdh_set_peerkey(struct crypto_ecdh *ecdh, int inc_y,
12281246
os_free(py);
12291247
os_free(buf);
12301248
os_free(secret);
1231-
crypto_ec_free_key(pkey);
1249+
crypto_ec_key_deinit(pkey);
12321250
crypto_bignum_deinit(bn_x, 1);
12331251
crypto_ec_point_deinit(ec_pt, 1);
12341252
mbedtls_ctr_drbg_free(&ctr_drbg);

components/wpa_supplicant/esp_supplicant/src/esp_dpp_i.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ int esp_supp_rx_action(uint8_t *hdr, uint8_t *payload, size_t len, uint8_t chann
5959
esp_err_t esp_dpp_post_evt(uint32_t evt_id, uint32_t data);
6060

6161
#ifdef CONFIG_TESTING_OPTIONS
62-
int dpp_test_gen_invalid_key(struct wpabuf *msg,
63-
const struct dpp_curve_params *curve);
62+
int dpp_test_gen_invalid_key(struct wpabuf *msg, const struct dpp_curve_params *curve);
6463
char * dpp_corrupt_connector_signature(const char *connector);
6564
#endif /* CONFIG_TESTING_OPTIONS */
6665

0 commit comments

Comments
 (0)