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

Error using ecdh

I used sdk15.2.

The peripheral sends the public key to the central.I received an exception to public key processing.

code:

        case BLE_BITBUTTON_C_EVT_BITBOTTON_M_NOTIFICATION:
        {
#if NRF_CRYPTO_ENABLED
          static uint16_t uc=0;
          memcpy(&raw_public_key_bitButton[uc],p_bitButton_c_evt->params.bitButton_m.value,p_bitButton_c_evt->params.bitButton_m.len);
          uc=p_bitButton_c_evt->params.bitButton_m.len+uc;
          if(uc==64)
           {
            bob_step_2();
           }
#endif
        } break;

 

void bob_step_2()
{
    static nrf_crypto_ecc_public_key_t               alice_public_key;
    ret_code_t                                       err_code = NRF_SUCCESS;
    size_t                                           size;
  size=sizeof(raw_public_key_bitButton);
    err_code = nrf_crypto_ecc_public_key_from_raw(&g_nrf_crypto_ecc_secp256r1_curve_info,
                                                  &alice_public_key,
                                                  raw_public_key_bitButton,
                                                  size);
    DEMO_ERROR_CHECK(err_code);
    size = sizeof(m_shared_secret_bob);
    err_code = nrf_crypto_ecdh_compute(NULL,
                                       &m_bob_private_key,
                                       &alice_public_key,
                                       m_shared_secret_bob,
                                       &size);
    DEMO_ERROR_CHECK(err_code);
    print_hex("Bob's shared secret:   ", m_shared_secret_bob, size);
    err_code = nrf_crypto_ecc_public_key_free(&alice_public_key);
    DEMO_ERROR_CHECK(err_code);
}
log:
Log information stays here and no errors appear. The peripheral is also disconnected.
note:
I testd the central. 
Related