1 /*
2 * Copyright (c) 2016, Freescale Semiconductor, Inc.
3 * Copyright 2016-2017, 2021 NXP
4 * All rights reserved.
5 *
6 * SPDX-License-Identifier: BSD-3-Clause
7 */
8 #ifndef _FSL_RNG_DRIVER_H_
9 #define _FSL_RNG_DRIVER_H_
10
11 #include "fsl_common.h"
12
13 #if defined(FSL_FEATURE_SOC_LPC_RNG_COUNT) && FSL_FEATURE_SOC_LPC_RNG_COUNT
14
15 /*!
16 * @addtogroup rng
17 * @{
18 */
19
20 /*******************************************************************************
21 * Definitions
22 *******************************************************************************/
23
24 /* Component ID definition, used by tools. */
25 #ifndef FSL_COMPONENT_ID
26 #define FSL_COMPONENT_ID "platform.drivers.rng"
27 #endif
28
29 /*! @name Driver version */
30 /*@{*/
31 /*! @brief RNG driver version 2.1.0.
32 *
33 * Current version: 2.1.0
34 *
35 * Change log:
36 * - Version 2.0.0
37 * - Initial version.
38 * - Version 2.1.0
39 * - Renamed function RNG_GetRandomData() to RNG_GetRandomDataWord(). Added function RNG_GetRandomData() which
40 * discarding next 32 words after reading RNG register which results into better entropy, as is recommended in UM.
41 * - API is aligned with other RNG driver, having similar functionality as other RNG/TRNG drivers.
42 */
43 #define FSL_RNG_DRIVER_VERSION (MAKE_VERSION(2, 1, 0))
44 /*@}*/
45
46 /*******************************************************************************
47 * API
48 *******************************************************************************/
49
50 #if defined(__cplusplus)
51 extern "C" {
52 #endif
53
54 /*!
55 * @brief Gets random data.
56 *
57 * This function gets random data from the RNG.
58 *
59 * @param data Pointer address used to store random data.
60 * @param dataSize Size of the buffer pointed by the data parameter.
61 * @return Status from operation
62 */
63 status_t RNG_GetRandomData(void *data, size_t dataSize);
64
65 /*!
66 * @brief Gets random data.
67 *
68 * This function returns single 32 bit random number.
69 * For each read word next 32 words should be discarded to achieve better entropy.
70 *
71 * @return random data
72 */
RNG_GetRandomDataWord(void)73 static inline uint32_t RNG_GetRandomDataWord(void)
74 {
75 return OTP_API->rngRead();
76 }
77
78 #if defined(__cplusplus)
79 }
80 #endif
81
82 /*! @}*/
83
84 #endif /* FSL_FEATURE_SOC_LPC_RNG_COUNT */
85 #endif /*_FSL_RNG_DRIVER_H_*/
86