K82: performance of hw random generator

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

K82: performance of hw random generator

939 Views
EugeneHiihtaja
Senior Contributor I

Hello !

Do I measure right and performance of TRNG random generator is about 100 bytes per seconds ?

Bus clock - 60 Mhz.

Regards,

Eugene

0 Kudos
6 Replies

791 Views
mjbcswitzerland
Specialist V

Eugene

The True Random Number Generator is a very high quality entropy source but takes a long time to complete its operation. I think that idea is to use it to seed a Pseudo Random Number Generator for subsequent use (which will be implemented in SW) and not to use it to generate each random number.

Regards

Mark

0 Kudos

791 Views
EugeneHiihtaja
Senior Contributor I

Hi Mark !

Yes, it is typical technique to use it, but it would be nice to know if my digits are correct for be sure if everything configured properly.

Regards,

Eugene

791 Views
mjbcswitzerland
Specialist V

Eugene

As you will know, the TRNG generates 16 long words of entropy each time it is used ( (64 bytes).

When I test this it takes typically between 590ms and 650ms, which would give approx. 10ms per byte, which corresponds to your 100bytes/s (or 10ms per byte).

I use this configuration on the K82F:

    POWER_UP_ATOMIC(3, TRNG0);                                           // power up TRNG0
    TRNG0_MCTL = (TRNG_MCTL_PRGM | TRNG_MCTL_RST_DEF);                   // ensure we are in programming mode with defaults set
    TRNG0_FRQMIN = 0;
    TRNG0_FRQMAX = 0x03ffff;                                             // the default maximum value is too low and causes a frequency count failure if not increased
    TRNG0_SDCTL = ((1600 << 16) | (2500));                               // entropy delay and sample size reduced to half of default
    TRNG0_MCTL = (TRNG_MCTL_PRGM_RUN | TRNG_MCTL_SAMP_MODE_VON_NEUMANN | TRNG_MCTL_TRNG_ACC | TRNG_MCTL_OSC_DIV_1); // set to run mode with TRNG access

Regards

Mark

791 Views
EugeneHiihtaja
Senior Contributor I

Hi Mark !

Thank you !

Pseudo random generator  from standart C library rand() utilize some global buffers what cause problem to run code with User privileges.

Better to allocate this buffer from RTOS Task stack and use after that in context of this task.

Do you know any public implementation of pseudo random generator what available with source code ?

Regards,

Eugene

0 Kudos

791 Views
mjbcswitzerland
Specialist V

Eugene

Try mbedTLS as reference.

Simplified:

They use a 16 byte long counter which is seeded from an entropy source [which can bet quite complicated if there is no good source] (TRNG would be used for this since it is an excellent source).
It then performs an AES_ECB (AES256) encryption to generate 16 bytes of output and increments the 16 byte before each use. The 16 bytes of output are used as random numbers.


It sometimes re-seeds itself (based on elapsed time or a number of utilisations).

Since the K80 can do AES256 in HW this algorithm looks suitable.

Regards

Mark

0 Kudos

791 Views
EugeneHiihtaja
Senior Contributor I

Hi Mark !

Thank you !

Regards,

Eugene

0 Kudos