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

Example for the mcuxClEcc component.

Example for the mcuxClEcc component

/*--------------------------------------------------------------------------*/
/* Copyright 2023 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 <mcuxClBuffer.h>
#include <mcuxClCore_FunctionIdentifiers.h> // Code flow protection
#include <mcuxClExample_Session_Helper.h>
#include <mcuxClEcc.h>
/* First input point for point subtraction */
static const uint8_t pPointP1[MCUXCLECC_WEIERECC_NIST_P224_SIZE_PRIMEP * 2u] =
{
/* P1 = 11*G = (x,y) with
* x = 0xEF53B6294ACA431F0F3C22DC82EB9050324F1D88D377E716448E507C (big endian) */
0xEFu, 0x53u, 0xB6u, 0x29u, 0x4Au, 0xCAu, 0x43u, 0x1Fu,
0x0Fu, 0x3Cu, 0x22u, 0xDCu, 0x82u, 0xEBu, 0x90u, 0x50u,
0x32u, 0x4Fu, 0x1Du, 0x88u, 0xD3u, 0x77u, 0xE7u, 0x16u,
0x44u, 0x8Eu, 0x50u, 0x7Cu,
/* y = 0x20B510004092E96636CFB7E32EFDED8265C266DFB754FA6D6491A6DA (big endian) */
0x20u, 0xB5u, 0x10u, 0x00u, 0x40u, 0x92u, 0xE9u, 0x66u,
0x36u, 0xCFu, 0xB7u, 0xE3u, 0x2Eu, 0xFDu, 0xEDu, 0x82u,
0x65u, 0xC2u, 0x66u, 0xDFu, 0xB7u, 0x54u, 0xFAu, 0x6Du,
0x64u, 0x91u, 0xA6u, 0xDAu
};
/* Second input point for point subtraciton */
static const uint8_t pPointP2[MCUXCLECC_WEIERECC_NIST_P224_SIZE_PRIMEP * 2u] =
{
/* P2 = 4*G = (x,y) with
* x = 0xAE99FEEBB5D26945B54892092A8AEE02912930FA41CD114E40447301 (big endian) */
0xAEu, 0x99u, 0xFEu, 0xEBu, 0xB5u, 0xD2u, 0x69u, 0x45u,
0xB5u, 0x48u, 0x92u, 0x09u, 0x2Au, 0x8Au, 0xEEu, 0x02u,
0x91u, 0x29u, 0x30u, 0xFAu, 0x41u, 0xCDu, 0x11u, 0x4Eu,
0x40u, 0x44u, 0x73u, 0x01u,
/* y = 0x0482580A0EC5BC47E88BC8C378632CD196CB3FA058A7114EB03054C9 (big endian) */
0x04u, 0x82u, 0x58u, 0x0Au, 0x0Eu, 0xC5u, 0xBCu, 0x47u,
0xE8u, 0x8Bu, 0xC8u, 0xC3u, 0x78u, 0x63u, 0x2Cu, 0xD1u,
0x96u, 0xCBu, 0x3Fu, 0xA0u, 0x58u, 0xA7u, 0x11u, 0x4Eu,
0xB0u, 0x30u, 0x54u, 0xC9u
};
/* Reference for the resulting point */
static const uint8_t pRefResult[MCUXCLECC_WEIERECC_NIST_P224_SIZE_PRIMEP * 2u] =
{
/* 7*G = (x,y) with
* x = 0xDB2F6BE630E246A5CF7D99B85194B123D487E2D466B94B24A03C3E28 (big endian) */
0xDBu, 0x2Fu, 0x6Bu, 0xE6u, 0x30u, 0xE2u, 0x46u, 0xA5u,
0xCFu, 0x7Du, 0x99u, 0xB8u, 0x51u, 0x94u, 0xB1u, 0x23u,
0xD4u, 0x87u, 0xE2u, 0xD4u, 0x66u, 0xB9u, 0x4Bu, 0x24u,
0xA0u, 0x3Cu, 0x3Eu, 0x28u,
/* y = 0x0F3A30085497F2F611EE2517B163EF8C53B715D18BB4E4808D02B963 (big endian) */
0x0Fu, 0x3Au, 0x30u, 0x08u, 0x54u, 0x97u, 0xF2u, 0xF6u,
0x11u, 0xEEu, 0x25u, 0x17u, 0xB1u, 0x63u, 0xEFu, 0x8Cu,
0x53u, 0xB7u, 0x15u, 0xD1u, 0x8Bu, 0xB4u, 0xE4u, 0x80u,
0x8Du, 0x02u, 0xB9u, 0x63u
};
#define MAX_CPUWA_SIZE MCUXCLECC_ARITHMETICOPERATION_POINTSUB_WACPU_SIZE
#define MAX_PKCWA_SIZE MCUXCLECC_ARITHMETICOPERATION_POINTSUB_WAPKC_SIZE_256 /* minimal workarea size usable for a 224 bit curve */
MCUXCLEXAMPLE_FUNCTION(mcuxClEcc_ArithmeticOperation_PointSub_NIST_P224_example)
{
/**************************************************************************/
/* Preparation */
/**************************************************************************/
mcuxClSession_Descriptor_t sessionDesc;
mcuxClSession_Handle_t pSession = &sessionDesc;
/* Allocate and initialize session */
MCUXCLEXAMPLE_ALLOCATE_AND_INITIALIZE_SESSION(pSession, MAX_CPUWA_SIZE, MAX_PKCWA_SIZE);
/**************************************************************************/
/* Subtract the two points P1 and P2 on NIST_P224 */
/**************************************************************************/
uint8_t pResult[MCUXCLECC_WEIERECC_NIST_P224_SIZE_PRIMEP * 2u] = {0};
uint32_t resultSize = 0u;
MCUXCLBUFFER_INIT_RO(buffPointP1, NULL, pPointP1, sizeof(pPointP1));
MCUXCLBUFFER_INIT_RO(buffPointP2, NULL, pPointP2, sizeof(pPointP2));
MCUXCLBUFFER_INIT(buffResult, NULL, pResult, sizeof(pResult));
MCUX_CSSL_FP_FUNCTION_CALL_BEGIN(pointSub_status, pointSub_token,
(mcuxClEcc_Weier_DomainParams_t *) &mcuxClEcc_Weier_DomainParams_NIST_P224,
buffPointP1,
sizeof(pPointP1),
buffPointP2,
sizeof(pPointP2),
buffResult,
&resultSize)
);
(MCUXCLECC_STATUS_OK != pointSub_status) || (sizeof(pResult) != resultSize))
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
/**************************************************************************/
/* Compare the resulting point to the reference result */
/**************************************************************************/
if(!mcuxClCore_assertEqual(pResult, pRefResult, MCUXCLECC_WEIERECC_NIST_P224_SIZE_PRIMEP * 2u))
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
/**************************************************************************/
/* Clean session */
/**************************************************************************/
if(!mcuxClExample_Session_Clean(pSession))
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
return MCUXCLEXAMPLE_STATUS_OK;
}
Top-level include file for the mcuxClBuffer component.
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:88
#define MCUXCLBUFFER_INIT_RO(name, info, ptr, size)
Initialize an input buffer (mcuxCl_InputBuffer_t) with plain CPU handling.
Definition mcuxClBuffer.h:105
mcuxClEcc_Status_t mcuxClEcc_ArithmeticOperation(mcuxClSession_Handle_t pSession, mcuxClEcc_ArithmeticOperation_t arithmeticOperation, mcuxClEcc_Weier_DomainParams_t *pEccWeierDomainParams, mcuxCl_InputBuffer_t pOp1, uint32_t op1Size, mcuxCl_InputBuffer_t pOp2, uint32_t op2Size, mcuxCl_Buffer_t pResult, uint32_t *const pResultSize)
Function to perform ECC arithmetic operations.
struct mcuxClEcc_Weier_DomainParams mcuxClEcc_Weier_DomainParams_t
Type for Weierstrass ECC domain parameters.
Definition mcuxClEcc_Types.h:116
static mcuxClEcc_ArithmeticOperation_t mcuxClEcc_ArithmeticOperation_PointSub
ECC Arithmetic operation type for full point subtraction on a short Weierstrass curve not secured aga...
Definition mcuxClEcc_Types.h:471
mcuxClSession_Descriptor_t *const mcuxClSession_Handle_t
Type for mcuxClSession Handle.
Definition mcuxClSession_Types.h:133
#define MCUX_CSSL_FP_FUNCTION_CALL_BEGIN(...)
Call a flow protected function and check the protection token.
Definition mcuxCsslFlowProtection.h:601
#define MCUX_CSSL_FP_FUNCTION_CALLED(...)
Expectation of a called function.
Definition mcuxCsslFlowProtection.h:755
#define MCUX_CSSL_FP_FUNCTION_CALL_END(...)
End a function call section started by MCUX_CSSL_FP_FUNCTION_CALL_BEGIN.
Definition mcuxCsslFlowProtection.h:636
#define MCUXCLECC_STATUS_OK
Operation was successful.
Definition mcuxClEcc_Constants.h:66