btstack_crypto: return 0xff..ff as DHKEY if public key is invalid for Controller ECC

This commit is contained in:
Matthias Ringwald 2023-09-06 09:40:58 +02:00
parent 506ad0bb7b
commit 9edc39914e
2 changed files with 8 additions and 2 deletions

View File

@ -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);

View File

@ -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
*/