This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

allocation failed error using nrf_crypto_ecc_key_pair_generate

Hello,

In my application I use NRF52840 with SDK 16.0.0 and softdevice 7.0.1. I want to add ECDH algorithm to my project using ECDH example in the SDK, but nrf_crypto_ecc_key_pair_generate gets a runtime 0x8515 error code, which is defined as NRF_ERROR_CRYPTO_ALLOC_FAILED.

Is it caused by using  softdevice and ecc libraries together as mentioned here?

If so, is there any other way for me to add ECDH to my project without using timeslots, like any other library that I can use to generate ECDH keys, that doesn't have conflicts with softdevice?

thanks.

  • Hi,

    This issue is not related to the SoftDevice.

    nrf_crypto_ecc_key_pair_generate() returns NRF_ERROR_CRYPTO_ALLOC_FAILED when failing to allocate memory for the context, see this snippet:

        // Allocate context if not provided
        if (p_context == NULL && context_size > 0)
        {
            p_allocated_context = NRF_CRYPTO_ALLOC(context_size);
            VERIFY_TRUE(p_allocated_context != NULL, NRF_ERROR_CRYPTO_ALLOC_FAILED);
            p_context = p_allocated_context;
        }
    

    Unless you have a RAM constrained design, then simply allocating a static context and providing that with the call to nrf_crypto_ecc_key_pair_generate() is the simplest way to fix this and the method that makes most sense in most cases. If not, then how to handle this depend on which memory allocator you want to use with nrf_crypto, and how you have configured it.

Related