This content has been marked as final.
Show 2 replies
-
1. Re: PSoC 62 generate deterministic random number based on seed
DheerajK_81Nov 29, 2019 5:05 AM (in response to JeHu_3414236)
1 of 1 people found this helpfulIn the code example CE221295, you can add another function to generate the Pseudo Random Number in the following manner:
void PseudoGeneratePassword(int32_t size, uint8_t* buffer){ /* Initialization seed values fro Pseudo Random Generator */ #define LFSR32_INITSTATE (0xd8959bc9) #define LFSR31_INITSTATE (0x2bb911f8) #define LFSR29_INITSTATE (0x060c31b7) #define MAX_PRNG_VALUE (8UL) /* Generated Random Number */ uint32_t rndNum = 0; int32_t index; cy_stc_crypto_context_prng_t cryptoPrngContext; cy_en_crypto_status_t cryptoStatus; /* Initialize Pseudo Random Generator in Crypto Driver */ cryptoStatus = Cy_Crypto_Prng_Init( LFSR32_INITSTATE, LFSR31_INITSTATE, LFSR29_INITSTATE, &cryptoPrngContext); for(index = 0; index < (size-1); index++) { /* Generate Pseudo Random number into rndNum variable */ cryptoStatus = Cy_Crypto_Prng_Generate(MAX_PRNG_VALUE, &rndNum, &cryptoPrngContext); /* ... check for errors... */ /* Wait crypto become available */ cryptoStatus = Cy_Crypto_Sync(CY_CRYPTO_SYNC_BLOCKING); /* Check if the generated random number is in the range of alpha-numeric, special characters ASCII codes. If not, convert to that range */ if(rndNum < ASCII_ALPHANUMERIC_LOWER_LIMIT) { rndNum += ASCII_ALPHANUMERIC_LOWER_LIMIT; } if(rndNum >= ASCII_ALPHANUMERIC_UPPER_LIMIT) { rndNum -= ASCII_ALPHANUMERIC_LOWER_LIMIT; } buffer[index] = rndNum; } buffer[index] = '\0'; /* Display the generated password on the UART Terminal */ printf("Pseudo Password: %s\r\n",buffer); printf(SCREEN_HEADER1); }
Just call this function in the for loop of main and you can observe both the TRNG and PRNG output.
The output of PRNG will remain same based on the seed value. Hope this helps
Regards,
Dheeraj
-
2. Re: PSoC 62 generate deterministic random number based on seed
JeHu_3414236 Dec 2, 2019 2:51 PM (in response to DheerajK_81)This works but I think the value of MAX_PRNG_VALUE is wrong. I assume you want 8 bits max but the value should be the maximum value not bits.