1 /** 2 * @file trng.h 3 * @brief True Random Number Generator(TRNG) function prototypes and data types. 4 */ 5 6 /****************************************************************************** 7 * 8 * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by 9 * Analog Devices, Inc.), 10 * Copyright (C) 2023-2024 Analog Devices, Inc. 11 * 12 * Licensed under the Apache License, Version 2.0 (the "License"); 13 * you may not use this file except in compliance with the License. 14 * You may obtain a copy of the License at 15 * 16 * http://www.apache.org/licenses/LICENSE-2.0 17 * 18 * Unless required by applicable law or agreed to in writing, software 19 * distributed under the License is distributed on an "AS IS" BASIS, 20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 * See the License for the specific language governing permissions and 22 * limitations under the License. 23 * 24 ******************************************************************************/ 25 26 /* Define to prevent redundant inclusion */ 27 #ifndef LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32650_TRNG_H_ 28 #define LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32650_TRNG_H_ 29 30 /* **** Includes **** */ 31 #include <stdint.h> 32 #include "mxc_sys.h" 33 #include "trng_regs.h" 34 35 #ifdef __cplusplus 36 extern "C" { 37 #endif 38 39 /** 40 * @defgroup trng TRNG 41 * @ingroup periphlibs 42 * @{ 43 */ 44 45 /* IN ADDITION TO THIS HEADER, FCL WILL BE SUPPORTED AND PROVIDED IN BINARY FORM */ 46 47 /***** Function Prototypes *****/ 48 typedef void (*mxc_trng_complete_t)(void *req, int result); 49 50 /* ************************************************************************* */ 51 /* Global Control/Configuration functions */ 52 /* ************************************************************************* */ 53 54 /** 55 * @brief Enable portions of the TRNG 56 * 57 * @return Success/Fail, see \ref MXC_Error_Codes for a list of return codes. 58 */ 59 int MXC_TRNG_Init(void); 60 61 /** 62 * @brief Enable TRNG Interrupts 63 * 64 */ 65 void MXC_TRNG_EnableInt(void); 66 67 /** 68 * @brief Disable TRNG Interrupts 69 * 70 */ 71 void MXC_TRNG_DisableInt(void); 72 73 /** 74 * @brief Disable and reset portions of the TRNG 75 * 76 * @return Success/Fail, see \ref MXC_Error_Codes for a list of return codes. 77 */ 78 int MXC_TRNG_Shutdown(void); 79 80 /** 81 * @brief This function should be called from the TRNG ISR Handler 82 * when using Async functions 83 */ 84 void MXC_TRNG_Handler(void); 85 86 /* ************************************************************************* */ 87 /* True Random Number Generator (TRNG) functions */ 88 /* ************************************************************************* */ 89 90 /** 91 * @brief Get a random number 92 * 93 * @return A random 32-bit number 94 */ 95 int MXC_TRNG_RandomInt(void); 96 97 /** 98 * @brief Get a random number of length len 99 * 100 * @param data Pointer to a location to store the number 101 * @param len Length of random number in bytes 102 * 103 * @return Success/Fail, see \ref MXC_Error_Codes for a list of return codes. 104 */ 105 int MXC_TRNG_Random(uint8_t *data, uint32_t len); 106 107 /** 108 * @brief Get a random number of length len, do not block while generating data 109 * @note The user must call MXC_TRNG_Handler() in the ISR 110 * 111 * @param data Pointer to a location to store the number 112 * @param len Length of random number in bytes 113 * @param callback Function that will be called when all data has been generated 114 * 115 */ 116 void MXC_TRNG_RandomAsync(uint8_t *data, uint32_t len, mxc_trng_complete_t callback); 117 118 /** 119 * @brief Generate an AES key and transfer to the AES block 120 */ 121 void MXC_TRNG_GenerateKey(void); 122 123 #ifdef __cplusplus 124 } 125 #endif 126 /**@} end of group trng */ 127 128 #endif // LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32650_TRNG_H_ 129