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