Example for the mcuxClEcc component deterministic ECDSA signature generation using the test vectors from from Section A.2.4 of rfc 6979 (test case "With SHA-256, message = "sample"")
Example for the mcuxClEcc component deterministic ECDSA signature generation using the test vectors from from Section A.2.4 of rfc 6979 (test case "With SHA-256, message = "sample"")
#include <mcuxClToolchain.h>
#include <mcuxClHashModes.h>
#include <mcuxClHmac.h>
#include <mcuxClCore_Examples.h>
#include <mcuxClExample_Session_Helper.h>
#include <mcuxClExample_ELS_Helper.h>
#include <mcuxClExample_RNG_Helper.h>
static const ALIGNED uint8_t pP[MCUXCLECC_WEIERECC_NIST_P224_SIZE_PRIMEP] =
{
0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu,
0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x00u, 0x01u
};
static const ALIGNED uint8_t pN[MCUXCLECC_WEIERECC_NIST_P224_SIZE_BASEPOINTORDER] =
{
0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0x16u, 0xA2u,
0xE0u, 0xB8u, 0xF0u, 0x3Eu, 0x13u, 0xDDu, 0x29u, 0x45u, 0x5Cu, 0x5Cu, 0x2Au, 0x3Du
};
static const ALIGNED uint8_t pA[MCUXCLECC_WEIERECC_NIST_P224_SIZE_PRIMEP] =
{
0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFEu,
0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFEu
};
static const ALIGNED uint8_t pB[MCUXCLECC_WEIERECC_NIST_P224_SIZE_PRIMEP] =
{
0xB4u, 0x05u, 0x0Au, 0x85u, 0x0Cu, 0x04u, 0xB3u, 0xABu, 0xF5u, 0x41u, 0x32u, 0x56u, 0x50u, 0x44u, 0xB0u, 0xB7u,
0xD7u, 0xBFu, 0xD8u, 0xBAu, 0x27u, 0x0Bu, 0x39u, 0x43u, 0x23u, 0x55u, 0xFFu, 0xB4u
};
static const ALIGNED uint8_t pG[2u * MCUXCLECC_WEIERECC_NIST_P224_SIZE_PRIMEP] =
{
0xB7u, 0x0Eu, 0x0Cu, 0xBDu, 0x6Bu, 0xB4u, 0xBFu, 0x7Fu, 0x32u, 0x13u, 0x90u, 0xB9u, 0x4Au, 0x03u, 0xC1u, 0xD3u,
0x56u, 0xC2u, 0x11u, 0x22u, 0x34u, 0x32u, 0x80u, 0xD6u, 0x11u, 0x5Cu, 0x1Du, 0x21u,
0xBDu, 0x37u, 0x63u, 0x88u, 0xB5u, 0xF7u, 0x23u, 0xFBu, 0x4Cu, 0x22u, 0xDFu, 0xE6u, 0xCDu, 0x43u, 0x75u, 0xA0u,
0x5Au, 0x07u, 0x47u, 0x64u, 0x44u, 0xD5u, 0x81u, 0x99u, 0x85u, 0x00u, 0x7Eu, 0x34u
};
static const ALIGNED uint8_t pPrivKey[MCUXCLECC_WEIERECC_NIST_P224_SIZE_PRIVATEKEY] =
{
0xF2u, 0x20u, 0x26u, 0x6Eu, 0x11u, 0x05u, 0xBFu, 0xE3u, 0x08u, 0x3Eu, 0x03u, 0xECu, 0x7Au, 0x3Au, 0x65u, 0x46u,
0x51u, 0xF4u, 0x5Eu, 0x37u, 0x16u, 0x7Eu, 0x88u, 0x60u, 0x0Bu, 0xF2u, 0x57u, 0xC1u
};
static const ALIGNED uint8_t pMessage[6u] =
{
0x73u, 0x61u, 0x6Du, 0x70u, 0x6Cu, 0x65u
};
static const ALIGNED uint8_t pRefSignature[MCUXCLECC_WEIERECC_NIST_P224_SIZE_SIGNATURE] =
{
0x61u, 0xAAu, 0x3Du, 0xA0u, 0x10u, 0xE8u, 0xE8u, 0x40u, 0x6Cu, 0x65u, 0x6Bu, 0xC4u, 0x77u, 0xA7u, 0xA7u, 0x18u,
0x98u, 0x95u, 0xE7u, 0xE8u, 0x40u, 0xCDu, 0xFEu, 0x8Fu, 0xF4u, 0x23u, 0x07u, 0xBAu,
0xBCu, 0x81u, 0x40u, 0x50u, 0xDAu, 0xB5u, 0xD2u, 0x37u, 0x70u, 0x87u, 0x94u, 0x94u, 0xF9u, 0xE0u, 0xA6u, 0x80u,
0xDCu, 0x1Au, 0xF7u, 0x16u, 0x19u, 0x91u, 0xBDu, 0xE6u, 0x92u, 0xB1u, 0x01u, 0x01u
};
MCUXCLEXAMPLE_FUNCTION(mcuxClEcc_ECDSA_Deterministic_NIST_P224_example)
{
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
MCUXCLEXAMPLE_ALLOCATE_AND_INITIALIZE_SESSION(sessionHandle, MCUXCLEXAMPLE_MAX_WA(MCUXCLECC_SIGN_DETERMINISTIC_ECDSA_WACPU_SIZE, MCUXCLRANDOMMODES_NCINIT_WACPU_SIZE), MCUXCLECC_SIGN_WAPKC_SIZE_256);
MCUXCLEXAMPLE_INITIALIZE_PRNG(sessionHandle);
uint32_t hmacModeDescBytes[MCUXCLHMAC_HMAC_MODE_DESCRIPTOR_SIZE_IN_WORDS];
MCUX_CSSL_ANALYSIS_START_PATTERN_REINTERPRET_MEMORY_OF_OPAQUE_TYPES()
MCUX_CSSL_ANALYSIS_STOP_PATTERN_REINTERPRET_MEMORY_OF_OPAQUE_TYPES()
MCUX_CSSL_ANALYSIS_START_SUPPRESS_POINTER_INCOMPATIBLE("The pointer hmacMode points to an object of the right type, the cast was valid.")
hmacMode,
MCUX_CSSL_ANALYSIS_STOP_SUPPRESS_POINTER_INCOMPATIBLE()
hashAlgorithm)
);
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
uint32_t signatureProtocolDescBytes[MCUXCLECC_ECDSA_SIGNATURE_PROTOCOL_DESCRIPTOR_SIZE_IN_WORDS];
MCUX_CSSL_ANALYSIS_START_PATTERN_REINTERPRET_MEMORY_OF_OPAQUE_TYPES()
MCUX_CSSL_ANALYSIS_STOP_PATTERN_REINTERPRET_MEMORY_OF_OPAQUE_TYPES()
sessionHandle,
MCUX_CSSL_ANALYSIS_START_SUPPRESS_POINTER_INCOMPATIBLE("The pointer pSignatureProtocolDesc points to an object of the right type, the cast was valid.")
pSignatureProtocolDesc,
MCUX_CSSL_ANALYSIS_STOP_SUPPRESS_POINTER_INCOMPATIBLE()
hmacMode));
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
uint32_t hashOutputSize = 0u;
sessionHandle,
hashAlgorithm,
buffMessage,
sizeof(pMessage),
buffHash,
&hashOutputSize
));
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
if(sizeof(pHash) != hashOutputSize)
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
ALIGNED uint8_t pSignature[MCUXCLECC_WEIERECC_NIST_P224_SIZE_SIGNATURE];
MCUXCLBUFFER_INIT(buffSignature, NULL, pSignature, MCUXCLECC_WEIERECC_NIST_P224_SIZE_SIGNATURE);
params.
pMode = pSignatureProtocolDesc;
sessionHandle,
¶ms));
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
if(!mcuxClCore_assertEqual(pSignature, pRefSignature, MCUXCLECC_WEIERECC_NIST_P224_SIZE_SIGNATURE))
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
if(!mcuxClExample_Session_Clean(sessionHandle))
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
if(!mcuxClExample_Els_Disable())
{
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
Provides the API for the CL buffer types.
Definition of function identifiers for the flow protection mechanism.
Top level header of mcuxClEcc component.
Top-level include file for the mcuxClHash component.
Top level header of mcuxClPkc component (PKC hardware driver)
Provides the API for the CSSL flow protection mechanism.
#define MCUXCLBUFFER_INIT(name, info, ptr, size)
Initialize an input/output buffer (mcuxCl_Buffer_t).
Definition mcuxClBuffer.h:71
#define MCUXCLBUFFER_INIT_RO(name, info, ptr, size)
Initialize an input buffer (mcuxCl_InputBuffer_t) with plain CPU handling.
Definition mcuxClBuffer.h:88
mcuxClEcc_Status_t mcuxClEcc_Sign(mcuxClSession_Handle_t pSession, const mcuxClEcc_Sign_Param_t *pParam)
implements ECDSA signature generation.
#define mcuxClEcc_Sign_Param_optLen_Pack(byteLenHash)
mcuxClEcc macros and defines to pack or access components of optLen parameter of mcuxClEcc_Sign_Param...
Definition mcuxClEcc_Types.h:158
#define mcuxClEcc_DomainParam_misc_Pack(byteLenN, byteLenP)
mcuxClEcc macros and defines to pack or access components of misc parameter of mcuxClEcc_DomainParam_...
Definition mcuxClEcc_Types.h:121
struct mcuxClEcc_ECDSA_SignatureProtocolDescriptor mcuxClEcc_ECDSA_SignatureProtocolDescriptor_t
ECDSA SignatureProtocol variant descriptor type.
Definition mcuxClEcc_Types.h:93
#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 MCUXCLHASH_STATUS_OK
Hash operation successful.
Definition mcuxClHash_Constants.h:35
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.
const mcuxClHash_AlgorithmDescriptor_t *const mcuxClHash_Algo_t
Hash mode/algorithm type.
Definition mcuxClHash_Types.h:50
static mcuxClHash_Algo_t mcuxClHash_Algorithm_Sha256
Sha-256 algorithm Sha-256 hash calculation using the Hash functionality of ELS, it supports RTF.
Definition mcuxClHashModes_Algorithms.h:121
#define MCUXCLHASH_OUTPUT_SIZE_SHA_256
SHA-256 output size: 256 bit (32 bytes)
Definition mcuxClHashModes_Constants.h:38
mcuxClMac_Status_t mcuxClHmac_createHmacMode(mcuxClMac_CustomMode_t mode, mcuxClHash_Algo_t hashAlgorithm)
This function creates a HMAC mode descriptor for software implementations of HMAC.
mcuxClMac_ModeDescriptor_t *const mcuxClMac_CustomMode_t
MAC custom mode/algorithm type.
Definition mcuxClMac_Types.h:75
mcuxClSession_Descriptor_t *const mcuxClSession_Handle_t
Type for mcuxClSession Handle.
Definition mcuxClSession_Types.h:113
#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
#define MCUXCLECC_STATUS_OK
Operation was successful.
Definition mcuxClEcc_Constants.h:46
mcuxCl_InputBuffer_t pG
[in] InputBuffer for octet string of base point G.
Definition mcuxClEcc_Types.h:110
uint32_t misc
[in] packed lengths, via mcuxClEcc_DomainParam_misc_Pack: bits 0~ 7: byteLenP: length of the octet st...
Definition mcuxClEcc_Types.h:114
mcuxCl_InputBuffer_t pB
[in] InputBuffer for octet string of curve parameter b (< p), of which the length is byteLenP.
Definition mcuxClEcc_Types.h:107
mcuxCl_InputBuffer_t pP
[in] InputBuffer for octet string of prime modulus p, of which the length is byteLenP.
Definition mcuxClEcc_Types.h:108
mcuxCl_InputBuffer_t pN
[in] InputBuffer for octet string of base point order n, of which the length is byteLenN.
Definition mcuxClEcc_Types.h:112
mcuxCl_InputBuffer_t pA
[in] InputBuffer for octet string of curve parameter a (< p), of which the length is byteLenP.
Definition mcuxClEcc_Types.h:106
Parameter structure for function mcuxClEcc_Sign.
Definition mcuxClEcc_Types.h:144
mcuxCl_InputBuffer_t pHash
[in] InputBuffer for string of message digest (hash), of which the length is byteLenHash (in optLen).
Definition mcuxClEcc_Types.h:146
const mcuxClEcc_ECDSA_SignatureProtocolDescriptor_t * pMode
[in] pointer to ECDSA protocol descriptor.
Definition mcuxClEcc_Types.h:154
const uint8_t * pPrivateKey
[in] pointer to octet string of private key, which is of the same format as base point order n.
Definition mcuxClEcc_Types.h:147
mcuxClEcc_DomainParam_t curveParam
[in] structure of InputBuffers for curve parameters and length of parameters.
Definition mcuxClEcc_Types.h:145
mcuxCl_Buffer_t pSignature
[out] Buffer for memory area in which signature R and S will be exported if signature is generated su...
Definition mcuxClEcc_Types.h:148
uint32_t optLen
[in] packed options (reserved) and lengths: bits 0~7: byteLenHash: length of the string of message di...
Definition mcuxClEcc_Types.h:151
Structure for mcuxClSession Descriptor.
Definition mcuxClSession_Types.h:121