Example for the mcuxCRsa component realize RSA key generation operation.
Example for the mcuxCRsa component realize RSA key generation operation.
#include <mcuxClToolchain.h>
#include <mcuxClCore_Examples.h>
#include <mcuxClExample_Session_Helper.h>
#include <mcuxClExample_RNG_Helper.h>
#define RSA_KEY_BIT_LENGTH (MCUXCLKEY_SIZE_2048)
#define RSA_KEY_BYTE_LENGTH (RSA_KEY_BIT_LENGTH / 8u)
#define RSA_PUBLIC_EXP_BYTE_LENGTH (3u)
static const uint8_t pubExp[RSA_PUBLIC_EXP_BYTE_LENGTH]
__attribute__ ((aligned (4))) = {
0x01u, 0x00u, 0x01u
};
MCUXCLEXAMPLE_FUNCTION(mcuxClRsa_KeyGeneration_example)
{
#define CPU_WA_BUFFER_SIZE MCUXCLCORE_MAX(MCUXCLCORE_MAX(\
MCUXCLRANDOM_NCINIT_WACPU_SIZE,\
MCUXCLRANDOMMODES_INIT_WACPU_SIZE),\
MCUXCLRSA_KEYGENERATION_PLAIN_WACPU_SIZE(RSA_KEY_BIT_LENGTH))
#define PKC_WA_BUFFER_SIZE (MCUXCLRSA_KEYGENERATION_PLAIN_WAPKC_SIZE(RSA_KEY_BIT_LENGTH))
mcuxClSession_Descriptor_t sessionDesc;
MCUXCLEXAMPLE_ALLOCATE_AND_INITIALIZE_SESSION(session,
CPU_WA_BUFFER_SIZE,
PKC_WA_BUFFER_SIZE);
uint32_t privKeyDesc[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,
privKey,
pPrivKeyData,
));
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
uint32_t pubKeyDesc[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,
pubKey,
pPubKeyData,
));
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
MCUXCLEXAMPLE_ALLOCATE_AND_INITIALIZE_RNG(session, MCUXCLRANDOMMODES_CTR_DRBG_AES256_CONTEXT_SIZE, mcuxClRandomModes_Mode_CtrDrbg_AES256_DRG3);
MCUX_CSSL_ANALYSIS_START_PATTERN_REINTERPRET_MEMORY_OF_OPAQUE_TYPES()
MCUX_CSSL_ANALYSIS_STOP_PATTERN_REINTERPRET_MEMORY_OF_OPAQUE_TYPES()
MCUX_CSSL_ANALYSIS_START_PATTERN_REINTERPRET_MEMORY_OF_OPAQUE_TYPES()
pKeyGeneration_RSA_Mode,
pubExp,
sizeof(pubExp)
)
);
MCUX_CSSL_ANALYSIS_STOP_PATTERN_REINTERPRET_MEMORY_OF_OPAQUE_TYPES()
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
session,
pKeyGeneration_RSA_Mode,
privKey,
pubKey
));
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
return MCUXCLEXAMPLE_STATUS_OK;
}
Top-level include file for the mcuxClKey component.
Top level header of mcuxClRandom component.
Top level header of mcuxClRandomModes component.
Top-level include file for the mcuxClRsa component.
Top-level include file for the mcuxClSession component.
#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_Status_t mcuxClKey_generate_keypair(mcuxClSession_Handle_t session, mcuxClKey_Generation_t generation, mcuxClKey_Handle_t privKey, mcuxClKey_Handle_t pubKey)
Key-pair generation function.
struct mcuxClKey_GenerationDescriptor mcuxClKey_GenerationDescriptor_t
Key generation descriptor type.
Definition mcuxClKey_Types.h:194
mcuxClKey_Descriptor_t *const mcuxClKey_Handle_t
Key handle type.
Definition mcuxClKey_Types.h:91
static const mcuxClKey_Type_t mcuxClKey_Type_Rsa_Public_2048
Key type pointer for RSA public key and key size 2048 bits.
Definition mcuxClRsa_KeyTypes.h:73
static const mcuxClKey_Type_t mcuxClKey_Type_Rsa_PrivatePlain_2048
Key type pointer for RSA private plain key and key size 2048 bits.
Definition mcuxClRsa_KeyTypes.h:106
void mcuxClRsa_KeyGeneration_ModeConstructor(mcuxClKey_GenerationDescriptor_t *pKeyGenMode, const uint8_t *pE, uint32_t eLength)
Mode constructor for RSA key generation algorithm.
mcuxClSession_Descriptor_t *const mcuxClSession_Handle_t
Type for mcuxClSession Handle.
Definition mcuxClSession_Types.h:98
#define MCUX_CSSL_FP_FUNCTION_CALL_VOID_BEGIN(...)
Call a flow protected void function and check the protection token.
Definition mcuxCsslFlowProtection.h:694
#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:725
#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
#define MCUXCLRSA_KEYGEN_MODE_SIZE
Definitions of RSA key generation mode descriptor size for the mcuxClRsa_KeyGeneration_ModeConstructo...
Definition mcuxClRsa_MemoryConsumption.h:30
#define MCUXCLRSA_KEYGENERATION_PLAIN_KEY_DATA_2048_SIZE
Definition of buffer size (in bytes) for the RSA private plain key data for 2048-bit keys.
Definition mcuxClRsa_MemoryConsumption.h:204
#define MCUXCLRSA_KEYGENERATION_PUBLIC_KEY_DATA_SIZE(keyByteLen, expByteLen)
Definition of buffer size (in bytes) for the RSA public key data for given key and public exponent si...
Definition mcuxClRsa_MemoryConsumption.h:218
Structure type for Rsa key entries, specifying key entry length and data.
Definition mcuxClRsa_Types.h:104