I am attempting to add TRNG support to my project to generate 128 bit random numbers. I found the a code example and modified it slightly to compile, however it doesn't link:
int myRandomTest()
{
TRNG_Handle handle;
int_fast16_t result;
TRNG_init();
handle = TRNG_open(0, NULL);
if (!handle) {
// Handle error
return -1; // REVISIT
}
CryptoKeyPlaintext_initKey(&entropyKey, entropyBuffer, KEY_LENGTH_BYTES);
result = TRNG_generateEntropy(handle, &entropyKey);
if (result != TRNG_STATUS_SUCCESS) {
// Handle error
return -1; // REVISIT
}
TRNG_close(handle);
return 0;
}
I had to find the source code for CryptoKeyPlaintext_initKey() and add to my file as apparently the crytpoutils source code didn't automatically build.
The link issue is related to TRNG_count and TRNG_config symbols are not available and the link fails. However, the board file CC2640R2_LAUNCHXL.c contains TRNGCC26XX_config and the enum value CC2640R2_LAUNCHXL_TRNGCOUNT. The TRNG_config and TRNGCC26XX_config are identical declarations, just different names.
I can create the TRNG_count variable and assign it the value of CC2640R2_LAUNCHXL_TRNGCOUNT, but when I rename TRNGCC26XX_config to TRNG_config, the link still fails as it is expecting TRNGCC26XX_config to be defined.
Any examples of source code that can be used to generate a 128 bit random number would be appreciated.