Skip to content

Commit fbde07c

Browse files
Aditi-Lonkarespressif-bot
authored andcommitted
feat(esp_wifi): Replace crypto_key with crypto_ec_key
Replaced all occurances of crypto_key with crypto_ec_key struct to make the code more consistent with upstream.
1 parent cab4dc1 commit fbde07c

File tree

5 files changed

+91
-91
lines changed

5 files changed

+91
-91
lines changed

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

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ int crypto_ec_point_cmp(const struct crypto_ec *e,
453453
(const mbedtls_ecp_point *) b);
454454
}
455455

456-
int crypto_key_compare(struct crypto_key *key1, struct crypto_key *key2)
456+
int crypto_ec_key_compare(struct crypto_ec_key *key1, struct crypto_ec_key *key2)
457457
{
458458
int ret = 0;
459459
mbedtls_entropy_context entropy;
@@ -488,7 +488,7 @@ void crypto_debug_print_point(const char *title, struct crypto_ec *e,
488488
wpa_hexdump(MSG_ERROR, "y:", y, 32);
489489
}
490490

491-
static struct crypto_key *crypto_alloc_key(void)
491+
static struct crypto_ec_key *crypto_alloc_key(void)
492492
{
493493
mbedtls_pk_context *key = os_malloc(sizeof(*key));
494494

@@ -498,14 +498,14 @@ static struct crypto_key *crypto_alloc_key(void)
498498
}
499499
mbedtls_pk_init(key);
500500

501-
return (struct crypto_key *)key;
501+
return (struct crypto_ec_key *)key;
502502
}
503503

504-
struct crypto_key * crypto_ec_set_pubkey_point(const struct crypto_ec_group *group,
504+
struct crypto_ec_key * crypto_ec_set_pubkey_point(const struct crypto_ec_group *group,
505505
const u8 *buf, size_t len)
506506
{
507507
mbedtls_ecp_point *point = NULL;
508-
struct crypto_key *pkey = NULL;
508+
struct crypto_ec_key *pkey = NULL;
509509
int ret;
510510
mbedtls_pk_context *key = (mbedtls_pk_context *)crypto_alloc_key();
511511
mbedtls_ecp_group *ecp_grp = (mbedtls_ecp_group *)group;
@@ -543,7 +543,7 @@ struct crypto_key * crypto_ec_set_pubkey_point(const struct crypto_ec_group *gro
543543
mbedtls_ecp_copy(&mbedtls_pk_ec(*key)->MBEDTLS_PRIVATE(Q), point);
544544
mbedtls_ecp_group_load(&mbedtls_pk_ec(*key)->MBEDTLS_PRIVATE(grp), ecp_grp->id);
545545

546-
pkey = (struct crypto_key *)key;
546+
pkey = (struct crypto_ec_key *)key;
547547
crypto_ec_point_deinit((struct crypto_ec_point *)point, 0);
548548
return pkey;
549549
fail:
@@ -557,21 +557,21 @@ struct crypto_key * crypto_ec_set_pubkey_point(const struct crypto_ec_group *gro
557557
return pkey;
558558
}
559559

560-
void crypto_ec_free_key(struct crypto_key *key)
560+
void crypto_ec_free_key(struct crypto_ec_key *key)
561561
{
562562
mbedtls_pk_context *pkey = (mbedtls_pk_context *)key;
563563
mbedtls_pk_free(pkey);
564564
os_free(key);
565565
}
566566

567-
struct crypto_ec_point *crypto_ec_key_get_public_key(struct crypto_key *key)
567+
struct crypto_ec_point *crypto_ec_key_get_public_key(struct crypto_ec_key *key)
568568
{
569569
mbedtls_pk_context *pkey = (mbedtls_pk_context *)key;
570570

571571
return (struct crypto_ec_point *)&mbedtls_pk_ec(*pkey)->MBEDTLS_PRIVATE(Q);
572572
}
573573

574-
int crypto_ec_get_priv_key_der(struct crypto_key *key, unsigned char **key_data, int *key_len)
574+
int crypto_ec_get_priv_key_der(struct crypto_ec_key *key, unsigned char **key_data, int *key_len)
575575
{
576576
mbedtls_pk_context *pkey = (mbedtls_pk_context *)key;
577577
char *der_data = os_malloc(ECP_PRV_DER_MAX_BYTES);
@@ -599,7 +599,7 @@ int crypto_ec_get_priv_key_der(struct crypto_key *key, unsigned char **key_data,
599599
return 0;
600600
}
601601

602-
struct crypto_ec_group *crypto_ec_get_group_from_key(struct crypto_key *key)
602+
struct crypto_ec_group *crypto_ec_get_group_from_key(struct crypto_ec_key *key)
603603
{
604604
mbedtls_pk_context *pkey = (mbedtls_pk_context *)key;
605605

@@ -614,14 +614,14 @@ int crypto_ec_key_group(struct crypto_ec_key *key)
614614
return iana_group;
615615
}
616616

617-
struct crypto_bignum *crypto_ec_key_get_private_key(struct crypto_key *key)
617+
struct crypto_bignum *crypto_ec_key_get_private_key(struct crypto_ec_key *key)
618618
{
619619
mbedtls_pk_context *pkey = (mbedtls_pk_context *)key;
620620

621621
return ((struct crypto_bignum *) & (mbedtls_pk_ec(*pkey)->MBEDTLS_PRIVATE(d)));
622622
}
623623

624-
int crypto_ec_get_publickey_buf(struct crypto_key *key, u8 *key_buf, int len)
624+
int crypto_ec_get_publickey_buf(struct crypto_ec_key *key, u8 *key_buf, int len)
625625
{
626626
mbedtls_pk_context *pkey = (mbedtls_pk_context *)key;
627627
unsigned char buf[MBEDTLS_MPI_MAX_SIZE + 10]; /* tag, length + MPI */
@@ -644,7 +644,7 @@ int crypto_ec_get_publickey_buf(struct crypto_key *key, u8 *key_buf, int len)
644644
return pk_len;
645645
}
646646

647-
int crypto_write_pubkey_der(struct crypto_key *key, unsigned char **key_buf)
647+
int crypto_write_pubkey_der(struct crypto_ec_key *key, unsigned char **key_buf)
648648
{
649649
unsigned char *buf = os_malloc(ECP_PUB_DER_MAX_BYTES);
650650

@@ -669,7 +669,7 @@ int crypto_write_pubkey_der(struct crypto_key *key, unsigned char **key_buf)
669669
return len;
670670
}
671671

672-
struct crypto_key *crypto_ec_key_parse_priv(const u8 *privkey, size_t privkey_len)
672+
struct crypto_ec_key *crypto_ec_key_parse_priv(const u8 *privkey, size_t privkey_len)
673673
{
674674
int ret;
675675
mbedtls_pk_context *kctx = (mbedtls_pk_context *)crypto_alloc_key();
@@ -685,7 +685,7 @@ struct crypto_key *crypto_ec_key_parse_priv(const u8 *privkey, size_t privkey_le
685685
goto fail;
686686
}
687687

688-
return (struct crypto_key *)kctx;
688+
return (struct crypto_ec_key *)kctx;
689689

690690
fail:
691691
mbedtls_pk_free(kctx);
@@ -728,7 +728,7 @@ int crypto_ec_get_curve_id(const struct crypto_ec_group *group)
728728
return (crypto_ec_get_mbedtls_to_nist_group_id(grp->id));
729729
}
730730

731-
int crypto_ecdh(struct crypto_key *key_own, struct crypto_key *key_peer,
731+
int crypto_ecdh(struct crypto_ec_key *key_own, struct crypto_ec_key *key_peer,
732732
u8 *secret, size_t *secret_len)
733733
{
734734
mbedtls_ecdh_context *ctx = NULL;
@@ -795,7 +795,7 @@ int crypto_ecdh(struct crypto_key *key_own, struct crypto_key *key_peer,
795795
}
796796

797797
int crypto_ecdsa_get_sign(unsigned char *hash,
798-
const struct crypto_bignum *r, const struct crypto_bignum *s, struct crypto_key *csign, int hash_len)
798+
const struct crypto_bignum *r, const struct crypto_bignum *s, struct crypto_ec_key *csign, int hash_len)
799799
{
800800
int ret = -1;
801801
mbedtls_pk_context *pkey = (mbedtls_pk_context *)csign;
@@ -821,7 +821,7 @@ int crypto_ecdsa_get_sign(unsigned char *hash,
821821
}
822822

823823
int crypto_edcsa_sign_verify(const unsigned char *hash,
824-
const struct crypto_bignum *r, const struct crypto_bignum *s, struct crypto_key *csign, int hlen)
824+
const struct crypto_bignum *r, const struct crypto_bignum *s, struct crypto_ec_key *csign, int hlen)
825825
{
826826
/* (mbedtls_ecdsa_context *) */
827827
mbedtls_ecp_keypair *ecp_kp = mbedtls_pk_ec(*(mbedtls_pk_context *)csign);
@@ -841,7 +841,7 @@ int crypto_edcsa_sign_verify(const unsigned char *hash,
841841
return ret;
842842
}
843843

844-
void crypto_ec_key_debug_print(const char *title, struct crypto_key *key)
844+
void crypto_ec_key_debug_print(const char *title, struct crypto_ec_key *key)
845845
{
846846
#ifdef DEBUG_PRINT
847847
mbedtls_pk_context *pkey = (mbedtls_pk_context *)key;
@@ -861,7 +861,7 @@ void crypto_ec_key_debug_print(const char *title, struct crypto_key *key)
861861
#endif
862862
}
863863

864-
struct crypto_key *crypto_ec_parse_subpub_key(const unsigned char *p, size_t len)
864+
struct crypto_ec_key *crypto_ec_parse_subpub_key(const unsigned char *p, size_t len)
865865
{
866866
int ret;
867867
mbedtls_pk_context *pkey = (mbedtls_pk_context *)crypto_alloc_key();
@@ -871,21 +871,21 @@ struct crypto_key *crypto_ec_parse_subpub_key(const unsigned char *p, size_t len
871871
}
872872
ret = mbedtls_pk_parse_subpubkey((unsigned char **)&p, p + len, pkey);
873873
if (ret == 0) {
874-
return (struct crypto_key *)pkey;
874+
return (struct crypto_ec_key *)pkey;
875875
}
876876

877877
mbedtls_pk_free(pkey);
878878
os_free(pkey);
879879
return NULL;
880880
}
881881

882-
int crypto_is_ec_key(struct crypto_key *key)
882+
int crypto_is_ec_key(struct crypto_ec_key *key)
883883
{
884884
int ret = mbedtls_pk_can_do((mbedtls_pk_context *)key, MBEDTLS_PK_ECKEY);
885885
return ret;
886886
}
887887

888-
struct crypto_key * crypto_ec_key_gen(u16 ike_group)
888+
struct crypto_ec_key * crypto_ec_key_gen(u16 ike_group)
889889
{
890890
mbedtls_pk_context *kctx = (mbedtls_pk_context *)crypto_alloc_key();
891891

@@ -902,7 +902,7 @@ struct crypto_key * crypto_ec_key_gen(u16 ike_group)
902902
mbedtls_ecp_gen_key(MBEDTLS_ECP_DP_SECP256R1, mbedtls_pk_ec(*kctx), //get this from argument
903903
crypto_rng_wrapper, NULL);
904904

905-
return (struct crypto_key *)kctx;
905+
return (struct crypto_ec_key *)kctx;
906906
fail:
907907
mbedtls_pk_free(kctx);
908908
os_free(kctx);
@@ -1018,7 +1018,7 @@ int crypto_pk_write_formatted_pubkey_der(mbedtls_pk_context *key, unsigned char
10181018
return ((int) len);
10191019
}
10201020

1021-
int crypto_ec_write_pub_key(struct crypto_key *key, unsigned char **key_buf)
1021+
int crypto_ec_write_pub_key(struct crypto_ec_key *key, unsigned char **key_buf)
10221022
{
10231023
unsigned char output_buf[1600] = {0};
10241024
int len = crypto_pk_write_formatted_pubkey_der((mbedtls_pk_context *)key, output_buf, 1600, 1);
@@ -1140,7 +1140,7 @@ struct wpabuf * crypto_ecdh_set_peerkey(struct crypto_ecdh *ecdh, int inc_y,
11401140
struct crypto_bignum *bn_x = NULL;
11411141
struct crypto_ec_point *ec_pt = NULL;
11421142
uint8_t *px = NULL, *py = NULL, *buf = NULL;
1143-
struct crypto_key *pkey = NULL;
1143+
struct crypto_ec_key *pkey = NULL;
11441144
struct wpabuf *sh_secret = NULL;
11451145
int secret_key = 0;
11461146

components/wpa_supplicant/src/common/dpp.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1730,7 +1730,7 @@ dpp_auth_req_rx(void *msg_ctx, u8 dpp_allowed_roles, int qr_mutual,
17301730
unsigned int curr_chan, const u8 *hdr, const u8 *attr_start,
17311731
size_t attr_len)
17321732
{
1733-
struct crypto_key *pi = NULL;
1733+
struct crypto_ec_key *pi = NULL;
17341734
size_t secret_len;
17351735
const u8 *addr[2];
17361736
size_t len[2];
@@ -2275,7 +2275,7 @@ struct wpabuf *
22752275
dpp_auth_resp_rx(struct dpp_authentication *auth, const u8 *hdr,
22762276
const u8 *attr_start, size_t attr_len)
22772277
{
2278-
struct crypto_key *pr;
2278+
struct crypto_ec_key *pr;
22792279
size_t secret_len;
22802280
const u8 *addr[2];
22812281
size_t len[2];
@@ -3203,7 +3203,7 @@ dpp_build_conf_start(struct dpp_authentication *auth,
32033203
return buf;
32043204
}
32053205

3206-
static int dpp_build_jwk(struct wpabuf *buf, const char *name, struct crypto_key *key,
3206+
static int dpp_build_jwk(struct wpabuf *buf, const char *name, struct crypto_ec_key *key,
32073207
const char *kid, const struct dpp_curve_params *curve)
32083208
{
32093209
struct wpabuf *pub;
@@ -3907,15 +3907,15 @@ static int dpp_parse_cred_legacy(struct dpp_config_obj *conf,
39073907
return 0;
39083908
}
39093909

3910-
static struct crypto_key * dpp_parse_jwk(struct json_token *jwk,
3910+
static struct crypto_ec_key * dpp_parse_jwk(struct json_token *jwk,
39113911
const struct dpp_curve_params **key_curve)
39123912
{
39133913
struct json_token *token;
39143914
const struct dpp_curve_params *curve;
39153915
struct wpabuf *x = NULL, *y = NULL;
39163916
unsigned char *a = NULL;
39173917
struct crypto_ec_group *group;
3918-
struct crypto_key *pkey = NULL;
3918+
struct crypto_ec_key *pkey = NULL;
39193919
size_t len;
39203920

39213921
token = json_get_member(jwk, "kty");
@@ -4077,7 +4077,7 @@ static int dpp_parse_connector(struct dpp_authentication *auth,
40774077
{
40784078
struct json_token *root, *groups, *netkey, *token;
40794079
int ret = -1;
4080-
struct crypto_key *key = NULL;
4080+
struct crypto_ec_key *key = NULL;
40814081
const struct dpp_curve_params *curve;
40824082
unsigned int rules = 0;
40834083

@@ -4144,7 +4144,7 @@ static int dpp_parse_connector(struct dpp_authentication *auth,
41444144
goto fail;
41454145
dpp_debug_print_key("DPP: Received netAccessKey", key);
41464146

4147-
if (crypto_key_compare(key, auth->own_protocol_key) != 1) {
4147+
if (crypto_ec_key_compare(key, auth->own_protocol_key) != 1) {
41484148
wpa_printf(MSG_DEBUG,
41494149
"DPP: netAccessKey in connector does not match own protocol key");
41504150
#ifdef CONFIG_TESTING_OPTIONS
@@ -4166,7 +4166,7 @@ static int dpp_parse_connector(struct dpp_authentication *auth,
41664166
return ret;
41674167
}
41684168

4169-
static void dpp_copy_csign(struct dpp_config_obj *conf, struct crypto_key *csign)
4169+
static void dpp_copy_csign(struct dpp_config_obj *conf, struct crypto_ec_key *csign)
41704170
{
41714171
unsigned char *der = NULL;
41724172
int der_len;
@@ -4200,7 +4200,7 @@ static int dpp_parse_cred_dpp(struct dpp_authentication *auth,
42004200
struct dpp_signed_connector_info info;
42014201
struct json_token *token, *csign;
42024202
int ret = -1;
4203-
struct crypto_key *csign_pub = NULL;
4203+
struct crypto_ec_key *csign_pub = NULL;
42044204
const struct dpp_curve_params *key_curve = NULL;
42054205
const char *signed_connector;
42064206

@@ -4836,7 +4836,7 @@ dpp_peer_intro(struct dpp_introduction *intro, const char *own_connector,
48364836
struct json_token *root = NULL, *netkey, *token;
48374837
struct json_token *own_root = NULL;
48384838
enum dpp_status_error ret = 255, res;
4839-
struct crypto_key *own_key = NULL, *peer_key = NULL;
4839+
struct crypto_ec_key *own_key = NULL, *peer_key = NULL;
48404840
struct wpabuf *own_key_pub = NULL;
48414841
const struct dpp_curve_params *curve, *own_curve;
48424842
struct dpp_signed_connector_info info;

0 commit comments

Comments
 (0)