MCUX CLNS
MCUX Crypto Library Normal Secure
Loading...
Searching...
No Matches
mcuxClEcc_WeierECC_DecodePoint_secp224r1_example.c

Example for the mcuxClEcc component.

Example for the mcuxClEcc component

/*--------------------------------------------------------------------------*/
/* Copyright 2023-2025 NXP */
/* */
/* SPDX-License-Identifier: BSD-3-Clause */
/* */
/* Redistribution and use in source and binary forms, with or without */
/* modification, are permitted provided that the following conditions are */
/* met: */
/* */
/* 1. Redistributions of source code must retain the above copyright */
/* notice, this list of conditions and the following disclaimer. */
/* */
/* 2. Redistributions in binary form must reproduce the above copyright */
/* notice, this list of conditions and the following disclaimer in the */
/* documentation and/or other materials provided with the distribution. */
/* */
/* 3. Neither the name of the copyright holder nor the names of its */
/* contributors may be used to endorse or promote products derived from */
/* this software without specific prior written permission. */
/* */
/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS */
/* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED */
/* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A */
/* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT */
/* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED */
/* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR */
/* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */
/* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */
/* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
/* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
/*--------------------------------------------------------------------------*/
#include <mcuxClCore_Examples.h>
#include <mcuxClSession.h>
#include <mcuxClCore_FunctionIdentifiers.h> // Code flow protection
#include <mcuxClExample_Session_Helper.h>
#include <mcuxClEcc.h>
/* Compressed point on secp224r1 according to encoding specified in SEC 1: Elliptic Curve Cryptography */
static const uint8_t pCompressedPoint[MCUXCLECC_WEIERECC_SECP224R1_SIZE_ENCPOINT_SEC_COMPRESSED] =
{
/* Q = ((0x02 | LSBit(y)) || x) with
* LSBit of y = 0x01 */
0x03u,
/* x = 0x4340025ad933f30a651a05ea93a0732d7d9f6666d99e2d8716c45dcd */
0x43u, 0x40u, 0x02u, 0x5Au, 0xD9u, 0x33u, 0xF3u, 0x0Au,
0x65u, 0x1Au, 0x05u, 0xEAu, 0x93u, 0xA0u, 0x73u, 0x2Du,
0x7Du, 0x9Fu, 0x66u, 0x66u, 0xD9u, 0x9Eu, 0x2Du, 0x87u,
0x16u, 0xC4u, 0x5Du, 0xCDu
};
/* Reference for the decompressed point */
static const uint8_t pRefDecodedPoint[MCUXCLECC_WEIERECC_SECP224R1_SIZE_PRIMEP * 2u] =
{
/* Q = 0x102029a7c2e4ae8d8afe7b64b42065c3983d5d6cd968bdbb588608d1 * G = (x,y) with
* x = 0x4340025ad933f30a651a05ea93a0732d7d9f6666d99e2d8716c45dcd (big endian) */
0x43u, 0x40u, 0x02u, 0x5Au, 0xD9u, 0x33u, 0xF3u, 0x0Au,
0x65u, 0x1Au, 0x05u, 0xEAu, 0x93u, 0xA0u, 0x73u, 0x2Du,
0x7Du, 0x9Fu, 0x66u, 0x66u, 0xD9u, 0x9Eu, 0x2Du, 0x87u,
0x16u, 0xC4u, 0x5Du, 0xCDu,
/* y = 0x15563d61534f834fb38d152c2f09538de07ea201c01a94a636321aef (big endian) */
0x15u, 0x56u, 0x3Du, 0x61u, 0x53u, 0x4Fu, 0x83u, 0x4Fu,
0xB3u, 0x8Du, 0x15u, 0x2Cu, 0x2Fu, 0x09u, 0x53u, 0x8Du,
0xE0u, 0x7Eu, 0xA2u, 0x01u, 0xC0u, 0x1Au, 0x94u, 0xA6u,
0x36u, 0x32u, 0x1Au, 0xEFu
};
#define MAX_CPUWA_SIZE MCUXCLECC_WEIERECC_DECODEPOINT_WACPU_SIZE
#define MAX_PKCWA_SIZE MCUXCLECC_WEIERECC_DECODEPOINT_WAPKC_SIZE_256
MCUXCLEXAMPLE_FUNCTION(mcuxClEcc_WeierECC_DecodePoint_secp224r1_example)
{
/**************************************************************************/
/* Preparation */
/**************************************************************************/
/* Setup one session to be used by all functions called */
mcuxClSession_Descriptor_t sessionDesc;
mcuxClSession_Handle_t pSession = &sessionDesc;
MCUXCLEXAMPLE_ALLOCATE_AND_INITIALIZE_SESSION(pSession, MAX_CPUWA_SIZE, MAX_PKCWA_SIZE);
/**************************************************************************/
/* Decode the compressed point on secp224r1 */
/**************************************************************************/
uint8_t pDecodedPoint[MCUXCLECC_WEIERECC_SECP224R1_SIZE_PRIMEP * 2u] = {0u};
MCUXCLBUFFER_INIT(buffDecodedPoint, NULL, pDecodedPoint, (MCUXCLECC_WEIERECC_SECP224R1_SIZE_PRIMEP * 2u));
MCUXCLBUFFER_INIT_RO(buffCompressedPoint, NULL, pCompressedPoint, sizeof(pCompressedPoint));
MCUX_CSSL_FP_FUNCTION_CALL_BEGIN(decodePoint_status, decodePoint_token, mcuxClEcc_WeierECC_DecodePoint(
pSession,
buffCompressedPoint,
buffDecodedPoint,
MCUX_CSSL_ANALYSIS_START_SUPPRESS_DISCARD_CONST_QUALIFIER()
(mcuxClEcc_Weier_DomainParams_t *) &mcuxClEcc_Weier_DomainParams_secp224r1
MCUX_CSSL_ANALYSIS_STOP_SUPPRESS_DISCARD_CONST_QUALIFIER())
);
if((MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClEcc_WeierECC_DecodePoint) != decodePoint_token) || (MCUXCLECC_STATUS_OK != decodePoint_status))
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
/**************************************************************************/
/* Compare the decoded point to the reference result */
/**************************************************************************/
if(!mcuxClCore_assertEqual(pDecodedPoint, pRefDecodedPoint, MCUXCLECC_WEIERECC_SECP224R1_SIZE_PRIMEP * 2u))
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
/**************************************************************************/
/* Clean session */
/**************************************************************************/
if(!mcuxClExample_Session_Clean(pSession))
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
return MCUXCLEXAMPLE_STATUS_OK;
}
Definition of function identifiers for the flow protection mechanism.
Top level header of mcuxClEcc component.
Top-level include file for the mcuxClSession component.
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:87
#define MCUXCLBUFFER_INIT_RO(name, info, ptr, size)
Initialize an input buffer (mcuxCl_InputBuffer_t) with plain CPU handling.
Definition mcuxClBuffer.h:104
mcuxClEcc_Status_t mcuxClEcc_WeierECC_DecodePoint(mcuxClSession_Handle_t pSession, mcuxCl_InputBuffer_t pEncodedPoint, mcuxCl_Buffer_t pDecodedPoint, mcuxClEcc_WeierECC_PointEncType_t pointEncType, mcuxClEcc_Weier_DomainParams_t *pEccWeierDomainParams)
Point decoding function.
struct mcuxClEcc_Weier_DomainParams mcuxClEcc_Weier_DomainParams_t
Type for Weierstrass ECC domain parameters.
Definition mcuxClEcc_Types.h:123
static const mcuxClEcc_WeierECC_PointEncType_t mcuxClEcc_WeierECC_PointEncType_SEC
Point encoding type to be used for Weierstrass curve points as specified in SEC 1: Elliptic Curve Cry...
Definition mcuxClEcc_Types.h:667
mcuxClSession_Descriptor_t *const mcuxClSession_Handle_t
Type for mcuxClSession Handle.
Definition mcuxClSession_Types.h:118
#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
#define MCUXCLECC_STATUS_OK
Operation was successful.
Definition mcuxClEcc_Constants.h:66