mirror of
https://github.com/espressif/esp-nimble.git
synced 2026-07-29 06:07:56 +00:00
ble_sm_alg.c: Added changes for mbedTLS v3.1.0 - Added MBEDTLS_PRIVATE for accessing private struct members wherever necessary - Added macros for version check for backward compatibility
This commit is contained in:
committed by
Abhinav Kudnar
parent
20c3ed12e3
commit
82c1ae72da
@@ -66,6 +66,20 @@ static struct trng_dev *g_trng;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Keep forward-compatibility with Mbed TLS 3.x.
|
||||
*
|
||||
* Direct access to fields of structures declared in public headers is no longer
|
||||
* supported. In Mbed TLS 3, the layout of structures is not considered part of
|
||||
* the stable API, and minor versions (3.1, 3.2, etc.) may add, remove, rename,
|
||||
* reorder or change the type of structure fields.
|
||||
*/
|
||||
#if (MBEDTLS_VERSION_NUMBER < 0x03000000)
|
||||
#ifndef MBEDTLS_PRIVATE
|
||||
#define MBEDTLS_PRIVATE(member) member
|
||||
#endif
|
||||
#endif
|
||||
|
||||
static void
|
||||
ble_sm_alg_xor_128(const uint8_t *p, const uint8_t *q, uint8_t *r)
|
||||
{
|
||||
@@ -534,15 +548,15 @@ ble_sm_alg_gen_dhkey(const uint8_t *peer_pub_key_x, const uint8_t *peer_pub_key_
|
||||
mbedtls_mpi_init(&z);
|
||||
|
||||
/* Below 3 steps are to validate public key on curve secp256r1 */
|
||||
if (mbedtls_ecp_group_load(&keypair.grp, MBEDTLS_ECP_DP_SECP256R1) != 0) {
|
||||
if (mbedtls_ecp_group_load(&keypair.MBEDTLS_PRIVATE(grp), MBEDTLS_ECP_DP_SECP256R1) != 0) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (mbedtls_ecp_point_read_binary(&keypair.grp, &pt, pub, 65) != 0) {
|
||||
if (mbedtls_ecp_point_read_binary(&keypair.MBEDTLS_PRIVATE(grp), &pt, pub, 65) != 0) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (mbedtls_ecp_check_pubkey(&keypair.grp, &pt) != 0) {
|
||||
if (mbedtls_ecp_check_pubkey(&keypair.MBEDTLS_PRIVATE(grp), &pt) != 0) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
@@ -553,7 +567,7 @@ ble_sm_alg_gen_dhkey(const uint8_t *peer_pub_key_x, const uint8_t *peer_pub_key_
|
||||
}
|
||||
|
||||
/* Prepare point Q from pub key */
|
||||
if (mbedtls_ecp_point_read_binary(&keypair.grp, &Q, pub, 65) != 0) {
|
||||
if (mbedtls_ecp_point_read_binary(&keypair.MBEDTLS_PRIVATE(grp), &Q, pub, 65) != 0) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
@@ -561,7 +575,7 @@ ble_sm_alg_gen_dhkey(const uint8_t *peer_pub_key_x, const uint8_t *peer_pub_key_
|
||||
goto exit;
|
||||
}
|
||||
|
||||
rc = mbedtls_ecdh_compute_shared(&keypair.grp, &z, &Q, &d,
|
||||
rc = mbedtls_ecdh_compute_shared(&keypair.MBEDTLS_PRIVATE(grp), &z, &Q, &d,
|
||||
mbedtls_ctr_drbg_random, &ctr_drbg);
|
||||
if (rc != 0) {
|
||||
goto exit;
|
||||
@@ -641,14 +655,14 @@ mbedtls_gen_keypair(uint8_t *public_key, uint8_t *private_key)
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (( rc = mbedtls_mpi_write_binary(&keypair.d, private_key, 32)) != 0) {
|
||||
if (( rc = mbedtls_mpi_write_binary(&keypair.MBEDTLS_PRIVATE(d), private_key, 32)) != 0) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
size_t olen = 0;
|
||||
uint8_t pub[65] = {0};
|
||||
|
||||
if ((rc = mbedtls_ecp_point_write_binary(&keypair.grp, &keypair.Q, MBEDTLS_ECP_PF_UNCOMPRESSED,
|
||||
if ((rc = mbedtls_ecp_point_write_binary(&keypair.MBEDTLS_PRIVATE(grp), &keypair.MBEDTLS_PRIVATE(Q), MBEDTLS_ECP_PF_UNCOMPRESSED,
|
||||
&olen, pub, 65)) != 0) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user