1 /******************************************************************************* 2 * File Name: cyhal_trng.c 3 * 4 * Description: 5 * Provides a high level interface for interacting with the Infineon True Random 6 * Number Generator. This is a wrapper around the lower level PDL API. 7 * 8 ******************************************************************************** 9 * \copyright 10 * Copyright 2018-2022 Cypress Semiconductor Corporation (an Infineon company) or 11 * an affiliate of Cypress Semiconductor Corporation 12 * 13 * SPDX-License-Identifier: Apache-2.0 14 * 15 * Licensed under the Apache License, Version 2.0 (the "License"); 16 * you may not use this file except in compliance with the License. 17 * You may obtain a copy of the License at 18 * 19 * http://www.apache.org/licenses/LICENSE-2.0 20 * 21 * Unless required by applicable law or agreed to in writing, software 22 * distributed under the License is distributed on an "AS IS" BASIS, 23 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 24 * See the License for the specific language governing permissions and 25 * limitations under the License. 26 *******************************************************************************/ 27 28 #include "cyhal_hwmgr.h" 29 #include "cyhal_crypto_common.h" 30 #include "cyhal_trng_impl.h" 31 32 #if (CYHAL_DRIVER_AVAILABLE_TRNG) 33 34 #if defined(__cplusplus) 35 extern "C" 36 { 37 #endif 38 39 /******************************************************************************* 40 * Functions 41 *******************************************************************************/ cyhal_trng_init(cyhal_trng_t * obj)42cy_rslt_t cyhal_trng_init(cyhal_trng_t *obj) 43 { 44 CY_ASSERT(NULL != obj); 45 return cyhal_crypto_reserve(&(obj->base), &(obj->resource), CYHAL_CRYPTO_TRNG); 46 } 47 cyhal_trng_free(cyhal_trng_t * obj)48void cyhal_trng_free(cyhal_trng_t *obj) 49 { 50 CY_ASSERT(NULL != obj || obj->resource.type != CYHAL_RSC_CRYPTO); 51 if (obj->resource.type != CYHAL_RSC_INVALID) 52 { 53 cyhal_crypto_free(obj->base, &(obj->resource), CYHAL_CRYPTO_TRNG); 54 } 55 } 56 57 #if defined(__cplusplus) 58 } 59 #endif 60 61 #endif /* CYHAL_DRIVER_AVAILABLE_TRNG */ 62