Example for the mcuxClEcc component deterministic ECDSA signature generation using the test vectors from from Section A.2.6 of rfc 6979 (test case "With SHA-512, message = "sample"")
Example for the mcuxClEcc component deterministic ECDSA signature generation using the test vectors from from Section A.2.6 of rfc 6979 (test case "With SHA-512, 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_P521_SIZE_PRIMEP] =
{
0x01u, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu
};
static const ALIGNED uint8_t pN[MCUXCLECC_WEIERECC_NIST_P521_SIZE_BASEPOINTORDER] =
{
0x01u, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu,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x99u, 0x5Eu, 0xF4u, 0x26u, 0x40u, 0xC5u, 0x50u, 0xB9u, 0x01u, 0x3Fu, 0xADu, 0x07u, 0x61u, 0x35u, 0x3Cu, 0x70u, 0x86u, 0xA2u, 0x72u, 0xC2u, 0x40u, 0x88u, 0xBEu, 0x94u, 0x76u, 0x9Fu, 0xD1u, 0x66u, 0x50u
};
static const ALIGNED uint8_t pPrivKey[MCUXCLECC_WEIERECC_NIST_P521_SIZE_PRIVATEKEY] =
{
0x00u, 0xFAu, 0xD0u, 0x6Du, 0xAAu, 0x62u, 0xBAu, 0x3Bu, 0x25u, 0xD2u, 0xFBu, 0x40u, 0x13u, 0x3Du, 0xA7u, 0x57u, 0x20u, 0x5Du, 0xE6u, 0x7Fu, 0x5Bu, 0xB0u, 0x01u, 0x8Fu, 0xEEu, 0x8Cu, 0x86u, 0xE1u, 0xB6u, 0x8Cu, 0x7Eu, 0x75u, 0xCAu, 0xA8u, 0x96u, 0xEBu, 0x32u, 0xF1u, 0xF4u, 0x7Cu, 0x70u, 0x85u, 0x58u, 0x36u, 0xA6u, 0xD1u, 0x6Fu, 0xCCu, 0x14u, 0x66u, 0xF6u, 0xD8u, 0xFBu, 0xECu, 0x67u, 0xDBu, 0x89u, 0xECu, 0x0Cu, 0x08u, 0xB0u, 0xE9u, 0x96u, 0xB8u, 0x35u, 0x38u
};
static const ALIGNED uint8_t pMessage[6u] =
{
0x73u, 0x61u, 0x6Du, 0x70u, 0x6Cu, 0x65u
};
static const ALIGNED uint8_t pRefSignature[MCUXCLECC_WEIERECC_NIST_P521_SIZE_SIGNATURE] =
{
0x00u, 0xC3u, 0x28u, 0xFAu, 0xFCu, 0xBDu, 0x79u, 0xDDu, 0x77u, 0x85u, 0x03u, 0x70u, 0xC4u, 0x63u, 0x25u, 0xD9u, 0x87u, 0xCBu, 0x52u, 0x55u, 0x69u, 0xFBu, 0x63u, 0xC5u, 0xD3u, 0xBCu, 0x53u, 0x95u, 0x0Eu, 0x6Du, 0x4Cu, 0x5Fu, 0x17u, 0x4Eu, 0x25u, 0xA1u, 0xEEu, 0x90u, 0x17u, 0xB5u, 0xD4u, 0x50u, 0x60u, 0x6Au, 0xDDu, 0x15u, 0x2Bu, 0x53u, 0x49u, 0x31u, 0xD7u, 0xD4u, 0xE8u, 0x45u, 0x5Cu, 0xC9u, 0x1Fu, 0x9Bu, 0x15u, 0xBFu, 0x05u, 0xECu, 0x36u, 0xE3u, 0x77u, 0xFAu,
0x00u, 0x61u, 0x7Cu, 0xCEu, 0x7Cu, 0xF5u, 0x06u, 0x48u, 0x06u, 0xC4u, 0x67u, 0xF6u, 0x78u, 0xD3u, 0xB4u, 0x08u, 0x0Du, 0x6Fu, 0x1Cu, 0xC5u, 0x0Au, 0xF2u, 0x6Cu, 0xA2u, 0x09u, 0x41u, 0x73u, 0x08u, 0x28u, 0x1Bu, 0x68u, 0xAFu, 0x28u, 0x26u, 0x23u, 0xEAu, 0xA6u, 0x3Eu, 0x5Bu, 0x5Cu, 0x07u, 0x23u, 0xD8u, 0xB8u, 0xC3u, 0x7Fu, 0xF0u, 0x77u, 0x7Bu, 0x1Au, 0x20u, 0xF8u, 0xCCu, 0xB1u, 0xDCu, 0xCCu, 0x43u, 0x99u, 0x7Fu, 0x1Eu, 0xE0u, 0xE4u, 0x4Du, 0xA4u, 0xA6u, 0x7Au
};
MCUXCLEXAMPLE_FUNCTION(mcuxClEcc_ECDSA_Deterministic_NIST_P521_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_640);
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_P521_SIZE_SIGNATURE];
MCUXCLBUFFER_INIT(buffSignature, NULL, pSignature, MCUXCLECC_WEIERECC_NIST_P521_SIZE_SIGNATURE);
params.
pMode = pSignatureProtocolDesc;
sessionHandle,
¶ms));
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
if(!mcuxClCore_assertEqual(pSignature, pRefSignature, MCUXCLECC_WEIERECC_NIST_P521_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_Sha512
Sha-512 algorithm Sha-512 hash calculation using the Hash functionality of ELS, it supports RTF.
Definition mcuxClHashModes_Algorithms.h:183
#define MCUXCLHASH_OUTPUT_SIZE_SHA_512
SHA-512 output size: 512 bit (64 bytes)
Definition mcuxClHashModes_Constants.h:40
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