Example for the mcuxClRandomModes component.
#include <mcuxClToolchain.h>
#include <mcuxClExample_Session_Helper.h>
#include <mcuxClCore_Examples.h>
static const uint32_t entropyAndNonceInputInit[MCUXCLCORE_NUM_OF_CPUWORDS_CEIL(MCUXCLRANDOMMODES_TESTMODE_CTR_DRBG_AES256_INIT_ENTROPY_SIZE)] =
{
0xC895B09Fu, 0xDC8A7855u, 0x30D29197u, 0xFFB78DEBu, 0xE05FBED6u, 0xFA18E8BCu, 0x08181916u, 0x22BC51E4u,
0xC88B1DF5u, 0x15343BC6u, 0xD132B62Fu, 0xBC64248Bu, 0xDBFCEBBEu, 0x3CBA96E9u, 0x54FEC285u, 0x51008B28u
};
static const uint32_t entropyInputReseed[MCUXCLCORE_NUM_OF_CPUWORDS_CEIL(MCUXCLRANDOMMODES_TESTMODE_CTR_DRBG_AES256_RESEED_ENTROPY_SIZE)] =
{
0x875CBF2Bu, 0xB691D99Eu, 0x3CB29A98u, 0x46F88260u, 0xCE3BAFD4u, 0x9A39EE02u, 0x06B14989u, 0xF16F46B6u,
0x25DC5BB4u, 0x1B8434F4u, 0x2B30D48Bu, 0xADB5F889u
};
static const uint32_t refOutput[64u / sizeof(uint32_t)] =
{
0x75321468u, 0x42B48F90u, 0x166757D0u, 0x8C9BE44Eu, 0x667A3AF8u, 0x3CC0CF82u, 0x1AA1EEFEu, 0xFF968FB5u,
0x9F8DA237u, 0x218C18B9u, 0x87A0EB74u, 0xF08F03B1u, 0xB91F5360u, 0x2903E42Bu, 0xC332CCEFu, 0x9BEF0FA2u
};
MCUXCLEXAMPLE_FUNCTION(mcuxClRandomModes_TestMode_CtrDrbg_AES256_DRG4_example)
{
mcuxClSession_Descriptor_t sessionDesc;
MCUXCLEXAMPLE_ALLOCATE_AND_INITIALIZE_SESSION(session, MCUXCLRANDOMMODES_MAX_CPU_WA_BUFFER_SIZE, 0u);
uint32_t testModeDescBytes[(MCUXCLRANDOMMODES_TESTMODE_DESCRIPTOR_SIZE + sizeof(uint32_t) - 1U)/sizeof(uint32_t)];
pTestModeDesc,
entropyAndNonceInputInit
));
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
uint32_t context[MCUXCLRANDOMMODES_CTR_DRBG_AES256_CONTEXT_SIZE_IN_WORDS] = {0};
session,
pTestModeDesc
));
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
ALIGNED uint8_t drbg_data1[64u] = {0u};
ALIGNED uint8_t drbg_data2[64u] = {0u};
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
session,
drbgBuf1,
sizeof(drbg_data1)));
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
session,
drbgBuf2,
sizeof(drbg_data2)));
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
bool outputIsExpected = mcuxClCore_assertEqual((const uint8_t*)drbg_data2, (const uint8_t*)refOutput, sizeof(drbg_data2));
if(!outputIsExpected)
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
if(!mcuxClExample_Session_Clean(session))
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
return MCUXCLEXAMPLE_STATUS_OK;
}
Definition of function identifiers for the flow protection mechanism.
Top level header of mcuxClRandom component.
Top level header of mcuxClRandomModes component.
Top-level include file for the mcuxClSession component.
Provides the API for the CSSL flow protection mechanism.
#define MCUXCLBUFFER_INIT(name, info, ptr, size)
Initialize an input/output buffer (mcuxCl_Buffer_t).
Definition mcuxClBuffer.h:67
mcuxClRandom_Status_t mcuxClRandom_reseed(mcuxClSession_Handle_t pSession)
Random data generator reseed function.
mcuxClRandom_Status_t mcuxClRandom_generate(mcuxClSession_Handle_t pSession, mcuxCl_Buffer_t pOut, uint32_t outLength)
Random data generation function.
mcuxClRandom_Status_t mcuxClRandom_uninit(mcuxClSession_Handle_t pSession)
Random data generator uninitialization function.
mcuxClRandom_Status_t mcuxClRandom_init(mcuxClSession_Handle_t pSession, mcuxClRandom_Context_t pContext, mcuxClRandom_Mode_t mode)
Random data generator initialization function.
mcuxClRandom_ContextDescriptor_t * mcuxClRandom_Context_t
Random context type.
Definition mcuxClRandom_Types.h:71
struct mcuxClRandom_ModeDescriptor mcuxClRandom_ModeDescriptor_t
Random data generation mode/algorithm descriptor type.
Definition mcuxClRandom_Types.h:87
#define mcuxClRandomModes_Mode_CtrDrbg_AES256_DRG4
Mode for a NIST SP800-90A CTR_DRBG based on AES-256 configured to not provide prediction resistance a...
Definition mcuxClRandomModes_Constants.h:74
mcuxClRandom_Status_t mcuxClRandomModes_createTestFromNormalMode(mcuxClRandom_ModeDescriptor_t *pTestMode, mcuxClRandom_Mode_t normalMode, const uint32_t *const pCustomSeed)
This function creates a TEST_MODE descriptor from an existing NORMAL_MODE one.
mcuxClRandom_Status_t mcuxClRandomModes_updateEntropyInput(mcuxClRandom_ModeDescriptor_t *pTestMode, const uint32_t *const pCustomSeed)
This function updates the custom seed pointer in a TEST_MODE descriptor.
mcuxClSession_Descriptor_t *const mcuxClSession_Handle_t
Type for mcuxClSession Handle.
Definition mcuxClSession_Types.h:98
#define MCUX_CSSL_FP_FUNCTION_CALL_BEGIN(...)
Call a flow protected function and check the protection token.
Definition mcuxCsslFlowProtection.h:623
#define MCUX_CSSL_FP_FUNCTION_CALLED(...)
Expectation of a called function.
Definition mcuxCsslFlowProtection.h:777
#define MCUX_CSSL_FP_FUNCTION_CALL_END(...)
End a function call section started by MCUX_CSSL_FP_FUNCTION_CALL_BEGIN.
Definition mcuxCsslFlowProtection.h:658
#define MCUXCLRANDOM_STATUS_OK
Random function returned successfully.
Definition mcuxClRandom_Constants.h:46