mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
examples: blufi: fix API usage for generating dhm secret
API usage for `mbedtls_dhm_calc_secret` was incorrect, fixed by providing correct RNG function pointer. This behavior was changed in mbedTLS-3.x update. Tested BluFi provisioning with this fix. Closes IDF-5796 Closes https://github.com/espressif/esp-idf/issues/9488
This commit is contained in:
parent
cdd50aff1a
commit
1e3bbd03de
@ -104,18 +104,25 @@ void blufi_dh_negotiate_data_handler(uint8_t *data, int len, uint8_t **output_da
|
|||||||
}
|
}
|
||||||
free(blufi_sec->dh_param);
|
free(blufi_sec->dh_param);
|
||||||
blufi_sec->dh_param = NULL;
|
blufi_sec->dh_param = NULL;
|
||||||
ret = mbedtls_dhm_make_public(&blufi_sec->dhm, (int) mbedtls_mpi_size( &blufi_sec->dhm.MBEDTLS_PRIVATE(P) ), blufi_sec->self_public_key, mbedtls_mpi_size( &blufi_sec->dhm.MBEDTLS_PRIVATE(P) ), myrand, NULL);
|
|
||||||
|
const int dhm_len = mbedtls_dhm_get_len(&blufi_sec->dhm);
|
||||||
|
ret = mbedtls_dhm_make_public(&blufi_sec->dhm, dhm_len, blufi_sec->self_public_key, dhm_len, myrand, NULL);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
BLUFI_ERROR("%s make public failed %d\n", __func__, ret);
|
BLUFI_ERROR("%s make public failed %d\n", __func__, ret);
|
||||||
btc_blufi_report_error(ESP_BLUFI_MAKE_PUBLIC_ERROR);
|
btc_blufi_report_error(ESP_BLUFI_MAKE_PUBLIC_ERROR);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
mbedtls_dhm_calc_secret( &blufi_sec->dhm,
|
ret = mbedtls_dhm_calc_secret( &blufi_sec->dhm,
|
||||||
blufi_sec->share_key,
|
blufi_sec->share_key,
|
||||||
SHARE_KEY_BIT_LEN,
|
SHARE_KEY_BIT_LEN,
|
||||||
&blufi_sec->share_len,
|
&blufi_sec->share_len,
|
||||||
NULL, NULL);
|
myrand, NULL);
|
||||||
|
if (ret) {
|
||||||
|
BLUFI_ERROR("%s mbedtls_dhm_calc_secret failed %d\n", __func__, ret);
|
||||||
|
btc_blufi_report_error(ESP_BLUFI_DH_PARAM_ERROR);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ret = mbedtls_md5(blufi_sec->share_key, blufi_sec->share_len, blufi_sec->psk);
|
ret = mbedtls_md5(blufi_sec->share_key, blufi_sec->share_len, blufi_sec->psk);
|
||||||
|
|
||||||
@ -129,7 +136,7 @@ void blufi_dh_negotiate_data_handler(uint8_t *data, int len, uint8_t **output_da
|
|||||||
|
|
||||||
/* alloc output data */
|
/* alloc output data */
|
||||||
*output_data = &blufi_sec->self_public_key[0];
|
*output_data = &blufi_sec->self_public_key[0];
|
||||||
*output_len = mbedtls_mpi_size( &blufi_sec->dhm.MBEDTLS_PRIVATE(P) );
|
*output_len = dhm_len;
|
||||||
*need_free = false;
|
*need_free = false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user