corePKCS11
v3.2.0
PKCS #11 Cryptoki Library
|
|
Generates random data.
CK_BYTE_PTR RandomData,
CK_ULONG ulRandomLen )
{
CK_RV xResult = CKR_OK;
int32_t lMbedTLSResult = 0;
if( ( NULL == RandomData ) ||
( ulRandomLen == 0UL ) )
{
LogError( (
"Failed to generate random bytes. The buffer to store "
"random numbers in was NULL or the length of the buffer was 0." ) );
xResult = CKR_ARGUMENTS_BAD;
}
if( xResult == CKR_OK )
{
if( lMbedTLSResult != 0 )
{
LogError( (
"Failed to generate random bytes. mbed TLS DRBG failed "
"to generate a random number: mbed TLS error = %s : %s.",
xResult = CKR_FUNCTION_FAILED;
}
else
{
LogDebug( (
"Successfully generated %lu random bytes.", (
unsigned long int ) ulRandomLen ) );
}
}
return xResult;
}
- Parameters
-
[in] | hSession | Handle of a valid PKCS #11 session. |
[out] | RandomData | Pointer to location that random data will be placed. It is the responsibility of the application to allocate this memory. |
[in] | ulRandomLen | Length of data (in bytes) to be generated. |
- Returns
- CKR_OK if successful.
#define mbedtlsLowLevelCodeOrDefault(mbedTlsCode)
Utility for converting the level-level code in an mbedTLS error to string, if the code-contains a lev...
Definition: core_pkcs11_mbedtls.c:90
static P11Struct_t xP11Context
The global PKCS #11 module object. Entropy/randomness and object lists are shared across PKCS #11 ses...
Definition: core_pkcs11_mbedtls.c:313
#define LogDebug(message)
Macro that is called in the corePKCS11 library for logging "Debug" level messages.
Definition: core_pkcs11_config_defaults.h:375
mbedtls_ctr_drbg_context xMbedDrbgCtx
CTR-DRBG context for PKCS #11 module - used to generate pseudo-random numbers.
Definition: core_pkcs11_mbedtls.c:273
CK_RV C_GenerateRandom(CK_SESSION_HANDLE hSession, CK_BYTE_PTR RandomData, CK_ULONG ulRandomLen)
Generates random data.
Definition: core_pkcs11_mbedtls.c:5589
static CK_RV prvCheckValidSessionAndModule(const P11Session_t *pxSession)
Helper to check if the current session is initialized and valid.
Definition: core_pkcs11_mbedtls.c:323
#define CK_DECLARE_FUNCTION(returnType, name)
Macro for defining a PKCS #11 functions.
Definition: core_pkcs11.h:75
static P11Session_t * prvSessionPointerFromHandle(CK_SESSION_HANDLE xSession)
Maps an opaque caller session handle into its internal state structure.
Definition: core_pkcs11_mbedtls.c:365
Session structure.
Definition: core_pkcs11_mbedtls.c:286
#define LogError(message)
Macro that is called in the corePKCS11 library for logging "Error" level messages.
Definition: core_pkcs11_config_defaults.h:315
#define mbedtlsHighLevelCodeOrDefault(mbedTlsCode)
Utility for converting the high-level code in an mbedTLS error to string, if the code-contains a high...
Definition: core_pkcs11_mbedtls.c:82