1 /* 2 * Copyright (c) 2001-2019, Arm Limited and Contributors. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 /************* Include Files ****************/ 8 #include "dx_rng.h" 9 #include "cc_pal_mem.h" 10 #include "cc_pal_mutex.h" 11 #include "cc_rng_plat.h" 12 #include "cc_pal_abort.h" 13 #include "dx_crys_kernel.h" 14 #include "cc_common_math.h" 15 #include "cc_rnd_local.h" 16 #include "cc_rnd_error.h" 17 #include "llf_rnd.h" 18 #include "llf_rnd_error.h" 19 #include "bypass_driver.h" 20 #include "cc_rng_params.h" 21 #include "cc_address_defs.h" 22 #include "cc_util_pm.h" 23 #include "llf_rnd_trng.h" 24 25 26 /****************************************************************************************/ 27 /** 28 * 29 * @brief The function retrievess the TRNG parameters, provided by the User trough NVM, 30 * and sets them into structures given by pointers pRndContext and pTrngParams. 31 * 32 * @author reuvenl (6/26/2012) 33 * 34 * @param[out] pRndState - The pointer to structure, containing PRNG data and 35 * parameters. 36 * @param[out] pTrngParams - The pointer to structure, containing parameters 37 * of HW TRNG. 38 * 39 * @return CCError_t - no return value 40 */ RNG_PLAT_SetUserRngParameters(CCRndParams_t * pTrngParams)41CCError_t RNG_PLAT_SetUserRngParameters( 42 CCRndParams_t *pTrngParams) 43 { 44 CCError_t error = CC_OK; 45 size_t paramsSize = sizeof(CC_PalTrngParams_t); 46 47 /* FUNCTION LOGIC */ 48 error = CC_PalTrngParamGet(&pTrngParams->userParams, ¶msSize); 49 if (error != CC_OK) { 50 return error; 51 } 52 // Verify PAL and run-time lib compiled with the same CC_CONFIG_TRNG_MODE 53 if (paramsSize != sizeof(CC_PalTrngParams_t)) { 54 error = CC_RND_MODE_MISMATCH_ERROR; 55 goto func_error; 56 } 57 58 /* Set TRNG parameters */ 59 /*-----------------------------*/ 60 pTrngParams->TrngMode = CC_RND_FE; 61 62 /* Allowed ROSCs lengths b'0-3. If bit value 1 - appropriate ROSC is allowed. */ 63 pTrngParams->RoscsAllowed = (((pTrngParams->userParams.SubSamplingRatio1 > 0) ? 0x1 : 0x0) | 64 ((pTrngParams->userParams.SubSamplingRatio2 > 0) ? 0x2 : 0x0) | 65 ((pTrngParams->userParams.SubSamplingRatio3 > 0) ? 0x4 : 0x0) | 66 ((pTrngParams->userParams.SubSamplingRatio4 > 0) ? 0x8 : 0x0)); 67 pTrngParams->SubSamplingRatio = 0; 68 if (pTrngParams->RoscsAllowed == 0) { 69 error = CC_RND_STATE_VALIDATION_TAG_ERROR; 70 goto func_error; 71 } 72 73 return CC_OK; 74 func_error: 75 CC_PalMemSetZero(pTrngParams, sizeof(CC_PalTrngParams_t)); 76 return error; 77 78 79 80 } /* End of RNG_PLAT_SetUserRngParameters */ 81 82 83