#include <mcuxClToolchain.h>
#include <mcuxClCore_Examples.h>
#include <mcuxClExample_Session_Helper.h>
#include <mcuxClExample_RNG_Helper.h>
static const ALIGNED uint8_t hmac_key[] = {
0x00u, 0x11u, 0x22u, 0x33u, 0x44u, 0x55u, 0x66u, 0x77u,
0x88u, 0x99u, 0xaau, 0xbbu, 0xccu, 0xddu, 0xeeu, 0xffu,
0x00u, 0x11u, 0x22u, 0x33u, 0x44u, 0x55u, 0x66u, 0x77u,
0x88u, 0x99u, 0xaau, 0xbbu, 0xccu, 0xddu, 0xeeu, 0xffu
};
static const ALIGNED uint8_t hmac_input_part1[] = {
0x00u, 0x9fu, 0x5eu, 0x39u, 0x94u, 0x30u, 0x03u, 0x82u,
0x50u, 0x72u, 0x1bu, 0xe1u, 0x79u, 0x65u, 0x35u, 0xffu,
0x21u, 0xa6u, 0x09u, 0xfdu, 0xf9u, 0xf0u, 0xf6u, 0x12u,
0x66u, 0xe3u
};
static const ALIGNED uint8_t hmac_input_part2[] = {
0xafu, 0x75u, 0xd7u, 0x04u, 0x31u, 0x7du, 0x55u, 0x06u,
0xf8u, 0x06u, 0x5cu, 0x48u, 0x72u, 0x18u, 0xe9u, 0x9eu,
0xb4u, 0xc3u, 0xd4u, 0x54u, 0x6cu, 0x4du, 0x60u, 0x70u,
0x16u, 0x90u, 0x11u, 0x38u, 0x73u, 0x9du, 0xbdu, 0xf4u,
0x37u, 0xa5u, 0xe6u, 0xf5u, 0x02u, 0x1au
};
0x06u, 0xb8u, 0xb8u, 0xc3u, 0x21u, 0x79u, 0x15u, 0xbeu,
0x0bu, 0x0fu, 0x86u, 0x90u, 0x4fu, 0x76u, 0x74u, 0x1bu,
0x1bu, 0xe2u, 0x86u, 0x79u, 0x38u, 0xf4u, 0xf0u, 0x5du,
0x34u, 0x15u, 0xbbu, 0x36u, 0x8fu, 0x4au, 0x57u, 0xfbu
};
MCUXCLEXAMPLE_FUNCTION(mcuxClHmac_Sw_Multipart_example)
{
mcuxClSession_Descriptor_t sessionDesc;
MCUXCLEXAMPLE_ALLOCATE_AND_INITIALIZE_SESSION(session, MCUXCLEXAMPLE_MAX_WA(MCUXCLHMAC_MAX_CPU_WA_BUFFER_SIZE, MCUXCLRANDOM_NCINIT_WACPU_SIZE), 0u);
MCUXCLEXAMPLE_INITIALIZE_PRNG(session);
uint32_t keyDesc[MCUXCLKEY_DESCRIPTOR_SIZE_IN_WORDS];
MCUX_CSSL_ANALYSIS_START_PATTERN_REINTERPRET_MEMORY_OF_OPAQUE_TYPES()
MCUX_CSSL_ANALYSIS_STOP_PATTERN_REINTERPRET_MEMORY_OF_OPAQUE_TYPES()
session,
key,
MCUX_CSSL_ANALYSIS_START_SUPPRESS_DISCARD_CONST("Required by API function")
(uint8_t *) hmac_key,
MCUX_CSSL_ANALYSIS_STOP_SUPPRESS_DISCARD_CONST()
sizeof(hmac_key)));
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
ALIGNED uint8_t hmacModeDescBuffer[MCUXCLHMAC_HMAC_MODE_DESCRIPTOR_SIZE];
MCUX_CSSL_ANALYSIS_START_PATTERN_REINTERPRET_MEMORY_OF_OPAQUE_TYPES()
MCUX_CSSL_ANALYSIS_STOP_PATTERN_REINTERPRET_MEMORY_OF_OPAQUE_TYPES()
mode,
);
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
uint8_t result[MCUXCLHMAC_MAX_OUTPUT_SIZE];
uint32_t result_size = 0u;
ALIGNED uint8_t ctxBuf[MCUXCLHMAC_CONTEXT_SIZE_SW];
MCUX_CSSL_ANALYSIS_START_PATTERN_REINTERPRET_MEMORY_OF_OPAQUE_TYPES()
MCUX_CSSL_ANALYSIS_STOP_PATTERN_REINTERPRET_MEMORY_OF_OPAQUE_TYPES()
session,
ctx,
key,
mode)
);
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
session,
MCUX_CSSL_ANALYSIS_START_SUPPRESS_ALREADY_INITIALIZED("Initialized by mcuxClMac_init")
ctx,
MCUX_CSSL_ANALYSIS_STOP_SUPPRESS_ALREADY_INITIALIZED()
inputBuf1,
sizeof(hmac_input_part1))
);
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
session,
MCUX_CSSL_ANALYSIS_START_SUPPRESS_ALREADY_INITIALIZED("Initialized by mcuxClMac_init")
ctx,
MCUX_CSSL_ANALYSIS_STOP_SUPPRESS_ALREADY_INITIALIZED()
inputBuf2,
sizeof(hmac_input_part2))
);
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
session,
MCUX_CSSL_ANALYSIS_START_SUPPRESS_ALREADY_INITIALIZED("Initialized by mcuxClMac_init")
ctx,
MCUX_CSSL_ANALYSIS_STOP_SUPPRESS_ALREADY_INITIALIZED()
resultBuf,
&result_size)
);
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
if(sizeof(hmac_output_reference) != result_size)
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
if(!mcuxClCore_assertEqual(hmac_output_reference, result, sizeof(hmac_output_reference)))
{
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 include file for the mcuxClHash component.
Top-level include file for the mcuxClHashModes component.
Top-level include file for the mcuxClHmac component.
Top-level include file for the mcuxClKey component.
Top-level include file for the mcuxClMac component.
Top-level include file for the mcuxClSession component.
Provides the API for the CSSL flow protection mechanism.
#define MCUXCLBUFFER_INIT_RW(name, info, ptr, size)
Initialize an input/output buffer (mcuxCl_Buffer_t) with plain CPU handling.
Definition mcuxClBuffer.h:101
#define MCUXCLBUFFER_INIT_RO(name, info, ptr, size)
Initialize an input buffer (mcuxCl_InputBuffer_t) with plain CPU handling.
Definition mcuxClBuffer.h:84
static mcuxClHash_Algo_t mcuxClHash_Algorithm_Sha256
Sha-256 algorithm descriptor Sha-256 hash calculation using the Hash functionality SGI.
Definition mcuxClHashModes_Algorithms.h:96
#define MCUXCLHASH_OUTPUT_SIZE_SHA_256
SHA-256 output size: 256 bit (32 bytes).
Definition mcuxClHashModes_Constants.h:38
mcuxClMac_Status_t mcuxClHmac_createHmacMode(mcuxClMac_CustomMode_t mode, mcuxClHash_Algo_t hashAlgorithm)
This function creates a HMAC mode descriptor for software implementations of HMAC.
static const mcuxClKey_Type_t mcuxClKey_Type_Hmac_variableLength
Key type pointer for HMAC keys with variable length.
Definition mcuxClHmac_KeyTypes.h:47
#define MCUXCLKEY_STATUS_OK
Key operation successful.
Definition mcuxClKey_Constants.h:40
mcuxClKey_Status_t mcuxClKey_init(mcuxClSession_Handle_t session, mcuxClKey_Handle_t key, mcuxClKey_Type_t type, const uint8_t *pKeyData, uint32_t keyDataLength)
Initializes a key handle.
mcuxClKey_Descriptor_t *const mcuxClKey_Handle_t
Key handle type.
Definition mcuxClKey_Types.h:91
#define MCUXCLMAC_STATUS_OK
Blocking operation finished successfully.
Definition mcuxClMac_Constants.h:36
mcuxClMac_Status_t mcuxClMac_process(mcuxClSession_Handle_t session, mcuxClMac_Context_t *const pContext, mcuxCl_InputBuffer_t pIn, uint32_t inLength)
Data processing for a multipart MAC computation.
mcuxClMac_Status_t mcuxClMac_init(mcuxClSession_Handle_t session, mcuxClMac_Context_t *const pContext, mcuxClKey_Handle_t key, mcuxClMac_Mode_t mode)
Initialization for a multipart MAC computation.
mcuxClMac_Status_t mcuxClMac_finish(mcuxClSession_Handle_t session, mcuxClMac_Context_t *const pContext, mcuxCl_Buffer_t pMac, uint32_t *const pMacLength)
Finalize a MAC generation for a multipart MAC computation.
mcuxClMac_ModeDescriptor_t *const mcuxClMac_CustomMode_t
MAC custom mode/algorithm type.
Definition mcuxClMac_Types.h:75
struct mcuxClMac_Context mcuxClMac_Context_t
Mac context type.
Definition mcuxClMac_Types.h:98
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