Example of ECC for key generation, signing and verification using the ELS (CLNS component mcuxClEls)
Example of ECC for key generation, signing and verification using the ELS (CLNS component mcuxClEls)
#include <mcuxClToolchain.h>
#include <mcuxClCore_Examples.h>
#include <mcuxClExample_ELS_Helper.h>
#include <mcuxClExample_ELS_Key_Helper.h>
0x22222222u,
0x33333333u,
0x44444444u,
0x55555555u,
0x66666666u,
0x77777777u,
0x88888888u};
MCUXCLEXAMPLE_FUNCTION(mcuxClEls_Ecc_Keygen_Sign_Verify_example)
{
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
KeyGenOptions,
keyIdx,
GenKeyProp,
NULL,
));
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
SignOptions,
keyIdx,
));
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
}
}
VerifyOptions,
));
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
if(!mcuxClExample_Els_KeyDelete(keyIdx))
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
if(!mcuxClExample_Els_Disable())
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
return MCUXCLEXAMPLE_STATUS_OK;
}
static uint32_t ecc_signature[MCUXCLELS_ECC_SIGNATURE_SIZE/sizeof(uint32_t)]
Destination buffer to receive the signature of the mcuxClEls_EccSign_Async operation.
Definition mcuxClEls_Ecc_Keygen_Sign_Verify_example.c:45
static uint32_t ecc_signature_and_public_key[(MCUXCLELS_ECC_SIGNATURE_SIZE+MCUXCLELS_ECC_PUBLICKEY_SIZE)/sizeof(uint32_t)]
Concatenation of the ECC signature and public key, needed for the mcuxClEls_EccVerify_Async operation...
Definition mcuxClEls_Ecc_Keygen_Sign_Verify_example.c:53
static uint32_t ecc_public_key[MCUXCLELS_ECC_PUBLICKEY_SIZE/sizeof(uint32_t)]
Destination buffer to receive the public key of the mcuxClEls_EccKeyGen_Async operation.
Definition mcuxClEls_Ecc_Keygen_Sign_Verify_example.c:42
static uint32_t const ecc_digest[MCUXCLELS_HASH_OUTPUT_SIZE_SHA_256/sizeof(uint32_t)]
Pre-hashed data to be signed.
Definition mcuxClEls_Ecc_Keygen_Sign_Verify_example.c:32
static uint32_t ecc_signature_r[MCUXCLELS_ECC_SIGNATURE_R_SIZE/sizeof(uint32_t)]
Destination buffer to receive the signature part r of the VerifyOptions operation.
Definition mcuxClEls_Ecc_Keygen_Sign_Verify_example.c:49
Definition of function identifiers for the flow protection mechanism.
Top-level include file for the ELS driver.
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
#define MCUXCLELS_STATUS_ECDSAVFY_OK
This value of mcuxClEls_HwState_t.ecdsavfy means that the most recently finished ECDSA signature veri...
Definition mcuxClEls_Common.h:148
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 ...
MCUXCLELS_API mcuxClEls_Status_t mcuxClEls_GetHwState(mcuxClEls_HwState_t *result)
Determines the current state of the ELS.
#define MCUXCLELS_ECC_NO_RANDOM_DATA
Set this option at mcuxClEls_EccKeyGenOption_t.kgsign_rnd to not include user provided random data fo...
Definition mcuxClEls_Ecc.h:121
#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_PUBLICKEY_SIGN_DISABLE
Set this option at mcuxClEls_EccKeyGenOption_t.kgsign to not sign the public key.
Definition mcuxClEls_Ecc.h:109
#define MCUXCLELS_ECC_SIGNATURE_R_SIZE
Size of the signature part r.
Definition mcuxClEls_Ecc.h:153
#define MCUXCLELS_ECC_PUBLICKEY_SIZE
Size of the public key.
Definition mcuxClEls_Ecc.h:151
#define MCUXCLELS_ECC_SIGNATURE_SIZE
Size of the signature.
Definition mcuxClEls_Ecc.h:152
MCUXCLELS_API mcuxClEls_Status_t mcuxClEls_EccVerify_Async(mcuxClEls_EccVerifyOption_t options, uint8_t const *pInputHash, uint8_t const *pInputMessage, size_t inputMessageLength, uint8_t const *pSignatureAndPubKey, uint8_t *pOutput)
Verifies an ECDSA signature of a given message.
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_EccSign_Async(mcuxClEls_EccSignOption_t options, mcuxClEls_KeyIndex_t keyIdx, uint8_t const *pInputHash, uint8_t const *pInputMessage, size_t inputMessageLength, uint8_t *pOutput)
Generates an ECDSA signature of a given message.
#define MCUXCLELS_HASH_OUTPUT_SIZE_SHA_256
SHA-256 output size: 256 bit (32 bytes)
Definition mcuxClEls_Hash.h:126
#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_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_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
#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
Result type of mcuxClEls_GetHwState.
Definition mcuxClEls_Common.h:222
uint32_t ecdsavfy
ECDSA verify operation state (For possible values of this field, see MCUXCLELS_STATUS_ECDSAVFY_)
Definition mcuxClEls_Common.h:233
struct mcuxClEls_HwState_t::@9 bits
Access mcuxClEls_HwState_t bit-wise.
Command option bit field for mcuxClEls_EccSign_Async Bit field to configure mcuxClEls_EccSign_Async.
Definition mcuxClEls_Ecc.h:184
Command option bit field for mcuxClEls_EccVerify_Async Bit field to configure mcuxClEls_EccVerifyOpti...
Definition mcuxClEls_Ecc.h:204
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 kgsign
Define if signing the output public key.
Definition mcuxClEls_Ecc.h:236
uint32_t kgsrc
Define if the output key is deterministic or random.
Definition mcuxClEls_Ecc.h:238
uint32_t kgsign_rnd
Define if using user provided random data for the signature.
Definition mcuxClEls_Ecc.h:241
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