Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nrf_crypto_init finds no backend in SDK15

Hi,

I have the problem, that nrf_crypto_init() does not find any backends and thus is skipping the initialization.

What is the precondition for NRF_CRYPTO_BACKEND_SECTION_ITEM_COUNT to find a backend?

I enabled NRF_CRYPTO_BACKEND_MICRO_ECC_ENABLED and NRF_CRYPTO_BACKEND_NRF_HW_RNG_ENABLED in the sdk_config.h.

I tried the ble_app_multirole_lesc example, where NRF_CRYPTO_BACKEND_OBERON_ENABLED and NRF_CRYPTO_BACKEND_NRF_HW_RNG_ENABLED are enabled.

This returns num_backends=1, but i don't know why this is not working for MicroEcc.

Also should nrf_crypto_init() really return NRF_SUCCESS in this case? It skips the entire initialization if num_backends = 0 but still sets m_state to INITIALIZED;

Best regards,

Niclas

Parents
  • Hi Niclas,

    Section variables are used to register init/uninit functions for backends that require initialization. Registration is done with the CRYPTO_BACKEND_REGISTER() macro. nrf_crypto_init() will then iterate through these and call the init functions that have been registered.

    uECC backend does not require initialization but the NRF HW RNG backend does so I would have expected the number of backends to be '1' in your case. Is nrf_hw_backend_init.c included in your project? This is where the init function gets registered. 

    Best regards,

    Vidar

Reply
  • Hi Niclas,

    Section variables are used to register init/uninit functions for backends that require initialization. Registration is done with the CRYPTO_BACKEND_REGISTER() macro. nrf_crypto_init() will then iterate through these and call the init functions that have been registered.

    uECC backend does not require initialization but the NRF HW RNG backend does so I would have expected the number of backends to be '1' in your case. Is nrf_hw_backend_init.c included in your project? This is where the init function gets registered. 

    Best regards,

    Vidar

Children
  • Hi Vidar,

    I don't use CRYPTO_BACKEND_REGISTER() directly and neither does the example, but including nrf_hw_backend_init.c  solved the error.

    Still it is offputting that the init function returns success in this case and neither compiler or linker report errors on the missing include. I had this same problem in SDK14 with the SOC_OBSERVER macro which also was only used inside the sdk and not in my application code.

    What is the intention behind macros used in sdk modules, that are essential to the functionality of those modules, just doing nothing if the right include is missing?

    EDIT: Also why is the legacy RNG required for all crypto functionality? Even the hw_backend_rng needs the legacy RNG.

    Best regards,

    Niclas

  • Hi Niclas,

    Glad to hear that it solved the problem.

    The Section variables documentation I linked to in my previous response summarizes the advantages of using this approach. However, I see your point, it would have been helpful to get an error at compile or link time if you had a missing dependency.

    Legacy RNG should not be required if you have enabled the HW RNG. Actually, it should not be possible to have more than one RNG backend enabled at a time. I did you see this in any of the nrf_crypto examples?

    Best regards,

    Vidar

  • Hi Vidar,

    the nrf_hw_backend_rng_mbedtls.c has the legacy rng included, so i have to add it to the Makefile to prevent compile errors. I didn't check if it was actually used in my case, but there are a lot of nrf_drv_rng functions used in that module.

    I also find no example in SDK15 using the new nrfx_rng module only some also using the legacy version.

    Best regards,

    Niclas

  • Hi Niclas,

    I thought we had a SW RNG for some reason, but we don't. So my previous comment does not make sense: "Legacy  (meant to say SW) RNG should not be required if you have enabled the HW RNG".

    Both nrfx_rng and nrf_drv_rng use the same RNG peripheral. 

    Best regards,

    Vidar

  • Hi Vidar,

    a colleague of yours pointed me in the right direction regarding this issue.

    It seems you have to delete the legacy defines completely from the sdk_config instead of just disabling them.

    Best regards,

    Niclas

Related