test
targets/TARGET_Maxim/TARGET_MAX32630/mxc/prng.h@1:8a094db1347f, 2020-11-09 (annotated)
- Committer:
- elijahsj
- Date:
- Mon Nov 09 00:02:47 2020 -0500
- Revision:
- 1:8a094db1347f
test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
elijahsj | 1:8a094db1347f | 1 | /** |
elijahsj | 1:8a094db1347f | 2 | * @file |
elijahsj | 1:8a094db1347f | 3 | * @brief Pseudo-random number generator(PRNG) Peripheral Module. |
elijahsj | 1:8a094db1347f | 4 | * @note The PRNG hardware does not produce true random numbers. The |
elijahsj | 1:8a094db1347f | 5 | * output should be used as a seed to an approved random-number |
elijahsj | 1:8a094db1347f | 6 | * algorithm, per a certifying authority such as NIST or PCI. The |
elijahsj | 1:8a094db1347f | 7 | * approved algorithm will output random numbers which are cerfitied |
elijahsj | 1:8a094db1347f | 8 | * for use in encryption and authentication algorithms. |
elijahsj | 1:8a094db1347f | 9 | */ |
elijahsj | 1:8a094db1347f | 10 | /* **************************************************************************** |
elijahsj | 1:8a094db1347f | 11 | * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. |
elijahsj | 1:8a094db1347f | 12 | * |
elijahsj | 1:8a094db1347f | 13 | * Permission is hereby granted, free of charge, to any person obtaining a |
elijahsj | 1:8a094db1347f | 14 | * copy of this software and associated documentation files (the "Software"), |
elijahsj | 1:8a094db1347f | 15 | * to deal in the Software without restriction, including without limitation |
elijahsj | 1:8a094db1347f | 16 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
elijahsj | 1:8a094db1347f | 17 | * and/or sell copies of the Software, and to permit persons to whom the |
elijahsj | 1:8a094db1347f | 18 | * Software is furnished to do so, subject to the following conditions: |
elijahsj | 1:8a094db1347f | 19 | * |
elijahsj | 1:8a094db1347f | 20 | * The above copyright notice and this permission notice shall be included |
elijahsj | 1:8a094db1347f | 21 | * in all copies or substantial portions of the Software. |
elijahsj | 1:8a094db1347f | 22 | * |
elijahsj | 1:8a094db1347f | 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
elijahsj | 1:8a094db1347f | 24 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
elijahsj | 1:8a094db1347f | 25 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
elijahsj | 1:8a094db1347f | 26 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
elijahsj | 1:8a094db1347f | 27 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
elijahsj | 1:8a094db1347f | 28 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
elijahsj | 1:8a094db1347f | 29 | * OTHER DEALINGS IN THE SOFTWARE. |
elijahsj | 1:8a094db1347f | 30 | * |
elijahsj | 1:8a094db1347f | 31 | * Except as contained in this notice, the name of Maxim Integrated |
elijahsj | 1:8a094db1347f | 32 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
elijahsj | 1:8a094db1347f | 33 | * Products, Inc. Branding Policy. |
elijahsj | 1:8a094db1347f | 34 | * |
elijahsj | 1:8a094db1347f | 35 | * The mere transfer of this software does not imply any licenses |
elijahsj | 1:8a094db1347f | 36 | * of trade secrets, proprietary technology, copyrights, patents, |
elijahsj | 1:8a094db1347f | 37 | * trademarks, maskwork rights, or any other form of intellectual |
elijahsj | 1:8a094db1347f | 38 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
elijahsj | 1:8a094db1347f | 39 | * ownership rights. |
elijahsj | 1:8a094db1347f | 40 | * |
elijahsj | 1:8a094db1347f | 41 | * $Date: 2016-10-10 19:26:15 -0500 (Mon, 10 Oct 2016) $ |
elijahsj | 1:8a094db1347f | 42 | * $Revision: 24668 $ |
elijahsj | 1:8a094db1347f | 43 | * |
elijahsj | 1:8a094db1347f | 44 | ******************************************************************************/ |
elijahsj | 1:8a094db1347f | 45 | |
elijahsj | 1:8a094db1347f | 46 | /* **** Includes **** */ |
elijahsj | 1:8a094db1347f | 47 | #include "prng_regs.h" |
elijahsj | 1:8a094db1347f | 48 | |
elijahsj | 1:8a094db1347f | 49 | /* Define to prevent redundant inclusion */ |
elijahsj | 1:8a094db1347f | 50 | #ifndef _PRNG_H_ |
elijahsj | 1:8a094db1347f | 51 | #define _PRNG_H_ |
elijahsj | 1:8a094db1347f | 52 | |
elijahsj | 1:8a094db1347f | 53 | #ifdef __cplusplus |
elijahsj | 1:8a094db1347f | 54 | extern "C" { |
elijahsj | 1:8a094db1347f | 55 | #endif |
elijahsj | 1:8a094db1347f | 56 | |
elijahsj | 1:8a094db1347f | 57 | /** |
elijahsj | 1:8a094db1347f | 58 | * @ingroup periphlibs |
elijahsj | 1:8a094db1347f | 59 | * @defgroup prng Pseudo-Random Number Generator (PRNG) |
elijahsj | 1:8a094db1347f | 60 | * @brief Pseudo-random number generator(PRNG) Peripheral Module. |
elijahsj | 1:8a094db1347f | 61 | * @note The PRNG hardware does not produce true random numbers. The |
elijahsj | 1:8a094db1347f | 62 | * output should be used as a seed to an approved random-number |
elijahsj | 1:8a094db1347f | 63 | * algorithm, per a certifying authority such as NIST or PCI. The |
elijahsj | 1:8a094db1347f | 64 | * approved algorithm will output random numbers which are cerfitied |
elijahsj | 1:8a094db1347f | 65 | * for use in encryption and authentication algorithms. |
elijahsj | 1:8a094db1347f | 66 | * @{ |
elijahsj | 1:8a094db1347f | 67 | */ |
elijahsj | 1:8a094db1347f | 68 | |
elijahsj | 1:8a094db1347f | 69 | /* **** Definitions **** */ |
elijahsj | 1:8a094db1347f | 70 | |
elijahsj | 1:8a094db1347f | 71 | /* **** Globals **** */ |
elijahsj | 1:8a094db1347f | 72 | |
elijahsj | 1:8a094db1347f | 73 | /* **** Function Prototypes **** */ |
elijahsj | 1:8a094db1347f | 74 | |
elijahsj | 1:8a094db1347f | 75 | /** |
elijahsj | 1:8a094db1347f | 76 | * @brief Initialize required clocks and enable PRNG module |
elijahsj | 1:8a094db1347f | 77 | * @note This function will set the clock divisors to divide by 1 if they are disabled. |
elijahsj | 1:8a094db1347f | 78 | * Otherwise, the clock divisors are left unchanged. |
elijahsj | 1:8a094db1347f | 79 | */ |
elijahsj | 1:8a094db1347f | 80 | void PRNG_Init(void); |
elijahsj | 1:8a094db1347f | 81 | |
elijahsj | 1:8a094db1347f | 82 | /** |
elijahsj | 1:8a094db1347f | 83 | * @brief Returns ready bit to indicates that the PRNG_GetSeed can be |
elijahsj | 1:8a094db1347f | 84 | * called without being held off. Only needs to be called one time after a POR event. |
elijahsj | 1:8a094db1347f | 85 | * |
elijahsj | 1:8a094db1347f | 86 | * @retval 0 PRNG not ready |
elijahsj | 1:8a094db1347f | 87 | * @retval non-zero PRNG ready to read |
elijahsj | 1:8a094db1347f | 88 | */ |
elijahsj | 1:8a094db1347f | 89 | __STATIC_INLINE uint16_t PRNG_Ready(void) |
elijahsj | 1:8a094db1347f | 90 | { |
elijahsj | 1:8a094db1347f | 91 | return (MXC_PRNG->user_entropy & MXC_F_PRNG_USER_ENTROPY_RND_NUM_READY); |
elijahsj | 1:8a094db1347f | 92 | } |
elijahsj | 1:8a094db1347f | 93 | |
elijahsj | 1:8a094db1347f | 94 | /** |
elijahsj | 1:8a094db1347f | 95 | * @brief Retrieve a seed value from the PRNG. |
elijahsj | 1:8a094db1347f | 96 | * @note The PRNG hardware does not produce true random numbers. The |
elijahsj | 1:8a094db1347f | 97 | * output should be used as a seed to an approved random-number |
elijahsj | 1:8a094db1347f | 98 | * algorithm, per a certifying authority such as NIST or PCI. The |
elijahsj | 1:8a094db1347f | 99 | * approved algorithm will output random numbers which are cerfitied |
elijahsj | 1:8a094db1347f | 100 | * for use in encryption and authentication algorithms. |
elijahsj | 1:8a094db1347f | 101 | * |
elijahsj | 1:8a094db1347f | 102 | * @return 16-bit seed value |
elijahsj | 1:8a094db1347f | 103 | */ |
elijahsj | 1:8a094db1347f | 104 | __STATIC_INLINE uint16_t PRNG_GetSeed(void) |
elijahsj | 1:8a094db1347f | 105 | { |
elijahsj | 1:8a094db1347f | 106 | return MXC_PRNG->rnd_num; |
elijahsj | 1:8a094db1347f | 107 | } |
elijahsj | 1:8a094db1347f | 108 | |
elijahsj | 1:8a094db1347f | 109 | /** |
elijahsj | 1:8a094db1347f | 110 | * @brief Add user entropy to the PRNG entropy source. |
elijahsj | 1:8a094db1347f | 111 | * |
elijahsj | 1:8a094db1347f | 112 | * @param entropy A value to be mixed into the PRNG entropy source. |
elijahsj | 1:8a094db1347f | 113 | */ |
elijahsj | 1:8a094db1347f | 114 | __STATIC_INLINE void PRNG_AddUserEntropy(uint8_t entropy) |
elijahsj | 1:8a094db1347f | 115 | { |
elijahsj | 1:8a094db1347f | 116 | MXC_PRNG->user_entropy = (uint32_t)entropy; |
elijahsj | 1:8a094db1347f | 117 | } |
elijahsj | 1:8a094db1347f | 118 | /**@}*/ |
elijahsj | 1:8a094db1347f | 119 | #ifdef __cplusplus |
elijahsj | 1:8a094db1347f | 120 | } |
elijahsj | 1:8a094db1347f | 121 | #endif |
elijahsj | 1:8a094db1347f | 122 | |
elijahsj | 1:8a094db1347f | 123 | #endif /* _PRNG_H_ */ |