1 /* 2 * Copyright 2018 NXP 3 * All rights reserved. 4 * 5 * 6 * SPDX-License-Identifier: BSD-3-Clause 7 */ 8 9 #include "fsl_common.h" 10 #include "fsl_adapter_rng.h" 11 #include "fsl_rng.h" 12 HAL_RngInit(void)13hal_rng_status_t HAL_RngInit(void) 14 { 15 /*MISRA C-2012 Rule 8.2*/ 16 return kStatus_HAL_RngSuccess; 17 } 18 HAL_RngDeinit(void)19void HAL_RngDeinit(void) 20 { 21 /*MISRA C-2012 Rule 8.2*/ 22 return; 23 } 24 HAL_RngGetData(void * pRandomNo,uint32_t dataSize)25hal_rng_status_t HAL_RngGetData(void *pRandomNo, uint32_t dataSize) 26 { 27 uint32_t skip; 28 uint32_t random_32; 29 uint8_t *random_p; 30 uint32_t random_size; 31 uint8_t *data_p = (uint8_t *)pRandomNo; 32 uint32_t i; 33 hal_rng_status_t status = kStatus_HAL_RngSuccess; 34 35 if (NULL == pRandomNo) 36 { 37 status = kStatus_HAL_RngNullPointer; 38 } 39 40 do 41 { 42 /* Read Entropy.*/ 43 random_32 = RNG_GetRandomDataWord(); 44 45 random_p = (uint8_t *)&random_32; 46 47 if (dataSize < sizeof(random_32)) 48 { 49 random_size = dataSize; 50 } 51 else 52 { 53 random_size = sizeof(random_32); 54 } 55 56 for (i = 0; i < random_size; i++) 57 { 58 *data_p++ = *random_p++; 59 } 60 61 dataSize -= random_size; 62 /* Skip next 32 random numbers for better entropy */ 63 for (skip = 0; skip < 32U; skip++) 64 { 65 (void)RNG_GetRandomDataWord(); 66 } 67 } while (dataSize > 0U); 68 return status; 69 } 70 HAL_RngHwGetData(void * pRandomNo,uint32_t dataSize)71hal_rng_status_t HAL_RngHwGetData(void *pRandomNo, uint32_t dataSize) 72 { 73 return KStatus_HAL_RngNotSupport; 74 } 75 HAL_RngSetSeed(uint32_t seed)76hal_rng_status_t HAL_RngSetSeed(uint32_t seed) 77 { 78 (void)RNG_GetRandomDataWord(); 79 return kStatus_HAL_RngSuccess; 80 } 81