TLS key derivation example.
#include <mcuxClToolchain.h>
#include <mcuxClCore_Examples.h>
#include <mcuxClExample_ELS_Helper.h>
#include <mcuxClExample_ELS_Key_Helper.h>
static ALIGNED uint8_t master_key_string[] =
"master secret";
static ALIGNED uint8_t key_expansion_string[] =
"key expansion";
MCUXCLEXAMPLE_FUNCTION(mcuxClEls_Tls_Master_Key_Session_Keys_example)
{
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
KeyGenOptions,
keyIdxPrivClient,
GenKeyProp,
NULL,
ecc_public_key_client
));
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
KeyGenOptions,
keyIdxPrivServer,
GenKeyProp,
NULL,
ecc_public_key_server
));
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
keyIdxPrivClient,
ecc_public_key_server,
sharedSecretIdx,
SharedSecretProp));
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
derivation_data,
key_expansion_string,
sizeof(key_expansion_string),
sizeof(key_expansion_string)
));
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
derivation_data+sizeof(key_expansion_string),
server_random,
sizeof(server_random),
sizeof(server_random)
));
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
derivation_data+sizeof(key_expansion_string)+32U,
client_random,
sizeof(client_random),
sizeof(client_random)
));
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
derivation_data+sizeof(key_expansion_string)+32U+32U,
0x80,
1U,
1U
));
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
derivation_data+sizeof(key_expansion_string)+32U+32U+1U,
0x00,
2U,
2U
));
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
derivation_data,
tlsMasterKeyProp,
sharedSecretIdx
));
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
derivation_data,
master_key_string,
sizeof(master_key_string),
sizeof(master_key_string)
));
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
derivation_data+sizeof(master_key_string),
client_random,
sizeof(client_random),
sizeof(client_random)
));
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
derivation_data+sizeof(master_key_string)+32U,
server_random,
sizeof(server_random),
sizeof(server_random)
));
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
derivation_data+sizeof(master_key_string)+32U+32U,
0x80,
1U,
1U
));
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
derivation_data+sizeof(master_key_string)+32U+32U+1U,
0x00,
2U,
2U
));
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
derivation_data,
GenKeyProp,
sharedSecretIdx
));
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
if(!mcuxClExample_Els_KeyDelete(keyIdxPrivClient))
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
if(!mcuxClExample_Els_KeyDelete(keyIdxPrivServer))
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
{
if(!mcuxClExample_Els_KeyDelete(i))
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
}
return MCUXCLEXAMPLE_STATUS_OK;
}
static mcuxClEls_EccByte_t ecc_public_key_client[MCUXCLELS_ECC_PUBLICKEY_SIZE] ALIGNED
Destination buffer to receive the public key of the mcuxClEls_EccKeyGen_Async operation.
Definition mcuxClEls_Tls_Master_Key_Session_Keys_example.c:33
Definition of function identifiers for the flow protection mechanism.
Top-level include file for the ELS driver.
Top-level include file for the memory operations.
Provides the API for the CSSL flow protection mechanism.
#define MCUXCLELS_ERROR_FLAGS_CLEAR
Set this option at mcuxClEls_ErrorHandling_t to clear all ELS error flags.
Definition mcuxClEls_Common.h:110
#define MCUXCLELS_RESET_DO_NOT_CANCEL
Set this option at mcuxClEls_ResetOption_t to abort the requested command if another ELS operation is...
Definition mcuxClEls_Common.h:119
MCUXCLELS_API mcuxClEls_Status_t mcuxClEls_LimitedWaitForOperation(uint32_t counterLimit, mcuxClEls_ErrorHandling_t errorHandling)
Await the completion of an ELS operation for a limited amount of time and optionally clear the error ...
#define MCUXCLELS_ECC_OUTPUTKEY_RANDOM
Set this option at mcuxClEls_EccKeyGenOption_t.kgsrc to specify output key is random.
Definition mcuxClEls_Ecc.h:115
#define MCUXCLELS_ECC_OUTPUTKEY_KEYEXCHANGE
Set this option at mcuxClEls_EccKeyGenOption_t.kgtypedh to specify output key will be a Diffie Helman...
Definition mcuxClEls_Ecc.h:112
#define MCUXCLELS_ECC_PUBLICKEY_SIZE
Size of the public key.
Definition mcuxClEls_Ecc.h:151
uint8_t mcuxClEls_EccByte_t
Data type for ECC parameters in ELS format.
Definition mcuxClEls_Ecc.h:177
MCUXCLELS_API mcuxClEls_Status_t mcuxClEls_EccKeyGen_Async(mcuxClEls_EccKeyGenOption_t options, mcuxClEls_KeyIndex_t signingKeyIdx, mcuxClEls_KeyIndex_t privateKeyIdx, mcuxClEls_KeyProp_t generatedKeyProperties, uint8_t const *pRandomData, uint8_t *pPublicKey)
Generates an ECC key pair on the NIST P-256 curve.
MCUXCLELS_API mcuxClEls_Status_t mcuxClEls_EccKeyExchange_Async(mcuxClEls_KeyIndex_t privateKeyIdx, uint8_t const *pPublicKey, mcuxClEls_KeyIndex_t sharedSecretIdx, mcuxClEls_KeyProp_t sharedSecretProperties)
Performs a Diffie-Hellman key exchange with an internal ECC private key and an external ECC public ke...
#define MCUXCLELS_TLS_DERIVATIONDATA_SIZE
Size of TLS derivation data.
Definition mcuxClEls_Kdf.h:82
#define MCUXCLELS_TLS_RANDOM_SIZE
Size of random bytes for TLS.
Definition mcuxClEls_Kdf.h:83
MCUXCLELS_API mcuxClEls_Status_t mcuxClEls_TlsGenerateSessionKeysFromMasterKey_Async(uint8_t const *pDerivationData, mcuxClEls_KeyProp_t keyProperties, mcuxClEls_KeyIndex_t keyIdx)
Generates TLS session keys based on a master key and derivation data, according to the TLS 1....
MCUXCLELS_API mcuxClEls_Status_t mcuxClEls_TlsGenerateMasterKeyFromPreMasterKey_Async(uint8_t const *pDerivationData, mcuxClEls_KeyProp_t keyProperties, mcuxClEls_KeyIndex_t keyIdx)
Generates a TLS master key based on a pre-master key and derivation data, according to the TLS 1....
MCUXCLELS_API mcuxClEls_Status_t mcuxClEls_GetKeyProperties(mcuxClEls_KeyIndex_t keyIdx, mcuxClEls_KeyProp_t *pKeyProp)
Exports the properties of the keys stored in the ELS internal keystore.
MCUXCLELS_API mcuxClEls_Status_t mcuxClEls_Prng_GetRandom(uint8_t *pOutput, size_t outputLength)
Writes random data from the ELS PRNG to the given buffer.
#define MCUXCLELS_KEYPROPERTY_SECURE_TRUE
This value of mcuxClEls_KeyProp_t.upprot_sec indicates that the caller must be in secure mode to use ...
Definition mcuxClEls_Types.h:158
#define MCUXCLELS_KEYPROPERTY_TLS_MASTER_SECRET_TRUE
This value of mcuxClEls_KeyProp_t.utlsms indicates that the key is a TLS Master Secret.
Definition mcuxClEls_Types.h:146
#define MCUXCLELS_KEYPROPERTY_PRIVILEGED_FALSE
This value of mcuxClEls_KeyProp_t.upprot_priv indicates that the caller does not need to be in privil...
Definition mcuxClEls_Types.h:157
#define MCUXCLELS_KEYPROPERTY_TLS_PREMASTER_SECRET_TRUE
This value of mcuxClEls_KeyProp_t.utlspms indicates that the key is a TLS Premaster Secret.
Definition mcuxClEls_Types.h:144
#define MCUXCLELS_STATUS_OK
No error occurred.
Definition mcuxClEls_Types.h:171
#define MCUXCLELS_STATUS_OK_WAIT
An _Async function successfully started an ELS command. Call mcuxClEls_WaitForOperation to complete i...
Definition mcuxClEls_Types.h:172
uint32_t mcuxClEls_KeyIndex_t
Type for ELS keystore indices.
Definition mcuxClEls_Types.h:222
void mcuxClMemory_copy(uint8_t *pDst, uint8_t const *pSrc, size_t length, size_t bufLength)
Copies a memory buffer to another location.
void mcuxClMemory_set(uint8_t *pDst, uint8_t val, size_t length, size_t bufLength)
Sets all bytes of a memory buffer to a specified value.
#define MCUX_CSSL_FP_FUNCTION_CALL_VOID_BEGIN(...)
Call a flow protected void function and check the protection token.
Definition mcuxCsslFlowProtection.h:652
#define MCUX_CSSL_FP_FUNCTION_CALL_VOID_END(...)
End a void function call section started by MCUX_CSSL_FP_FUNCTION_CALL_VOID_BEGIN.
Definition mcuxCsslFlowProtection.h:683
#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
Command option bit field for mcuxClEls_EccKeyGen_Async Bit field to configure mcuxClEls_EccKeyGenOpti...
Definition mcuxClEls_Ecc.h:229
struct mcuxClEls_EccKeyGenOption_t::@23 bits
Access mcuxClEls_EccKeyGenOption_t bit-wise.
uint32_t kgsrc
Define if the output key is deterministic or random.
Definition mcuxClEls_Ecc.h:238
uint32_t kgtypedh
Define the usage of the output key.
Definition mcuxClEls_Ecc.h:237
Type for ELS key store key properties.
Definition mcuxClEls_Types.h:226
uint32_t upprot_sec
Access restriction to TrustZone secure mode.
Definition mcuxClEls_Types.h:270
struct mcuxClEls_KeyProp_t::@39 bits
Access mcuxClEls_KeyProp_t bit-wise.
uint32_t upprot_priv
Access restriction to privileged mode.
Definition mcuxClEls_Types.h:269
uint32_t utlsms
Usage permission as a TLS master secret.
Definition mcuxClEls_Types.h:264