MTB CAT1 Peripheral driver library

General Description

Functions

__STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Prng_Init (CRYPTO_Type *base, uint32_t lfsr32InitState, uint32_t lfsr31InitState, uint32_t lfsr29InitState)
 Initializes the PRND parameters. More...
 
__STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Prng (CRYPTO_Type *base, uint32_t max, uint32_t *randomNum)
 Generates a Pseudo Random Number. More...
 
void Cy_Crypto_Core_Trng_Init (CRYPTO_Type *base, cy_stc_crypto_trng_config_t *config)
 Initialize the TRNG hardware submodule. More...
 
void Cy_Crypto_Core_Trng_DeInit (CRYPTO_Type *base)
 Clears all TRNG registers by setting it to hardware default values. More...
 
cy_en_crypto_status_t Cy_Crypto_Core_Trng_Start (CRYPTO_Type *base, uint32_t dataSize)
 Starts a random number generation. More...
 
cy_en_crypto_status_t Cy_Crypto_Core_Trng_ReadData (CRYPTO_Type *base, uint32_t *randomData)
 Reads in blocking mode a generated random number. More...
 
cy_en_crypto_status_t Cy_Crypto_Core_Trng (CRYPTO_Type *base, uint32_t GAROPol, uint32_t FIROPol, uint32_t max, uint32_t *randomNum)
 Generates a True Random Number. More...
 
__STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Trng_Ext (CRYPTO_Type *base, uint32_t max, uint32_t *randomNum)
 Generates a True Random Number. More...
 

Function Documentation

◆ Cy_Crypto_Core_Prng_Init()

__STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Prng_Init ( CRYPTO_Type *  base,
uint32_t  lfsr32InitState,
uint32_t  lfsr31InitState,
uint32_t  lfsr29InitState 
)

Initializes the PRND parameters.

Invoking this function causes a restart of the pseudo-random sequence.

Parameters
baseThe pointer to the CRYPTO instance.
lfsr32InitStateA non-zero seed value for the first LFSR.
lfsr31InitStateA non-zero seed value for the second LFSR.
lfsr29InitStateA non-zero seed value for the third LFSR.
Returns
cy_en_crypto_status_t
Function Usage
/* Initialization seed values for Pseudo Random Generator */
#define LFSR32_INITSTATE (0xd8959bc9)
#define LFSR31_INITSTATE (0x2bb911f8)
#define LFSR29_INITSTATE (0x060c31b7)
#define MAX_PRNG_VALUE (255UL)
/* Generated Random Number */
uint32_t rndNum = 0;
cy_en_crypto_status_t cryptoStatus;
/* Initialize Pseudo Random Generator */
cryptoStatus = Cy_Crypto_Core_Prng_Init(
CRYPTO_HW, /* Pointer to Crypto instance */
LFSR32_INITSTATE, /* Seed value for first LFSR */
LFSR31_INITSTATE, /* Seed value for second LFSR */
LFSR29_INITSTATE); /* Seed value for third LFSR */
/* ... check for errors... */
/* Generate a Pseudo Random number in specified range */
cryptoStatus = Cy_Crypto_Core_Prng(
CRYPTO_HW,
MAX_PRNG_VALUE, /* Range of random number */
&rndNum); /* Pointer to generated random number */
/* ... check for errors... */

◆ Cy_Crypto_Core_Prng()

__STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Prng ( CRYPTO_Type *  base,
uint32_t  max,
uint32_t *  randomNum 
)

Generates a Pseudo Random Number.

Parameters
baseThe pointer to the CRYPTO instance.
maxThe maximum value of a random number.
randomNumThe pointer to a variable to store the generated pseudo random number.
Returns
cy_en_crypto_status_t
Function Usage
/* Initialization seed values for Pseudo Random Generator */
#define LFSR32_INITSTATE (0xd8959bc9)
#define LFSR31_INITSTATE (0x2bb911f8)
#define LFSR29_INITSTATE (0x060c31b7)
#define MAX_PRNG_VALUE (255UL)
/* Generated Random Number */
uint32_t rndNum = 0;
cy_en_crypto_status_t cryptoStatus;
/* Initialize Pseudo Random Generator */
cryptoStatus = Cy_Crypto_Core_Prng_Init(
CRYPTO_HW, /* Pointer to Crypto instance */
LFSR32_INITSTATE, /* Seed value for first LFSR */
LFSR31_INITSTATE, /* Seed value for second LFSR */
LFSR29_INITSTATE); /* Seed value for third LFSR */
/* ... check for errors... */
/* Generate a Pseudo Random number in specified range */
cryptoStatus = Cy_Crypto_Core_Prng(
CRYPTO_HW,
MAX_PRNG_VALUE, /* Range of random number */
&rndNum); /* Pointer to generated random number */
/* ... check for errors... */

◆ Cy_Crypto_Core_Trng_Init()

void Cy_Crypto_Core_Trng_Init ( CRYPTO_Type *  base,
cy_stc_crypto_trng_config_t config 
)

Initialize the TRNG hardware submodule.

Precondition
If the TRNG submodule is initialized previously, the Cy_Crypto_Core_Trng_DeInit() must be called before calling this function.
Parameters
baseThe pointer to the CRYPTO instance.
configThe pointer to the configuration structure.

◆ Cy_Crypto_Core_Trng_DeInit()

void Cy_Crypto_Core_Trng_DeInit ( CRYPTO_Type *  base)

Clears all TRNG registers by setting it to hardware default values.

Parameters
baseThe pointer to the CRYPTO instance.

Clears all TRNG registers by setting it to hardware default values.

Parameters
baseThe pointer to the CRYPTO instance.

◆ Cy_Crypto_Core_Trng_Start()

cy_en_crypto_status_t Cy_Crypto_Core_Trng_Start ( CRYPTO_Type *  base,
uint32_t  dataSize 
)

Starts a random number generation.

Parameters
baseThe pointer to the CRYPTO instance.
dataSizeThe maximum length of a random number, in the range [0, 32] bits.
Returns
The error / status code. See cy_en_crypto_status_t.

◆ Cy_Crypto_Core_Trng_ReadData()

cy_en_crypto_status_t Cy_Crypto_Core_Trng_ReadData ( CRYPTO_Type *  base,
uint32_t *  randomData 
)

Reads in blocking mode a generated random number.

Note
Call this API only after Cy_Crypto_Core_Trng_Start() is successful.
Parameters
baseThe pointer to the CRYPTO instance.
randomDataThe pointer to a generated true random number. Must be 4-byte aligned.
Returns
The error / status code. See cy_en_crypto_status_t.

◆ Cy_Crypto_Core_Trng()

cy_en_crypto_status_t Cy_Crypto_Core_Trng ( CRYPTO_Type *  base,
uint32_t  GAROPol,
uint32_t  FIROPol,
uint32_t  max,
uint32_t *  randomNum 
)

Generates a True Random Number.

Parameters
baseThe pointer to the CRYPTO instance.
GAROPolThe polynomial for the programmable Galois ring oscillator.
FIROPolThe polynomial for the programmable Fibonacci ring oscillator.
maxThe maximum length of a random number, in the range of [0, 32] bits.
randomNumThe pointer to a generated true random number. Must be 4-byte aligned.
Returns
cy_en_crypto_status_t
Parameters
baseThe pointer to the CRYPTO instance.
GAROPolThe polynomial for the programmable Galois ring oscillator.
FIROPolThe polynomial for the programmable Fibonacci ring oscillator.
maxThe maximum length of a random number, in the range of [0, 32] bits.
randomNumThe pointer to a generated true random number. Must be 4-byte aligned.
Returns
cy_en_crypto_status_t
Function Usage
/* Initialization polynomial values for True Random Generator.
Polynomial for programmable Galois ring oscillator.
The polynomial is represented WITHOUT the high order bit (this bit is always assumed '1').
GARO 31 bit polynomial (0x04c1:1db7) = x31 + x26 + x23 + x22 + x16 + x12 + x11 + x10 + x8 + x7 + x5 + x4 + x2 + x + 1
Polynomial for programmable Fibonacci ring oscillator.
The polynomial is represented WITHOUT the high order bit (this bit is always assumed '1').
FIRO 31 bit polynomial (0x04c1:1db7) = x31 + x26 + x23 + x22 + x16 + x12 + x11 + x10 + x8 + x7 + x5 + x4 + x2 + x + 1
*/
#define GARO31_INITSTATE (0x04c11db7)
#define FIRO31_INITSTATE (0x04c11db7)
#define MAX_TRNG_BIT_SIZE (32UL)
/* Generated Random Number */
uint32_t rndNum = 0;
cy_en_crypto_status_t cryptoStatus;
/* Generate True Random number in a specified range */
cryptoStatus = Cy_Crypto_Core_Trng(
CRYPTO_HW, /* Pointer to Crypto instance */
GARO31_INITSTATE, /* Polynomial for programmable GARO */
FIRO31_INITSTATE, /* Polynomial for programmable FIRO */
MAX_TRNG_BIT_SIZE, /* Range of random number */
&rndNum); /* Pointer to generated random number */
/* ... check for errors... */

◆ Cy_Crypto_Core_Trng_Ext()

__STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Trng_Ext ( CRYPTO_Type *  base,
uint32_t  max,
uint32_t *  randomNum 
)

Generates a True Random Number.

Parameters
baseThe pointer to the CRYPTO instance.
maxThe maximum length of a random number, in the range of [0, 32] bits.
randomNumThe pointer to a generated true random number. Must be 4-byte aligned.
Returns
cy_en_crypto_status_t