1 /***************************************************************************//**
2 * \file cy_crypto_core_prng.h
3 * \version 2.90
4 *
5 * \brief
6 * This file provides provides constant and parameters for the API of the PRNG
7 * in the Crypto block driver.
8 *
9 ********************************************************************************
10 * \copyright
11 * Copyright (c) (2020-2022), Cypress Semiconductor Corporation (an Infineon company) or
12 * an affiliate of Cypress Semiconductor Corporation.
13 * SPDX-License-Identifier: Apache-2.0
14 *
15 * Licensed under the Apache License, Version 2.0 (the "License");
16 * you may not use this file except in compliance with the License.
17 * You may obtain a copy of the License at
18 *
19 * http://www.apache.org/licenses/LICENSE-2.0
20 *
21 * Unless required by applicable law or agreed to in writing, software
22 * distributed under the License is distributed on an "AS IS" BASIS,
23 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24 * See the License for the specific language governing permissions and
25 * limitations under the License.
26 *******************************************************************************/
27
28
29 #if !defined (CY_CRYPTO_CORE_PRNG_H)
30 #define CY_CRYPTO_CORE_PRNG_H
31
32 #include "cy_device.h"
33
34 #if defined (CY_IP_MXCRYPTO)
35
36 #include "cy_crypto_common.h"
37
38 #if defined(__cplusplus)
39 extern "C" {
40 #endif
41
42 #if (CPUSS_CRYPTO_PR == 1) && defined(CY_CRYPTO_CFG_PRNG_C)
43
44 #include "cy_crypto_core_prng_v1.h"
45 #include "cy_crypto_core_prng_v2.h"
46
47 typedef cy_en_crypto_status_t (*cy_crypto_prng_init_func_t)(CRYPTO_Type *base,
48 uint32_t lfsr32InitState,
49 uint32_t lfsr31InitState,
50 uint32_t lfsr29InitState);
51
52 typedef cy_en_crypto_status_t (*cy_crypto_prng_func_t)(CRYPTO_Type *base,
53 uint32_t max,
54 uint32_t *randomNum);
55
56 /**
57 * \addtogroup group_crypto_lld_rng_functions
58 * \{
59 */
60
61 /*******************************************************************************
62 * Function Name: Cy_Crypto_Core_Prng_Init
63 ****************************************************************************//**
64 *
65 * Initializes the PRND parameters.
66 * Invoking this function causes a restart of the pseudo-random sequence.
67 *
68 * \param base
69 * The pointer to the CRYPTO instance.
70 *
71 * \param lfsr32InitState
72 * A non-zero seed value for the first LFSR.
73
74 * \param lfsr31InitState
75 * A non-zero seed value for the second LFSR.
76
77 * \param lfsr29InitState
78 * A non-zero seed value for the third LFSR.
79 *
80 * \return
81 * \ref cy_en_crypto_status_t
82 *
83 * \funcusage
84 * \snippet crypto/snippet/main.c snippet_myCryptoCorePrngUse
85 *
86 *******************************************************************************/
Cy_Crypto_Core_Prng_Init(CRYPTO_Type * base,uint32_t lfsr32InitState,uint32_t lfsr31InitState,uint32_t lfsr29InitState)87 __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Prng_Init(CRYPTO_Type *base,
88 uint32_t lfsr32InitState,
89 uint32_t lfsr31InitState,
90 uint32_t lfsr29InitState)
91 {
92 cy_en_crypto_status_t tmpResult = CY_CRYPTO_NOT_SUPPORTED;
93
94 if (CY_CRYPTO_V1)
95 {
96 #if defined(CY_CRYPTO_CFG_HW_V1_ENABLE)
97 tmpResult = Cy_Crypto_Core_V1_Prng_Init(base, lfsr32InitState, lfsr31InitState, lfsr29InitState);
98 #endif /* defined(CY_CRYPTO_CFG_HW_V1_ENABLE) */
99 }
100 else
101 {
102 #if defined(CY_CRYPTO_CFG_HW_V2_ENABLE)
103 tmpResult = Cy_Crypto_Core_V2_Prng_Init(base, lfsr32InitState, lfsr31InitState, lfsr29InitState);
104 #endif /* defined(CY_CRYPTO_CFG_HW_V2_ENABLE) */
105 }
106
107 return tmpResult;
108 }
109
110 /*******************************************************************************
111 * Function Name: Cy_Crypto_Core_Prng
112 ****************************************************************************//**
113 *
114 * Generates a Pseudo Random Number.
115 *
116 * \param base
117 * The pointer to the CRYPTO instance.
118 *
119 * \param max
120 * The maximum value of a random number.
121 *
122 * \param randomNum
123 * The pointer to a variable to store the generated pseudo random number.
124 *
125 * \return
126 * \ref cy_en_crypto_status_t
127 *
128 * \funcusage
129 * \snippet crypto/snippet/main.c snippet_myCryptoCorePrngUse
130 *
131 *******************************************************************************/
Cy_Crypto_Core_Prng(CRYPTO_Type * base,uint32_t max,uint32_t * randomNum)132 __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Prng(CRYPTO_Type *base,
133 uint32_t max,
134 uint32_t *randomNum)
135 {
136 cy_en_crypto_status_t tmpResult = CY_CRYPTO_NOT_SUPPORTED;
137
138 if (CY_CRYPTO_V1)
139 {
140 #if defined(CY_CRYPTO_CFG_HW_V1_ENABLE)
141 tmpResult = Cy_Crypto_Core_V1_Prng(base, max, randomNum);
142 #endif /* defined(CY_CRYPTO_CFG_HW_V1_ENABLE) */
143 }
144 else
145 {
146 #if defined(CY_CRYPTO_CFG_HW_V2_ENABLE)
147 tmpResult = Cy_Crypto_Core_V2_Prng(base, max, randomNum);
148 #endif /* defined(CY_CRYPTO_CFG_HW_V2_ENABLE) */
149 }
150
151 return tmpResult;
152 }
153
154 /** \} group_crypto_lld_rng_functions */
155
156 #endif /* (CPUSS_CRYPTO_PR == 1) && defined(CY_CRYPTO_CFG_PRNG_C) */
157
158 #if defined(__cplusplus)
159 }
160 #endif
161
162 #endif /* CY_IP_MXCRYPTO */
163
164 #endif /* #if !defined (CY_CRYPTO_CORE_PRNG_H) */
165
166
167 /* [] END OF FILE */
168