Hello:
We have a BLE application on an NRF52840 with SD 140 and SDK 1.5.3. Our device acts as a BLE peripheral with bonding and LESC, and we additionally use block level aes encryption at the application level for all incoming and outgoing characteristics. For encryption, we are using nrf_crypto_aes_crypt() for our encrypt/decrypt operations. We have observed a case when we are encrypting packet of data using nrf_crypto_aes_crypt() when an incoming encrypted write occurs, which interrupts (from the soft device) our encryption process with an attempt to decrypt the incoming packet, also using using nrf_crypto_aes_crypt(). The interrupting operation fails with NRF_ERROR_CRYPTO_BUSY because of a mutex and can never succeed because of the priority inversion condition that exists until we release back to the original encrypt operation.
What we've noted, however, is that when this occurs, the main loop's interrupted encryption also fails with NRF_ERROR_CRYPTO_BUSY for reasons we cannot describe. This failure should have been prevented when the interrupting decrypt call evaluates the mutex on lines 454/455 of cc310_backend_aes.c as far as we can tell. Is there something deeper that may cause a failure when we return from the interrupt context?
For now, our approach is to enter a critical region with sd_nvic_critical_region_enter/exit() for encryption operations which appears to prevent the issue. But we are concerned that the mutex in cc310_backend_aes.c isn't working or is somehow stomping on the main context's crypto operations, or we are otherwise masking a larger issue. Any advice for additional troubleshooting or mitigation would be appreciated.
Thanks
Dan