0

im trying to code a Diffie-Hellman key Exchange (client side) into a XMC4500 and I'm using ARMmbed lib.

This is the code I got (based on dh_client.c):

int dhm (void) {

int ret;
size_t n, buflen;

unsigned char *p, *end;
unsigned char buf[512];
unsigned char hash[32];
const char *pers = "dh_client";

mbedtls_entropy_context entropy;
mbedtls_ctr_drbg_context ctr_drbg;
mbedtls_rsa_context rsa;
mbedtls_dhm_context dhm;
mbedtls_aes_context aes;

mbedtls_rsa_init( &rsa, MBEDTLS_RSA_PKCS_V15, MBEDTLS_MD_SHA256 );
mbedtls_dhm_init( &dhm );
mbedtls_aes_init( &aes );
mbedtls_ctr_drbg_init( &ctr_drbg );

/*
 * 1. Setup the RNG
 */

mbedtls_entropy_init( &entropy );
ret = mbedtls_ctr_drbg_seed( &ctr_drbg,
                            mbedtls_entropy_func,
                            &entropy,
                            (const unsigned char *) pers,
                            strlen( pers ) );

mbedtls_aes_free( &aes );
mbedtls_rsa_free( &rsa );
mbedtls_dhm_free( &dhm );
mbedtls_ctr_drbg_free( &ctr_drbg );
mbedtls_entropy_free( &entropy );

return ret;}

I did not try to go further this, because it is not working and it is the very beginning of dhm algorithm. The function mbedtls_ctr_drbg_seed is returning MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED.

Also in the ctr_drbg.h I had to edit the MBEDTLS_CTR_DRBG_MAX_SEED_INPUT from 384(default) to 336, otherwise the code would crash. Everything else is default.

Someone knows why is returning this error? Thanks in advance.

Note: Im calling this function in main. Running the code gives me no errors.

Innat
  • 16,113
  • 6
  • 53
  • 101

1 Answers1

0

This error is returned when your entropy function(mbedtls_entropy_func) fails. Do you have an entropy source enabled? You probably don't have any strong entropy source configured in your platform, thus causing this failure.

Ron Eldor
  • 210
  • 1
  • 11