MCUX CLNS
MCUX Crypto Library Normal Secure
mcuxClMath_Functions.h
Go to the documentation of this file.
1 /*--------------------------------------------------------------------------*/
2 /* Copyright 2020-2023 NXP */
3 /* */
4 /* NXP Confidential. This software is owned or controlled by NXP and may */
5 /* only be used strictly in accordance with the applicable license terms. */
6 /* By expressly accepting such terms or by downloading, installing, */
7 /* activating and/or otherwise using the software, you are agreeing that */
8 /* you have read, and that you agree to comply with and are bound by, such */
9 /* license terms. If you do not agree to be bound by the applicable license */
10 /* terms, then you may not retain, install, activate or otherwise use the */
11 /* software. */
12 /*--------------------------------------------------------------------------*/
13 
20 #ifndef MCUXCLMATH_FUNCTIONS_H_
21 #define MCUXCLMATH_FUNCTIONS_H_
22 
23 
24 #include <mcuxClCore_Platform.h>
26 #include <mcuxCsslFlowProtection.h>
27 
28 #include <mcuxClPkc.h>
29 #include <mcuxClSession.h>
30 
31 #include <mcuxClMath_Types.h>
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
94  uint32_t i3_i2_i1_i0,
95  uint32_t i7_i6_i5_i4,
96  uint16_t *localPtrUptrt,
97  uint8_t noOfIndices,
98  const uint16_t **oldPtrUptrt
99  );
100 
101 
134  uint8_t iX,
135  uint32_t *pNumLeadingZeros
136  );
137 
138 
173  uint8_t iX
174  );
175 
176 
212  uint16_t iNShifted_iN
213  );
215 #define MCUXCLMATH_SHIFTMODULUS(iNShifted, iN) \
216  mcuxClMath_ShiftModulus(MCUXCLPKC_PACKARGS2(iNShifted, iN))
217 
218 #define MCUXCLMATH_FP_SHIFTMODULUS(iNShifted, iN) \
219  MCUX_CSSL_FP_FUNCTION_CALL_VOID(MCUXCLMATH_SHIFTMODULUS(iNShifted, iN))
220 
221 
259  uint16_t iN_iT
260  );
262 #define MCUXCLMATH_NDASH(iN, iT) \
263  mcuxClMath_NDash(MCUXCLPKC_PACKARGS2(iN, iT))
264 
265 #define MCUXCLMATH_FP_NDASH(iN, iT) \
266  MCUX_CSSL_FP_FUNCTION_CALL_VOID(MCUXCLMATH_NDASH(iN, iT))
267 
268 
311  uint32_t iQDash_iNShifted_iN_iT,
312  uint16_t length
313  );
315 #define MCUXCLMATH_QDASH(iQDash, iNShifted, iN, iT, len) \
316  mcuxClMath_QDash(MCUXCLPKC_PACKARGS4(iQDash, iNShifted, iN, iT), len)
317 
318 #define MCUXCLMATH_FP_QDASH(iQDash, iNShifted, iN, iT, len) \
319  MCUX_CSSL_FP_FUNCTION_CALL_VOID(MCUXCLMATH_QDASH(iQDash, iNShifted, iN, iT, len))
320 
321 
361  uint32_t iQSqr_iNShifted_iN_iT
362  );
364 #define MCUXCLMATH_QSQUARED(iQSqr, iNShifted, iN, iT) \
365  mcuxClMath_QSquared(MCUXCLPKC_PACKARGS4(iQSqr, iNShifted, iN, iT))
366 
367 #define MCUXCLMATH_FP_QSQUARED(iQSqr, iNShifted, iN, iT) \
368  MCUX_CSSL_FP_FUNCTION_CALL_VOID(MCUXCLMATH_QSQUARED(iQSqr, iNShifted, iN, iT))
369 
370 
413  uint32_t iR_iX_iN_iT
414  );
416 #define MCUXCLMATH_MODINV(iR, iX, iN, iT) \
417  mcuxClMath_ModInv(MCUXCLPKC_PACKARGS4(iR, iX, iN, iT))
418 
419 #define MCUXCLMATH_FP_MODINV(iR, iX, iN, iT) \
420  MCUX_CSSL_FP_FUNCTION_CALL_VOID(MCUXCLMATH_MODINV(iR, iX, iN, iT))
421 
422 
473  uint32_t iR_iX_iN_iT0,
474  uint32_t iT1_iT2_iT3
475  );
477 #define MCUXCLMATH_REDUCEMODEVEN(iR, iX, iN, iT0, iT1, iT2, iT3) \
478  mcuxClMath_ReduceModEven(MCUXCLPKC_PACKARGS4(iR, iX, iN, iT0), MCUXCLPKC_PACKARGS4(0u, iT1, iT2, iT3))
479 
480 #define MCUXCLMATH_FP_REDUCEMODEVEN(iR, iX, iN, iT0, iT1, iT2, iT3) \
481  MCUX_CSSL_FP_FUNCTION_CALL_VOID(MCUXCLMATH_REDUCEMODEVEN(iR, iX, iN, iT0, iT1, iT2, iT3))
482 
483 
525  const uint8_t *pExp,
526  uint32_t expByteLength,
527  uint32_t iR_iX_iN_iT
528  );
530 #define MCUXCLMATH_MODEXP_SQRMULTL2R(pExp, byteLenExp, iR, iX, iN, iT) \
531  mcuxClMath_ModExp_SqrMultL2R(pExp, byteLenExp, MCUXCLPKC_PACKARGS4(iR, iX, iN, iT))
532 
533 #define MCUXCLMATH_FP_MODEXP_SQRMULTL2R(pExp, byteLenExp, iR, iX, iN, iT) \
534  MCUX_CSSL_FP_FUNCTION_CALL_VOID(MCUXCLMATH_MODEXP_SQRMULTL2R(pExp, byteLenExp, iR, iX, iN, iT))
535 
536 
613  mcuxClSession_Handle_t session,
614  const uint8_t *pExp,
615  uint32_t *pExpTemp,
616  uint32_t expByteLength,
617  uint32_t iT3_iX_iT2_iT1,
618  uint32_t iN_iTE_iT0_iR,
619  uint32_t secOption
620  );
622 #define MCUXCLMATH_SECMODEXP(session, pExp, pExpTemp, byteLenExp, iR, iX, iN, iTE, iT0, iT1, iT2, iT3) \
623  mcuxClMath_SecModExp(session, pExp, pExpTemp, byteLenExp, MCUXCLPKC_PACKARGS4(iT3, iX, iT2, iT1), MCUXCLPKC_PACKARGS4(iN, iTE, iT0, iR), 0u)
624 
626 #define MCUXCLMATH_SECMODEXP_WITHOUT_RERANDOMIZATION(session, pExp, pExpTemp, byteLenExp, iR, iX, iN, iTE, iT0, iT1, iT2, iT3) \
627  mcuxClMath_SecModExp(session, pExp, pExpTemp, byteLenExp, MCUXCLPKC_PACKARGS4(iT3, iX, iT2, iT1), MCUXCLPKC_PACKARGS4(iN, iTE, iT0, iR), MCUXCLMATH_SECMODEXP_OPTION_DIS_RERAND)
628 
629 
681 MCUX_CSSL_FP_PROTECTED_TYPE(void) mcuxClMath_ExactDivideOdd(uint32_t iR_iX_iY_iT, uint32_t xPkcByteLength, uint32_t yPkcByteLength);
683 #define MCUXCLMATH_EXACTDIVIDEODD(iR, iX, iN, iT, xPkcByteLen, yPkcByteLen) \
684  mcuxClMath_ExactDivideOdd(MCUXCLPKC_PACKARGS4(iR, iX, iN, iT), xPkcByteLen, yPkcByteLen)
685 
686 #define MCUXCLMATH_FP_EXACTDIVIDEODD(iR, iX, iN, iT, xPkcByteLen, yPkcByteLen) \
687  MCUX_CSSL_FP_FUNCTION_CALL_VOID(MCUXCLMATH_EXACTDIVIDEODD(iR, iX, iN, iT, xPkcByteLen, yPkcByteLen))
688 
689 
750 MCUX_CSSL_FP_PROTECTED_TYPE(void) mcuxClMath_ExactDivide(uint32_t iR_iX_iY_iT, uint32_t xPkcByteLength, uint32_t yPkcByteLength);
752 #define MCUXCLMATH_EXACTDIVIDE(iR, iX, iN, iT, xPkcByteLen, yPkcByteLen) \
753  mcuxClMath_ExactDivide(MCUXCLPKC_PACKARGS4(iR, iX, iN, iT), xPkcByteLen, yPkcByteLen)
754 
756 #define MCUXCLMATH_FP_EXACTDIVIDE(iR, iX, iN, iT, xPkcByteLen, yPkcByteLen) \
757  MCUX_CSSL_FP_FUNCTION_CALL_VOID(MCUXCLMATH_EXACTDIVIDE(iR, iX, iN, iT, xPkcByteLen, yPkcByteLen))
758 
759  /* mcuxClMath_Functions */
763 
764 #ifdef __cplusplus
765 } /* extern "C" */
766 #endif
767 
768 #endif /* MCUXCLMATH_FUNCTIONS_H_ */
void mcuxClMath_ExactDivideOdd(uint32_t iR_iX_iY_iT, uint32_t xPkcByteLength, uint32_t yPkcByteLength)
Calculates exact division with odd divisor.
uint32_t mcuxClMath_TrailingZeros(uint8_t iX)
Counts number of trailing zero bits of a PKC operand.
void mcuxClMath_LeadingZeros(uint8_t iX, uint32_t *pNumLeadingZeros)
Counts number of leading zero bits of a PKC operand.
void mcuxClMath_ShiftModulus(uint16_t iNShifted_iN)
Prepares shifted modulus.
void mcuxClMath_ReduceModEven(uint32_t iR_iX_iN_iT0, uint32_t iT1_iT2_iT3)
Calculates modular reduction with even modulus.
void mcuxClMath_ModExp_SqrMultL2R(const uint8_t *pExp, uint32_t expByteLength, uint32_t iR_iX_iN_iT)
Calculates modular exponentiation.
Top-level include file for the mcuxClSession component.
mcuxClMath_Status_t mcuxClMath_SecModExp(mcuxClSession_Handle_t session, const uint8_t *pExp, uint32_t *pExpTemp, uint32_t expByteLength, uint32_t iT3_iX_iT2_iT1, uint32_t iN_iTE_iT0_iR, uint32_t secOption)
Securely calculates modular exponentiation.
void mcuxClMath_NDash(uint16_t iN_iT)
Prepares modulus (calculates NDash) for PKC modular multiplication.
Top level header of mcuxClPkc component (PKC hardware driver)
void mcuxClMath_ExactDivide(uint32_t iR_iX_iY_iT, uint32_t xPkcByteLength, uint32_t yPkcByteLength)
Calculates exact division (supporting even divisor).
void mcuxClMath_InitLocalUptrt(uint32_t i3_i2_i1_i0, uint32_t i7_i6_i5_i4, uint16_t *localPtrUptrt, uint8_t noOfIndices, const uint16_t **oldPtrUptrt)
Initializes and uses the new UPTRT and returns the address of original UPTRT.
uint32_t mcuxClMath_Status_t
Type for error codes used by Math component functions.
Definition: mcuxClMath_Types.h:46
Definition of function identifiers for the flow protection mechanism.
Provides the API for the CSSL flow protection mechanism.
mcuxClSession_Descriptor_t *const mcuxClSession_Handle_t
Type for mcuxClSession Handle.
Definition: mcuxClSession_Types.h:133
void mcuxClMath_QSquared(uint32_t iQSqr_iNShifted_iN_iT)
Calculates QSquared = Q^2 mod n, where Q = 256^(operandSize) mod n.
#define MCUX_CSSL_FP_FUNCTION_DECL(...)
Declaration of a flow protected function.
Definition: mcuxCsslFlowProtection.h:125
void mcuxClMath_QDash(uint32_t iQDash_iNShifted_iN_iT, uint16_t length)
Calculates QDash = Q * Q' mod n, where Q = 256^(operandSize) mod n, and Q' = 256^length mod n.
void mcuxClMath_ModInv(uint32_t iR_iX_iN_iT)
Calculates modular inversion, with odd modulus.
#define MCUX_CSSL_FP_PROTECTED_TYPE(resultType)
Based on a given base type, builds a return type with flow protection.
Definition: mcuxCsslFlowProtection.h:81