btstack_crypto: extract btstack_crypto_state_reset

This commit is contained in:
Matthias Ringwald 2022-06-02 09:47:30 +02:00
parent 6bc33c8be3
commit e4ccc1413c

View File

@ -1340,6 +1340,17 @@ void btstack_crypto_ccm_decrypt_block(btstack_crypto_ccm_t * request, uint16_t l
}
static void btstack_crypto_state_reset() {
#ifndef USE_BTSTACK_AES128
btstack_crypto_cmac_state = CMAC_IDLE;
#endif
#ifdef ENABLE_ECC_P256
btstack_crypto_ecc_p256_key_generation_state = ECC_P256_KEY_GENERATION_IDLE;
#endif
btstack_crypto_wait_for_hci_result = false;
btstack_crypto_operations = NULL;
}
void btstack_crypto_init(void){
if (btstack_crypto_initialized) return;
btstack_crypto_initialized = true;
@ -1347,23 +1358,19 @@ void btstack_crypto_init(void){
// register with HCI
hci_event_callback_registration.callback = &btstack_crypto_event_handler;
hci_add_event_handler(&hci_event_callback_registration);
#ifndef USE_BTSTACK_AES128
btstack_crypto_cmac_state = CMAC_IDLE;
#endif
#ifdef ENABLE_ECC_P256
btstack_crypto_ecc_p256_key_generation_state = ECC_P256_KEY_GENERATION_IDLE;
#endif
#ifdef USE_MBEDTLS_ECC_P256
mbedtls_ecp_group_init(&mbedtls_ec_group);
mbedtls_ecp_group_load(&mbedtls_ec_group, MBEDTLS_ECP_DP_SECP256R1);
#endif
// reset state
btstack_crypto_state_reset();
}
// De-Init
void btstack_crypto_deinit(void) {
btstack_crypto_initialized = false;
btstack_crypto_wait_for_hci_result = false;
btstack_crypto_operations = NULL;
}
// PTS only