Error: mbedtls_ecdsa_genkey failed

Hello to all,

Below are the setup details I'm using:

  1. nRF52840 DevKit
  2. SDK: nRF5_SDK_for_Thread_and_Zigbee_v4.0.0_dc7186b
  3. Segger Embedded Studio 4.16

I am working on a project that requires srp to be implemented. I am using the attached code that uses mbed tls library. I am getting following error in the function mbedtls_ecdsa_genkey(). I am not able to debug the same. 

// Function to generate a key
int 
generate_key(srp_key_t * key)
{
    int status;
    char errbuf[64];
    if (srp_key_setup(key) < 0)
    {
        return -1;
    }

    const mbedtls_pk_info_t *key_type = mbedtls_pk_info_from_type(MBEDTLS_PK_ECKEY);

    if (key == NULL || key_type == NULL) {
        return -1;
    }
    
    if ((status = mbedtls_pk_setup(&key->key, key_type)) != 0) {
        mbedtls_strerror(status, errbuf, sizeof errbuf);
        ERROR("mbedtls_pk_setup failed: %s", errbuf);
    } else if ((status = mbedtls_ecdsa_genkey(mbedtls_pk_ec(key->key), MBEDTLS_ECP_DP_SECP256R1,
                                              mbedtls_ctr_drbg_random, &key->ctr)) != 0) {
        mbedtls_strerror(status, errbuf, sizeof errbuf);
        ERROR("mbedtls_ecdsa_genkey failed: %s", errbuf);
    } else {
        return 0;
    }

    srp_keypair_free(key);
    return -1;
}

mbedtls_ecdsa_genkey () returns with 1 and is stored in the the status, and also it prints the error string on debug terminal as  mbedtls_ecdsa_genkey failed: without the actual error message, please find the attached picture of the error message

I would appreciate any pointers to what I might be missing.

Kind regards,

Shivaprasad

Related