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

Integrating ecdh example into my ble project based on s132

I am trying to use functions of ecdh example in my softdevice based project.

 

err_code = nrf_crypto_ecc_key_pair_generate(NULL,
                                            &g_nrf_crypto_ecc_secp256r1_curve_info,
                                            &m_bob_private_key,
                                            &bob_public_key);
 

key generator function you see below crashes my application. Firstly I have tried to debug with Keil but it gave "softdevice assertion error" which I think is not about the bug, the debugging itself. So I have done something different to debug it, I looked into function and went through SDK files, and finally, I see that "nrf_crypto_rng_vector_generate" function makes the application crashed (When I make this line comment, it is not crashed)

After seeing this, in order to look what's going on, I write code and directly used "nrf_crypto_rng_vector_generate" on my main code. And used APP_ERROR_CHECK for investigating whats it throwing.

#define VECTOR_LENGTH 10
uint8_t m_random_vector[VECTOR_LENGTH];            // Result buffer.
uint8_t m_min[VECTOR_LENGTH] = {0x00, 0x00, 0xFF}; // Lower bound as big-endian.
uint8_t m_max[VECTOR_LENGTH] = {0x00, 0xFF, 0xFF}; // Upper bound as big-endian.

// Generate a random vector of specified length.
ret_code_t ret_val;
ret_val = nrf_crypto_rng_vector_generate(m_random_vector, VECTOR_LENGTH);
APP_ERROR_CHECK(ret_val);

Then I used J-Link RTT viewer, for getting error code, it returns 34050 which is an unknown error code. 

Then I've tried to use "random_vector_generate" function placed in nrf_drv_rng.c for knowing whether it is a pure softdevice problem or not, and then it worked. So i think it is possible to use rng module while softdevice running. But I don't know and can't found something about whether the crypto library can be used with softdevice or not. Please help.

Softdevice that I use: s132_nrf52_6.1.1

SDK : nRF5_SDK_15.2.0

Parents
  • The error code 34050 means:

    #define NRF_ERROR_CRYPTO_CONTEXT_NOT_INITIALIZED    (NRF_ERROR_CRYPTO_ERR_BASE + 0x02)      /**< The context was not initialized prior to this call or it was corrupted. Call the corresponding init function for the algorithm to initialize it. */

    Also, if you want to use the RNG peripheral, then you need to use the softdevice api to fetch RNG values, you can't use the RNG peripheral directly when the softdevice is enabled.

  • Also, if you want to use the RNG peripheral, then you need to use the softdevice api to fetch RNG values, you can't use the RNG peripheral directly when the softdevice is enabled.

    I get that I can't use methods from ecdh or any other crypto example. Should I use cryptocell API  for implementing a diffie hellman application? And an additional question, I see that all example projects placed on SDK files are designed for non-softdevice systems, is it true? Is there a place that I can find examples for usage of crypto API on softdevice?

    Thanks.

  • I believe there are a few BLE peripheral examples that support LESC:

    \nRF5_SDK_15.3.0_59ac345\examples\ble_peripheral\experimental\ble_app_hids_keyboard_pairing_nfc

    \nRF5_SDK_15.3.0_59ac345\examples\ble_peripheral\experimental\ble_app_hrs_nfc_pairing 

    If you set NFC_PAIRING_MODE to NFC_PAIRING_MODE_LESC_JUST_WORKS it will handle LESC bonding. The actual crypto backend is configured through sdk_config.h.

    Best regards,
    Kenneth

Reply
  • I believe there are a few BLE peripheral examples that support LESC:

    \nRF5_SDK_15.3.0_59ac345\examples\ble_peripheral\experimental\ble_app_hids_keyboard_pairing_nfc

    \nRF5_SDK_15.3.0_59ac345\examples\ble_peripheral\experimental\ble_app_hrs_nfc_pairing 

    If you set NFC_PAIRING_MODE to NFC_PAIRING_MODE_LESC_JUST_WORKS it will handle LESC bonding. The actual crypto backend is configured through sdk_config.h.

    Best regards,
    Kenneth

Children
No Data
Related