Greg Steiert / pegasus_dev

Dependents:   blinky_max32630fthr

Committer:
switches
Date:
Fri Nov 11 20:59:50 2016 +0000
Revision:
0:5c4d7b2438d3
Initial commit

Who changed what in which revision?

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