AnsweredAssumed Answered

Why is the TRNG slow?

Question asked by Chris Cowdery on May 6, 2020
Latest reply on May 11, 2020 by Mark Butcher

I am using the TRNG to generate 16 secure keys, each one is 16 bytes long.

Although the TRNG is working fine in the sense that it does generate random keys, it takes about 10 seconds to generate these keys!!

My code is based on the example for fsl_trng.

 

Init is like this:

void BOARD_ConfigTRNG(void)    // random number generator
{
    trng_config_t trngConfig;    
    status_t status;    
    TRNG_GetDefaultConfig(&trngConfig);
    /* Set sample mode of the TRNG ring oscillator to Von Neumann, for better random data.
     * It is optional.*/
    trngConfig.sampleMode = kTRNG_SampleModeVonNeumann;
    trngConfig.frequencyCountLimit.maximum = TRNG_MAX_FREQUENCY;

 

    /* Initialize TRNG */
    status = TRNG_Init(TRNG, &trngConfig);
    if( kStatus_Success != status )
    {    
        zprintf(CRITICAL_IMPORTANCE, "Failed to start random number generator\r\n");
    }
}

 

And my loop to generate keys is this:

    zprintf(MEDIUM_IMPORTANCE,"Generating security keys...\r\n");
    for (i=0; i<MAX_NUMBER_OF_DEVICES; i++)
    {
        TRNG_GetRandomData(TRNG, SecurityKeys[i], 16);
    }
    zprintf(MEDIUM_IMPORTANCE,"Key generation complete\r\n");

 

Should this take 10 seconds?, what is wrong?


Thanks,

 

Chris.

Outcomes