Example for generating and exporting rsa key.
#include "common.h"
#include <mcuxClToolchain.h>
#include <mcuxClToolchain.h>
#include <stdbool.h>
#include <mcuxClCore_Examples.h>
static const ALIGNED uint8_t PublicExp[] =
{
0x01, 0x00, 0x01
};
#define LIFETIME_INTERNAL PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(PSA_KEY_LIFETIME_VOLATILE, PSA_KEY_LOCATION_EXTERNAL_STORAGE)
#define LIFETIME_EXTERNAL PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(PSA_KEY_LIFETIME_VOLATILE, PSA_KEY_LOCATION_LOCAL_STORAGE)
MCUXCLEXAMPLE_FUNCTION(mcuxClPsaDriver_keygen_export_public_key_rsa_example)
{
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
psa_key_attributes_t attributes = {
.core = {
.type = PSA_KEY_TYPE_RSA_KEY_PAIR,
.lifetime = LIFETIME_EXTERNAL,
.id = 0U,
.policy = {
.usage = PSA_ALG_NONE,
.alg = PSA_ALG_NONE,
.alg2 = PSA_ALG_NONE},
.flags = 0U},
MCUX_CSSL_ANALYSIS_START_SUPPRESS_DISCARD_CONST("Required by API function")
.domain_parameters = (uint8_t*)PublicExp,
MCUX_CSSL_ANALYSIS_STOP_SUPPRESS_DISCARD_CONST()
.domain_parameters_size = sizeof(PublicExp)};
MCUX_CSSL_ANALYSIS_START_PATTERN_EXTERNAL_MACRO()
ALIGNED uint8_t key_buffer[PSA_KEY_EXPORT_RSA_KEY_PAIR_MAX_SIZE(2048u)] = {0U};
size_t key_buffer_size = PSA_KEY_EXPORT_RSA_KEY_PAIR_MAX_SIZE(2048u);
MCUX_CSSL_ANALYSIS_STOP_PATTERN_EXTERNAL_MACRO()
size_t key_buffer_length = 0U;
psa_status_t status = psa_driver_wrapper_generate_key(
&attributes,
(uint8_t *)&key_buffer, key_buffer_size, &key_buffer_length );
if(status != PSA_SUCCESS)
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
MCUX_CSSL_ANALYSIS_START_PATTERN_EXTERNAL_MACRO()
if(key_buffer_length > PSA_KEY_EXPORT_RSA_KEY_PAIR_MAX_SIZE(2048u))
MCUX_CSSL_ANALYSIS_STOP_PATTERN_EXTERNAL_MACRO()
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
MCUX_CSSL_ANALYSIS_START_PATTERN_EXTERNAL_MACRO()
size_t data_size = PSA_EXPORT_KEY_OUTPUT_SIZE(PSA_KEY_TYPE_RSA_PUBLIC_KEY,
MCUXCLKEY_SIZE_2048);
MCUX_CSSL_ANALYSIS_STOP_PATTERN_EXTERNAL_MACRO()
size_t data_length = 0U;
attributes.core.policy.usage = PSA_KEY_USAGE_EXPORT;
status = psa_driver_wrapper_export_public_key(
&attributes,
key_buffer, key_buffer_size,
data, data_size, &data_length);
if(status != PSA_SUCCESS)
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
if(data_length > data_size)
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
{
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
Top-level include file for the ELS driver.
Top-level include file for the mcuxClKey component.
Top level header of mcuxClPkc component (PKC hardware driver)
Additional macros for the ARM PSA driver.
Top-level include file for the mcuxClRsa component.
Top-level include file for the mcuxClSession component.
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
MCUXCLELS_API mcuxClEls_Status_t mcuxClEls_Enable_Async(void)
Enables the ELS.
MCUXCLELS_API mcuxClEls_Status_t mcuxClEls_Disable(void)
Disable the ELS.
MCUXCLELS_API mcuxClEls_Status_t mcuxClEls_WaitForOperation(mcuxClEls_ErrorHandling_t errorHandling)
Wait for an ELS operation and optionally clear the error status.
#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
#define MCUXCLKEY_SIZE_2048
2048 bit key, size in bits
Definition mcuxClKey_Constants.h:112
#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