mbedTLS ECJ-PAKE

Hi,
I am trying to implement the j-pake algorithm on nordic 52832 and using nordic SDK and mbed tls library. The crypto libraries are enabled and the code compiles without any error.

But the ecj-pake read round returns error -16. I tried running the ecj-pake selftest also and it also returns error -16. Below is the code snippet. The client and server are simulated on same board and simply feed the message buffer from write_round_1 to the read_round_1 function. The error comes from function mbedtls_mpi_grow()
if( ( p = (mbedtls_mpi_uint*)mbedtls_calloc( nblimbs, ciL ) ) == NULL )
return( MBEDTLS_ERR_MPI_ALLOC_FAILED );
I checked the nblimbs value and it is 8.

static const unsigned char ecjpake_secret = { 0x74, 0x68, 0x72, 0x65, 0x61, 0x64, 0x6a, 0x70, 0x61, 0x6b, 0x65, 0x74, 0x65, 0x73, 0x74 };
mbedtls_ecjpake_context ecjpake_client;
mbedtls_ecjpake_context ecjpake_server;

int main (){

int ret;
ret_code_t err_code = NRF_SUCCESS;
unsigned char msg_client [512], pms[32];
size_t msg_client_len,pmslen;
mbedtls_ctr_drbg_context ctr_drbg;
mbedtls_entropy_context entropy;

err_code = nrf_mem_init();
err_code = nrf_crypto_init();

mbedtls_ecjpake_init(&ecjpake_client);
mbedtls_ecjpake_init( &ecjpake_server );
mbedtls_ecjpake_setup( &ecjpake_client, MBEDTLS_ECJPAKE_CLIENT, MBEDTLS_MD_SHA256, MBEDTLS_ECP_DP_SECP256R1,
ecjpake_secret, sizeof( ecjpake_secret ));
mbedtls_ecjpake_setup( &ecjpake_server, MBEDTLS_ECJPAKE_SERVER, MBEDTLS_MD_SHA256, MBEDTLS_ECP_DP_SECP256R1, ecjpake_secret, sizeof( ecjpake_secret ));

ret = mbedtls_ecjpake_write_round_one( &ecjpake_client, msg_client, sizeof(msg_client ), &msg_client_len,
nrf_crypto_backend_mbedtls_ecc_mbedtls_rng, &ctr_drbg ) ;
ret = mbedtls_ecjpake_read_round_one( &ecjpake_server, msg_client, msg_client_len );
ret = mbedtls_ecjpake_write_round_one( &ecjpake_server, msg_client, sizeof( msg_client ), &msg_client_len,
nrf_crypto_backend_mbedtls_ecc_mbedtls_rng, &ctr_drbg);
ret = mbedtls_ecjpake_read_round_one( &ecjpake_client, msg_client, msg_client_len );

}

Can you help me to understand why this error coming. Are the steps followed correct or am I doing something wrong.

Thanks