1 /* 2 * Copyright (c) 2001-2019, Arm Limited and Contributors. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 /*! 8 @addtogroup cc_pal_trng 9 @{ 10 */ 11 12 /*! 13 @file 14 @brief This file contains APIs for retrieving TRNG user parameters. 15 */ 16 17 #ifndef _CC_PAL_TRNG_H 18 #define _CC_PAL_TRNG_H 19 20 #ifdef __cplusplus 21 extern "C" 22 { 23 #endif 24 25 #include "cc_pal_types.h" 26 27 #if (CC_CONFIG_TRNG_MODE==1) 28 /*! 29 @brief The random-generator parameters of CryptoCell for TRNG mode. 30 31 This is as defined in <em>NIST SP 90B: Recommendation for 32 the Entropy Sources Used for Random Bit Generation</em>. 33 */ 34 typedef struct CC_PalTrngModeParams_t 35 { 36 /*! The amount of bytes for the required entropy bits. It is calculated as 37 ROUND_UP(ROUND_UP(((required entropy bits)/(entropy per bit)), 1024), 38 (EHR width in bytes)) / 8. 39 The 1024 bits is the multiple of the window size. The multiple of the EHR 40 width, which is 192 bits. */ 41 uint32_t numOfBytes; 42 /*! The repetition counter cutoff, as defined in <em>NIST SP 90B: 43 Recommendation for the Entropy Sources Used for Random Bit 44 Generation</em>, section 4.4.1. 45 This is calculated as C = ROUND_UP(1+(-log(W)/H)), W = 2^(-40), 46 H=(entropy per bit). */ 47 uint32_t repetitionCounterCutoff; 48 /*! The adaptive proportion cutoff, as defined in <em>NIST SP 90B: 49 Recommendation for the Entropy Sources Used for Random Bit 50 Generation</em>, section 4.4.2. 51 This is calculated as C =CRITBINOM(W, power(2,(-H)),1-a), W = 1024, 52 a = 2^(-40), H=(entropy per bit). */ 53 uint32_t adaptiveProportionCutOff; 54 55 } CC_PalTrngModeParams_t; 56 #endif 57 58 /*! Definition for the structure of the random-generator parameters 59 of CryptoCell, containing the user-given parameters. */ 60 typedef struct CC_PalTrngParams_t 61 { 62 /*! The sampling ratio of ROSC #1.*/ 63 uint32_t SubSamplingRatio1; 64 /*! The sampling ratio of ROSC #2.*/ 65 uint32_t SubSamplingRatio2; 66 /*! The sampling ratio of ROSC #3.*/ 67 uint32_t SubSamplingRatio3; 68 /*! The sampling ratio of ROSC #4.*/ 69 uint32_t SubSamplingRatio4; 70 #if (CC_CONFIG_TRNG_MODE==1) 71 /*! Specific parameters of the TRNG mode.*/ 72 CC_PalTrngModeParams_t trngModeParams; 73 #endif 74 } CC_PalTrngParams_t; 75 76 /*---------------------------- 77 PUBLIC FUNCTIONS 78 -----------------------------------*/ 79 80 /*! 81 @brief This function returns the TRNG user parameters. 82 83 @return \c 0 on success. 84 @return A non-zero value on failure. 85 */ 86 CCError_t CC_PalTrngParamGet( 87 /*! [out] A pointer to the TRNG user parameters. */ 88 CC_PalTrngParams_t *pTrngParams, 89 /*! [in/out] A pointer to the size of the TRNG-user-parameters 90 structure used. Input: the function must verify its size is the 91 same as #CC_PalTrngParams_t. Output: the function returns the size 92 of #CC_PalTrngParams_t for library-size verification. */ 93 size_t *pParamsSize 94 ); 95 96 #ifdef __cplusplus 97 } 98 #endif 99 100 /*! 101 @} 102 */ 103 #endif 104 105 106