diff --git a/src/btstack_crypto.c b/src/btstack_crypto.c index 2f949dd99..f1f6f2ef1 100644 --- a/src/btstack_crypto.c +++ b/src/btstack_crypto.c @@ -1160,8 +1160,11 @@ static void btstack_crypto_event_handler(uint8_t packet_type, uint16_t cid, uint btstack_crypto_wait_for_hci_result = 0; if (hci_subevent_le_generate_dhkey_complete_get_status(packet)){ log_error("Generate DHKEY failed -> abort"); + // set DHKEY to 0xff..ff + memset(btstack_crypto_ec_p192->dhkey, 0xff, 32); + } else { + hci_subevent_le_generate_dhkey_complete_get_dhkey(packet, btstack_crypto_ec_p192->dhkey); } - hci_subevent_le_generate_dhkey_complete_get_dhkey(packet, btstack_crypto_ec_p192->dhkey); // done btstack_linked_list_pop(&btstack_crypto_operations); (*btstack_crypto_ec_p192->btstack_crypto.context_callback.callback)(btstack_crypto_ec_p192->btstack_crypto.context_callback.context); diff --git a/src/btstack_crypto.h b/src/btstack_crypto.h index 3d1065876..20b445449 100644 --- a/src/btstack_crypto.h +++ b/src/btstack_crypto.h @@ -206,6 +206,8 @@ void btstack_crypto_ecc_p256_generate_key(btstack_crypto_ecc_p256_t * request, u /** * Calculate Diffie-Hellman Key based on local private key and remote public key + * @note Bluetooth Core v5.1+ requires the Controller to return an error if the public key is invalid + * In this case, dhkey will be set to 0xff..ff * @param request * @param public_key (64 bytes) * @param dhkey (32 bytes) @@ -215,7 +217,8 @@ void btstack_crypto_ecc_p256_generate_key(btstack_crypto_ecc_p256_t * request, u void btstack_crypto_ecc_p256_calculate_dhkey(btstack_crypto_ecc_p256_t * request, const uint8_t * public_key, uint8_t * dhkey, void (* callback)(void * arg), void * callback_arg); /* - * Validate public key (not implemented for LE Controller ECC) + * Validate public key + * @note Not implemented for ECC in Controller. @see btstack_crypto_ecc_p256_calculate_dhkey * @param public_key (64 bytes) * @result 0 == valid */