#include <mcuxClCore_Examples.h>
#include <mcuxClExample_Session_Helper.h>
#include <mcuxClExample_RNG_Helper.h>
#include <mcuxClToolchain.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)
#define RSA_PSS_SALT_LENGTH (0U)
#define INPUT_MESSAGE_LENGTH (64U)
static const uint8_t modulus[RSA_KEY_BYTE_LENGTH]
__attribute__ ((aligned (4))) = {
0xd3U, 0x24U, 0x96U, 0xe6U, 0x2dU, 0x16U, 0x34U, 0x6eU, 0x06U, 0xe7U, 0xa3U, 0x1cU, 0x12U, 0x0aU, 0x21U, 0xb5U,
0x45U, 0x32U, 0x32U, 0x35U, 0xeeU, 0x1dU, 0x90U, 0x72U, 0x1dU, 0xceU, 0xaaU, 0xd4U, 0x6dU, 0xc4U, 0xceU, 0xbdU,
0x80U, 0xc1U, 0x34U, 0x5aU, 0xffU, 0x95U, 0xb1U, 0xddU, 0xf8U, 0x71U, 0xebU, 0xb7U, 0xf2U, 0x0fU, 0xedU, 0xb6U,
0xe4U, 0x2eU, 0x67U, 0xa0U, 0xccU, 0x59U, 0xb3U, 0x9fU, 0xfdU, 0x31U, 0xe9U, 0x83U, 0x42U, 0xf4U, 0x0aU, 0xd9U,
0xafU, 0xf9U, 0x3cU, 0x3cU, 0x51U, 0xcfU, 0x5fU, 0x3cU, 0x8aU, 0xd0U, 0x64U, 0xb8U, 0x33U, 0xf9U, 0xacU, 0x34U,
0x22U, 0x9aU, 0x3eU, 0xd3U, 0xddU, 0x29U, 0x41U, 0xbeU, 0x12U, 0x5bU, 0xc5U, 0xa2U, 0x0cU, 0xb6U, 0xd2U, 0x31U,
0xb6U, 0xd1U, 0x84U, 0x7eU, 0xc4U, 0xfeU, 0xaeU, 0x2bU, 0x88U, 0x46U, 0xcfU, 0x00U, 0xc4U, 0xc6U, 0xe7U, 0x5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beU, 0xe3U,
0x56U, 0xf1U, 0x2cU, 0x6aU, 0x19U, 0x0eU, 0x55U, 0x7bU, 0xbfU, 0x25U, 0xe1U, 0x10U, 0x80U, 0x7bU, 0x85U, 0xcaU,
0xd5U, 0x1bU, 0x39U, 0x87U, 0x57U, 0x08U, 0x06U, 0xbeU, 0x81U, 0xf3U, 0x71U, 0x3fU, 0x5dU, 0x17U, 0x40U, 0x74U,
0x99U, 0xa5U, 0xdeU, 0xdaU, 0xc0U, 0xf3U, 0xe3U, 0xbcU, 0x79U, 0x96U, 0x35U, 0x95U, 0xf8U, 0xe0U, 0xcfU, 0x01U,
0x29U, 0x1dU, 0xc1U, 0x02U, 0x09U, 0xc0U, 0x6eU, 0xb6U, 0x0eU, 0x2eU, 0x9cU, 0x47U, 0xecU, 0x91U, 0x42U, 0xedU,
0xa5U, 0xf3U, 0xb7U, 0x0aU, 0xc6U, 0x7fU, 0x72U, 0xbfU, 0x52U, 0xb3U, 0x31U, 0x37U, 0xd1U, 0x49U, 0xb6U, 0xf6U,
0x06U, 0xe4U, 0x59U, 0x61U, 0x7dU, 0xaaU, 0x8eU, 0x10U, 0x18U, 0xa8U, 0x14U, 0x1dU, 0x89U, 0x4eU, 0xcaU, 0xffU
};
static const uint8_t pubExp[RSA_PUBLIC_EXP_BYTE_LENGTH]
__attribute__ ((aligned (4))) = {
0x01U, 0x00U, 0x01U
};
static const uint8_t data[INPUT_MESSAGE_LENGTH] = {
0x61U, 0x62U, 0x63U, 0x64U, 0x65U, 0x66U, 0x67U, 0x68U, 0x69U, 0x6AU, 0x6BU, 0x6CU, 0x6DU, 0x6EU, 0x6FU, 0x70U,
0x62U, 0x63U, 0x64U, 0x65U, 0x66U, 0x67U, 0x68U, 0x69U, 0x6AU, 0x6BU, 0x6CU, 0x6DU, 0x6EU, 0x6FU, 0x70U, 0x71U,
0x63U, 0x64U, 0x65U, 0x66U, 0x67U, 0x68U, 0x69U, 0x6AU, 0x6BU, 0x6CU, 0x6DU, 0x6EU, 0x6FU, 0x70U, 0x71U, 0x72U,
0x64U, 0x65U, 0x66U, 0x67U, 0x68U, 0x69U, 0x6AU, 0x6BU, 0x6CU, 0x6DU, 0x6EU, 0x6FU, 0x70U, 0x71U, 0x72U, 0x73U
};
MCUXCLEXAMPLE_FUNCTION(mcuxClRsa_Signature_RSASSA_PSS_example)
{
#define CPU_WA_BUFFER_SIZE MCUXCLCORE_MAX(MCUXCLCORE_MAX(MCUXCLCORE_MAX(MCUXCLCORE_MAX(\
MCUXCLRANDOM_NCINIT_WACPU_SIZE,\
MCUXCLRANDOMMODES_INIT_WACPU_SIZE),\
MCUXCLRSA_SIGN_PLAIN_PSSENCODE_WACPU_SIZE(RSA_KEY_BIT_LENGTH)),\
MCUXCLRSA_VERIFY_PSSVERIFY_WACPU_SIZE),\
MCUXCLHASH_COMPUTE_CPU_WA_BUFFER_SIZE_MAX)
#define PKC_WA_BUFFER_SIZE MCUXCLCORE_MAX(MCUXCLRSA_SIGN_PLAIN_WAPKC_SIZE(RSA_KEY_BIT_LENGTH),\
MCUXCLRSA_VERIFY_WAPKC_SIZE(RSA_KEY_BIT_LENGTH))
mcuxClSession_Descriptor_t sessionDesc;
MCUXCLEXAMPLE_ALLOCATE_AND_INITIALIZE_SESSION(session,
CPU_WA_BUFFER_SIZE,
PKC_WA_BUFFER_SIZE);
#if defined(MCUXCL_FEATURE_RANDOMMODES_SECSTRENGTH_256)
MCUXCLEXAMPLE_ALLOCATE_AND_INITIALIZE_RNG(session, MCUXCLRANDOMMODES_CTR_DRBG_AES256_CONTEXT_SIZE, mcuxClRandomModes_Mode_CtrDrbg_AES256_DRG3);
#elif defined(MCUXCL_FEATURE_RANDOMMODES_SECSTRENGTH_128)
MCUXCLEXAMPLE_ALLOCATE_AND_INITIALIZE_RNG(session, MCUXCLRANDOMMODES_CTR_DRBG_AES128_CONTEXT_SIZE, mcuxClRandomModes_Mode_CtrDrbg_AES128_DRG3);
#else
#error "Example not supported for target"
#endif
MCUX_CSSL_ANALYSIS_START_SUPPRESS_DISCARD_CONST_QUALIFIER()
.
modulus.pKeyEntryData = (uint8_t*)modulus,
.modulus.keyEntryLength = RSA_KEY_BYTE_LENGTH,
.exponent.pKeyEntryData = (uint8_t*)privExp,
.exponent.keyEntryLength = sizeof(privExp)
};
MCUX_CSSL_ANALYSIS_STOP_SUPPRESS_DISCARD_CONST_QUALIFIER()
MCUX_CSSL_ANALYSIS_START_SUPPRESS_DISCARD_CONST_QUALIFIER()
.
modulus.pKeyEntryData = (uint8_t*)modulus,
.modulus.keyEntryLength = RSA_KEY_BYTE_LENGTH,
.exponent.pKeyEntryData = (uint8_t*)pubExp,
.exponent.keyEntryLength = sizeof(pubExp)
};
MCUX_CSSL_ANALYSIS_STOP_SUPPRESS_DISCARD_CONST_QUALIFIER()
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,
(uint8_t *) &privKeyStruct,
sizeof(privKeyStruct)
));
{
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,
(uint8_t *) &pubKeyStruct,
sizeof(pubKeyStruct)
));
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
ALIGNED uint8_t signatureModeBytes[MCUXCLSIGNATURE_MODE_SIZE];
MCUX_CSSL_ANALYSIS_START_PATTERN_REINTERPRET_MEMORY_OF_OPAQUE_TYPES()
MCUX_CSSL_ANALYSIS_STOP_PATTERN_REINTERPRET_MEMORY_OF_OPAQUE_TYPES()
ALIGNED uint8_t rsaProtocolDescriptorBytes[MCUXCLRSA_SIGNATURE_PROTOCOLDESCRIPTOR_SIZE];
MCUX_CSSL_ANALYSIS_START_PATTERN_REINTERPRET_MEMORY_OF_OPAQUE_TYPES()
mcuxClRsa_SignatureProtocolDescriptor_t *pRsaProtocolDescriptor = (mcuxClRsa_SignatureProtocolDescriptor_t *) rsaProtocolDescriptorBytes;
MCUX_CSSL_ANALYSIS_STOP_PATTERN_REINTERPRET_MEMORY_OF_OPAQUE_TYPES()
MCUX_CSSL_ANALYSIS_START_PATTERN_REINTERPRET_MEMORY_OF_OPAQUE_TYPES()
pSignatureMode,
pRsaProtocolDescriptor,
RSA_PSS_SALT_LENGTH,
0u
)
);
MCUX_CSSL_ANALYSIS_STOP_PATTERN_REINTERPRET_MEMORY_OF_OPAQUE_TYPES()
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
uint32_t hashSize = 0;
session,
dataBuf,
sizeof(data),
hashBuf,
&hashSize
));
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
uint8_t signature[RSA_KEY_BYTE_LENGTH];
uint32_t signatureSize = 0;
session,
privKey,
pSignatureMode,
MCUX_CSSL_ANALYSIS_START_SUPPRESS_ALREADY_INITIALIZED("hashBuf initialized by mcuxClHash_compute")
MCUX_CSSL_ANALYSIS_STOP_SUPPRESS_ALREADY_INITIALIZED()
sizeof(hash),
signatureBuf,
&signatureSize
));
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
if(signatureSize != sizeof(signature))
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
session,
pubKey,
pSignatureMode,
sizeof(hash),
signatureSize
));
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
if(!mcuxClExample_Session_Clean(session))
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
return MCUXCLEXAMPLE_STATUS_OK;
}
Top-level include file for the mcuxClBuffer component.
Top-level include file for the mcuxClHash component.
Top-level include file for the mcuxClHashModes component.
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.
Top-level include file for the mcuxClSignature component.
#define MCUXCLBUFFER_INIT(name, info, ptr, size)
Initialize an input/output buffer (mcuxCl_Buffer_t).
Definition mcuxClBuffer.h:87
#define MCUXCLBUFFER_INIT_RO(name, info, ptr, size)
Initialize an input buffer (mcuxCl_InputBuffer_t) with plain CPU handling.
Definition mcuxClBuffer.h:104
const uint8_t * mcuxCl_InputBuffer_t
Input buffer type.
Definition mcuxClBuffer_Pointer.h:58
#define MCUXCLHASH_STATUS_OK
Hash operation successful.
Definition mcuxClHash_Constants.h:55
mcuxClHash_Status_t mcuxClHash_compute(mcuxClSession_Handle_t session, mcuxClHash_Algo_t algorithm, mcuxCl_InputBuffer_t pIn, uint32_t inSize, mcuxCl_Buffer_t pOut, uint32_t *const pOutSize)
One-shot Hash computation function.
static mcuxClHash_Algo_t mcuxClHash_Algorithm_Sha256
Sha-256 algorithm descriptor Sha-256 hash calculation using the Hash functionality SGI.
Definition mcuxClHashModes_Algorithms.h:116
#define MCUXCLHASH_OUTPUT_SIZE_SHA_256
SHA-256 output size: 256 bit (32 bytes).
Definition mcuxClHashModes_Constants.h:58
#define MCUXCLKEY_STATUS_OK
Key operation successful.
Definition mcuxClKey_Constants.h:60
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_Descriptor_t *const mcuxClKey_Handle_t
Key handle type.
Definition mcuxClKey_Types.h:111
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:97
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:141
void mcuxClRsa_SignatureModeConstructor_RSASSA_PSS(mcuxClSignature_ModeDescriptor_t *pSignatureMode, mcuxClRsa_SignatureProtocolDescriptor_t *pProtocolDescriptor, mcuxClHash_Algo_t hashAlgorithm, uint32_t saltLength, uint32_t options)
Mode constructor for RSASSA-PSS signature generation and verification.
mcuxClSession_Descriptor_t *const mcuxClSession_Handle_t
Type for mcuxClSession Handle.
Definition mcuxClSession_Types.h:118
mcuxClSignature_Status_t mcuxClSignature_verify(mcuxClSession_Handle_t session, mcuxClKey_Handle_t key, mcuxClSignature_Mode_t mode, mcuxCl_InputBuffer_t pIn, uint32_t inSize, mcuxCl_InputBuffer_t pSignature, uint32_t signatureSize)
One-shot verification function.
mcuxClSignature_Status_t mcuxClSignature_sign(mcuxClSession_Handle_t session, mcuxClKey_Handle_t key, mcuxClSignature_Mode_t mode, mcuxCl_InputBuffer_t pIn, uint32_t inSize, mcuxCl_Buffer_t pSignature, uint32_t *const pSignatureSize)
One-shot signing function.
struct mcuxClSignature_ModeDescriptor mcuxClSignature_ModeDescriptor_t
Signature mode/algorithm descriptor type.
Definition mcuxClSignature_Types.h:65
#define MCUX_CSSL_FP_FUNCTION_CALL_VOID_BEGIN(...)
Call a flow protected void function and check the protection token.
Definition mcuxCsslFlowProtection.h:714
#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:745
#define MCUX_CSSL_FP_FUNCTION_CALL_BEGIN(...)
Call a flow protected function and check the protection token.
Definition mcuxCsslFlowProtection.h:643
#define MCUX_CSSL_FP_FUNCTION_CALLED(...)
Expectation of a called function.
Definition mcuxCsslFlowProtection.h:797
#define MCUX_CSSL_FP_FUNCTION_CALL_END(...)
End a function call section started by MCUX_CSSL_FP_FUNCTION_CALL_BEGIN.
Definition mcuxCsslFlowProtection.h:678
Structure type for Rsa plain key data.
Definition mcuxClRsa_KeyTypes.h:287
mcuxClRsa_KeyEntry_t modulus
Key entry for the modulus.
Definition mcuxClRsa_KeyTypes.h:288
Structure type for Rsa key entries, specifying key entry length and data.
Definition mcuxClRsa_Types.h:124