MCUX CLNS
MCUX Crypto Library Normal Secure
 
Loading...
Searching...
No Matches
mcuxClKey_example.c

Example for the mcuxClKey component.

Example for the mcuxClKey component

/*--------------------------------------------------------------------------*/
/* Copyright 2021-2023 NXP */
/* */
/* NXP Confidential. This software is owned or controlled by NXP and may */
/* only be used strictly in accordance with the applicable license terms. */
/* By expressly accepting such terms or by downloading, installing, */
/* activating and/or otherwise using the software, you are agreeing that */
/* you have read, and that you agree to comply with and are bound by, such */
/* license terms. If you do not agree to be bound by the applicable license */
/* terms, then you may not retain, install, activate or otherwise use the */
/* software. */
/*--------------------------------------------------------------------------*/
#include <mcuxClKey.h>
#include <mcuxClSession.h>
#include <mcuxClCore_FunctionIdentifiers.h> // Code flow protection
#include <mcuxClCore_Examples.h>
#include <stdbool.h> // bool type for the example's return code
#include <mcuxClAes.h>
#include <mcuxClExample_Session_Helper.h>
#include <mcuxClExample_Key_Helper.h>
/* Example AES-128 key. */
{
0xb97d0b7cu, 0xd0101f81u, 0x7a6c470eu, 0xe0f6920du
};
MCUXCLEXAMPLE_FUNCTION(mcuxClKey_example)
{
/**************************************************************************/
/* Preparation */
/**************************************************************************/
//Allocate and initialize session
MCUXCLEXAMPLE_ALLOCATE_AND_INITIALIZE_SESSION(&session, 0u, 0u);
/**************************************************************************/
/* Key setup */
/**************************************************************************/
/* Create and initialize mcuxClKey_Descriptor_t structure. */
uint32_t keyDesc[MCUXCLKEY_DESCRIPTOR_SIZE_IN_WORDS];
/* Set key properties. */
mcuxClEls_KeyProp_t key_properties;
key_properties.word.value = 0u;
/* Key buffer for the key in memory. */
uint32_t key_buffer[MCUXCLAES_AES128_KEY_SIZE_IN_WORDS];
//Initializes a key handle, Set key properties and Load key.
if(!mcuxClExample_Key_Init_And_Load(&session,
key,
(uint8_t *) aes128_key,
sizeof(aes128_key),
&key_properties,
key_buffer, MCUXCLEXAMPLE_CONST_EXTERNAL_KEY))
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
/**************************************************************************/
/* The key could now be used for a cryptographic operation. */
/**************************************************************************/
/**************************************************************************/
/* Cleanup */
/**************************************************************************/
/* Flush the key. */
&session,
key));
if((MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClKey_flush) != tokenFlush) || (MCUXCLKEY_STATUS_OK != resultFlush))
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
if(!mcuxClExample_Session_Clean(&session))
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
return MCUXCLEXAMPLE_STATUS_OK;
}
static uint32_t const aes128_key[MCUXCLELS_CIPHER_KEY_SIZE_AES_128/sizeof(uint32_t)]
Key for the AES encryption.
Definition mcuxClEls_Cipher_Aes128_Ecb_Encrypt_example.c:42
Top-level interface header for the mcuxClAes component.
Definition of function identifiers for the flow protection mechanism.
Top-level include file for the mcuxClKey component.
Top-level include file for the mcuxClSession component.
Provides the API for the CSSL flow protection mechanism.
#define MCUXCLAES_AES128_KEY_SIZE_IN_WORDS
AES-128 key size in words.
Definition mcuxClAes_Constants.h:42
static const mcuxClKey_Type_t mcuxClKey_Type_Aes128
Key type pointer for AES-128 based keys.
Definition mcuxClAes_KeyTypes.h:50
#define MCUXCLELS_KEYPROPERTY_KEY_SIZE_128
This value of mcuxClEls_KeyProp_t.ksize indicates a 128 bit key.
Definition mcuxClEls_Types.h:101
#define MCUXCLELS_KEYPROPERTY_ACTIVE_TRUE
This value of mcuxClEls_KeyProp_t.kactv indicates that the slot contains an active key.
Definition mcuxClEls_Types.h:106
#define MCUXCLKEY_STATUS_OK
Key operation successful.
Definition mcuxClKey_Constants.h:39
mcuxClKey_Status_t mcuxClKey_flush(mcuxClSession_Handle_t pSession, mcuxClKey_Handle_t key)
Flush key from destination which can be a key slot of coprocessor or memory buffer.
mcuxClKey_Descriptor_t *const mcuxClKey_Handle_t
Key handle type.
Definition mcuxClKey_Types.h:88
#define MCUX_CSSL_FP_FUNCTION_CALL_BEGIN(...)
Call a flow protected function and check the protection token.
Definition mcuxCsslFlowProtection.h:581
#define MCUX_CSSL_FP_FUNCTION_CALLED(...)
Expectation of a called function.
Definition mcuxCsslFlowProtection.h:735
#define MCUX_CSSL_FP_FUNCTION_CALL_END(...)
End a function call section started by MCUX_CSSL_FP_FUNCTION_CALL_BEGIN.
Definition mcuxCsslFlowProtection.h:616
Type for ELS key store key properties.
Definition mcuxClEls_Types.h:226
struct mcuxClEls_KeyProp_t::@39 bits
Access mcuxClEls_KeyProp_t bit-wise.
uint32_t ksize
Key size.
Definition mcuxClEls_Types.h:237
struct mcuxClEls_KeyProp_t::@38 word
Access mcuxClEls_KeyProp_t word-wise.
uint32_t kactv
Status flag to indicate whether the key slot contains an active key or not.
Definition mcuxClEls_Types.h:240
uint32_t value
Accesses the bit field as a full word; initialize with a combination of constants from MCUXCLELS_KEYP...
Definition mcuxClEls_Types.h:229
Structure for mcuxClSession Descriptor.
Definition mcuxClSession_Types.h:121