FreeRTOS: PKCS11
PKCS11 Cryptoki Library
Return to main page ↑
C_GenerateRandom

Generates random data.

CK_DECLARE_FUNCTION( CK_RV, C_GenerateRandom )( CK_SESSION_HANDLE hSession,
CK_BYTE_PTR RandomData,
CK_ULONG ulRandomLen )
{
CK_RV xResult = CKR_OK;
int32_t lMbedResult = 0;
const P11Session_t * pxSession = prvSessionPointerFromHandle( hSession );
xResult = prvCheckValidSessionAndModule( pxSession );
if( ( NULL == RandomData ) ||
( ulRandomLen == 0UL ) )
{
xResult = CKR_ARGUMENTS_BAD;
}
if( xResult == CKR_OK )
{
lMbedResult = mbedtls_ctr_drbg_random( &xP11Context.xMbedDrbgCtx, RandomData, ulRandomLen );
if( lMbedResult != 0 )
{
PKCS11_PRINT( ( "ERROR: DRBG failed %d \r\n", lMbedResult ) );
xResult = CKR_FUNCTION_FAILED;
}
}
return xResult;
}
Parameters
[in]hSessionHandle of a valid PKCS #11 session.
[out]RandomDataPointer to location that random data will be placed. It is the responsiblity of the application to allocate this memory.
[in]ulRandomLenLength of data (in bytes) to be generated.
Returns
CKR_OK if successful. Else, see PKCS #11 specification for more information.
C_GenerateRandom
CK_RV C_GenerateRandom(CK_SESSION_HANDLE hSession, CK_BYTE_PTR RandomData, CK_ULONG ulRandomLen)
Generates random data.
Definition: iot_pkcs11_mbedtls.c:4416
CK_DECLARE_FUNCTION
#define CK_DECLARE_FUNCTION(returnType, name)
Macro for defining a PKCS #11 functions.
Definition: iot_pkcs11.h:66
PKCS11_PRINT
#define PKCS11_PRINT(X)
Macro for logging in PKCS #11.
Definition: iot_pkcs11_mbedtls.c:103
prvSessionPointerFromHandle
static P11Session_t * prvSessionPointerFromHandle(CK_SESSION_HANDLE xSession)
Maps an opaque caller session handle into its internal state structure.
Definition: iot_pkcs11_mbedtls.c:287
prvCheckValidSessionAndModule
static CK_RV prvCheckValidSessionAndModule(const P11Session_t *pxSession)
Helper to check if the current session is initialized and valid.
Definition: iot_pkcs11_mbedtls.c:248
P11Struct_t::xMbedDrbgCtx
mbedtls_ctr_drbg_context xMbedDrbgCtx
CTR-DRBG context for PKCS #11 module - used to generate pseudo-random numbers.
Definition: iot_pkcs11_mbedtls.c:203
P11Session_t
Session structure.
Definition: iot_pkcs11_mbedtls.c:217
xP11Context
static P11Struct_t xP11Context
The global PKCS #11 module object. Entropy/randomness and object lists are shared across PKCS #11 ses...
Definition: iot_pkcs11_mbedtls.c:238