I am trying to run the example of generating a random string from MBEDTLS website , below is my code , before running this code I have done the following changes.
Set MBEDTLS_CONFIG_FILE to nrf_mbedtls_config_file.h , included the necessary library path i.e /external/mbedtls/include to the pre processor in SES Build Config
I got the error from mbedtls/config.h saying MBEDTLS_TIMING_C requires unix or windows , so I naively commented the MBEDTLS_CONFIG_C , and sunk the entropy collector , now my
mbedtls_entropy_init() returns MBEDTLS_ERR_ENTROPY_SOURCE_FAILED.
See my code below for generating random code : this one works just fine on my ESP8266 no problems with that I dont want to write large parts of my C code by appending specific nrf* apis.
mbedtls_entropy_context entropy;
mbedtls_entropy_init(&entropy); //Code is probably blown here
mbedtls_ctr_drbg_context ctr_drbg;
unsigned char *personalization = (unsigned char *)"bhavar kumavat";
mbedtls_ctr_drbg_init(&ctr_drbg);
const int size_of_buffer = 17;
unsigned char random_bucket[size_of_buffer];
unsigned char random_return_bucket[size_of_buffer];
memset(random_bucket, '\0', sizeof(unsigned char)*size_of_buffer);
memset(random_return_bucket, '\0', sizeof(unsigned char)*size_of_buffer);
int ret = mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy, (const unsigned char *)personalization, strlen((char *)personalization));
printf("Return Code %d\n",ret); // I get the notification here
if (ret == 0)
{
mbedtls_ctr_drbg_random(&ctr_drbg, random_bucket, sizeof(random_bucket));
for (register int counter = 0; counter < size_of_buffer; counter++)
{
random_return_bucket[counter] = RANGE_FUNCTION(random_bucket[counter]);
}
random_return_bucket[size_of_buffer] = '\0';
printf("generate_random_string : %s\n",random_return_bucket);
}
else{
printf( " failed\n ! mbedtls_ctr_drbg_init returned -0x%04x\n", -ret );
}
Let me know if someone can help me , thank you.
Let me also know if I cant use mbedtls the way I am using it in ESP8266 / ESP32 here in NRF52
I am new to Embedded Development but can compensate it with excitement to learn :) ,
OS : Ubuntu 18.04
IDE : SES
Project Template : Blinky Project
CMSIS Config : I did'nt touch it.