20 #ifndef MCUXCLMATH_FUNCTIONS_H_ 21 #define MCUXCLMATH_FUNCTIONS_H_ 29 #include <mcuxClMath_Types.h> 49 uint16_t *localPtrUptrt,
51 const uint16_t **oldPtrUptrt
54 #define MCUXCLMATH_FP_INITLOCALUPTRT(i3_i2_i1_i0, i7_i6_i5_i4, localPtrUptrt, noOfIndices) \ 56 const uint16_t *oldPtrUptrt_; \ 57 MCUX_CSSL_FP_FUNCTION_CALL(retValTemp, mcuxClMath_InitLocalUptrt(i3_i2_i1_i0, i7_i6_i5_i4, localPtrUptrt, noOfIndices, &oldPtrUptrt_)); \ 70 uint32_t *nLeadingZeros
73 #define MCUXCLMATH_FP_LEADINGZEROS(iX) \ 75 uint32_t nLeadingZeros_; \ 76 MCUX_CSSL_FP_FUNCTION_CALL(retValTemp, mcuxClMath_LeadingZeros(iX, &nLeadingZeros_)); \ 89 uint32_t *nTrailingZeros
92 #define MCUXCLMATH_FP_TRAILINGZEROS(iX) \ 94 uint32_t nTrailingZeros_; \ 95 MCUX_CSSL_FP_FUNCTION_CALL(retValTemp, mcuxClMath_TrailingZeros(iX, &nTrailingZeros_)); \ 110 uint16_t iNShifted_iN
114 #define MCUXCLMATH_SHIFTMODULUS(iNShifted, iN) \ 115 mcuxClMath_ShiftModulus(MCUXCLPKC_PACKARGS2(iNShifted, iN)) 117 #define MCUXCLMATH_FP_SHIFTMODULUS(iNShifted, iN) \ 119 MCUX_CSSL_FP_FUNCTION_CALL(retValTemp, MCUXCLMATH_SHIFTMODULUS(iNShifted, iN)); \ 136 #define MCUXCLMATH_NDASH(iN, iT) \ 137 mcuxClMath_NDash(MCUXCLPKC_PACKARGS2(iN, iT)) 139 #define MCUXCLMATH_FP_NDASH(iN, iT) \ 141 MCUX_CSSL_FP_FUNCTION_CALL(retValTemp, MCUXCLMATH_NDASH(iN, iT)); \ 153 uint32_t iQDash_iNShifted_iN_iT,
160 #define MCUXCLMATH_QDASH(iQDash, iNShifted, iN, iT, len) \ 161 mcuxClMath_QDash(MCUXCLPKC_PACKARGS4(iQDash, iNShifted, iN, iT), len) 163 #define MCUXCLMATH_FP_QDASH(iQDash, iNShifted, iN, iT, len) \ 165 MCUX_CSSL_FP_FUNCTION_CALL(retValTemp, MCUXCLMATH_QDASH(iQDash, iNShifted, iN, iT, len)); \ 178 uint32_t iQSqr_iNShifted_iN_iT
184 #define MCUXCLMATH_QSQUARED(iQSqr, iNShifted, iN, iT) \ 185 mcuxClMath_QSquared(MCUXCLPKC_PACKARGS4(iQSqr, iNShifted, iN, iT)) 187 #define MCUXCLMATH_FP_QSQUARED(iQSqr, iNShifted, iN, iT) \ 189 MCUX_CSSL_FP_FUNCTION_CALL(retValTemp, MCUXCLMATH_QSQUARED(iQSqr, iNShifted, iN, iT)); \ 209 #define MCUXCLMATH_MODINV(iR, iX, iN, iT) \ 210 mcuxClMath_ModInv(MCUXCLPKC_PACKARGS4(iR, iX, iN, iT)) 212 #define MCUXCLMATH_FP_MODINV(iR, iX, iN, iT) \ 214 MCUX_CSSL_FP_FUNCTION_CALL(retValTemp, MCUXCLMATH_MODINV(iR, iX, iN, iT)); \ 226 uint32_t iR_iX_iN_iT0,
235 #define MCUXCLMATH_REDUCEMODEVEN(iR, iX, iN, iT0, iT1, iT2, iT3) \ 236 mcuxClMath_ReduceModEven(MCUXCLPKC_PACKARGS4(iR, iX, iN, iT0), MCUXCLPKC_PACKARGS4(0u, iT1, iT2, iT3)) 238 #define MCUXCLMATH_FP_REDUCEMODEVEN(iR, iX, iN, iT0, iT1, iT2, iT3) \ 240 MCUX_CSSL_FP_FUNCTION_CALL(retValTemp, MCUXCLMATH_REDUCEMODEVEN(iR, iX, iN, iT0, iT1, iT2, iT3)); \ 276 #define MCUXCLMATH_MODEXP_SQRMULTL2R(pExp, byteLenExp, iR, iX, iN, iT) \ 277 mcuxClMath_ModExp_SqrMultL2R(pExp, byteLenExp, MCUXCLPKC_PACKARGS4(iR, iX, iN, iT)) 279 #define MCUXCLMATH_FP_MODEXP_SQRMULTL2R(pExp, byteLenExp, iR, iX, iN, iT) \ 281 MCUX_CSSL_FP_FUNCTION_CALL(retValTemp, MCUXCLMATH_MODEXP_SQRMULTL2R(pExp, byteLenExp, iR, iX, iN, iT)); \ 326 uint32_t iT3_iX_iT2_iT1,
327 uint32_t iN_iTE_iT0_iR
330 #define MCUXCLMATH_SECMODEXP(pExp, pExpTemp, byteLenExp, iR, iX, iN, iTE, iT0, iT1, iT2, iT3) \ 331 mcuxClMath_SecModExp(pExp, pExpTemp, byteLenExp, MCUXCLPKC_PACKARGS4(iT3, iX, iT2, iT1), MCUXCLPKC_PACKARGS4(iN, iTE, iT0, iR)) 333 #define MCUXCLMATH_FP_SECMODEXP(pExp, pExpTemp, byteLenExp, iR, iX, iN, iTE, iT0, iT1, iT2, iT3) \ 335 MCUX_CSSL_FP_FUNCTION_CALL(retVal, MCUXCLMATH_SECMODEXP(pExp, pExpTemp, byteLenExp, iR, iX, iN, iTE, iT0, iT1, iT2, iT3)); \ 336 if (MCUXCLMATH_ERRORCODE_OK != retVal) \ 338 MCUX_CSSL_FP_FUNCTION_EXIT(mcuxClMath_SecModExp, MCUXCLMATH_ERRORCODE_ERROR); \ 354 #define MCUXCLMATH_EXACTDIVIDEODD(iR, iX, iN, iT, pkcByteLenX, pkcByteLenY) \ 355 mcuxClMath_ExactDivideOdd(MCUXCLPKC_PACKARGS4(iR, iX, iN, iT), pkcByteLenX, pkcByteLenY) 357 #define MCUXCLMATH_FP_EXACTDIVIDEODD(iR, iX, iN, iT, pkcByteLenX, pkcByteLenY) \ 359 MCUX_CSSL_FP_FUNCTION_CALL(retValTemp, MCUXCLMATH_EXACTDIVIDEODD(iR, iX, iN, iT, pkcByteLenX, pkcByteLenY)); \ 406 #define MCUXCLMATH_EXACTDIVIDE(iR, iX, iN, iT, pkcByteLenX, pkcByteLenY) \ 407 mcuxClMath_ExactDivide(MCUXCLPKC_PACKARGS4(iR, iX, iN, iT), pkcByteLenX, pkcByteLenY) 409 #define MCUXCLMATH_FP_EXACTDIVIDE(iR, iX, iN, iT, pkcByteLenX, pkcByteLenY) \ 411 MCUX_CSSL_FP_FUNCTION_CALL(retValTemp, MCUXCLMATH_EXACTDIVIDE(iR, iX, iN, iT, pkcByteLenX, pkcByteLenY)); \ mcuxClMath_Status_Protected_t mcuxClMath_SecModExp(const uint8_t *pExp, uint32_t *pExpTemp, uint32_t byteLenExp, uint32_t iT3_iX_iT2_iT1, uint32_t iN_iTE_iT0_iR)
Securely calculates modular exponentiation.
mcuxClMath_Status_Protected_t mcuxClMath_ShiftModulus(uint16_t iNShifted_iN)
Left shifts modulus until most significant bit of the buffer (length = ps1 OPLEN) is 1,...
mcuxClMath_Status_Protected_t mcuxClMath_NDash(uint16_t iN_iT)
Prepares modulus buffer (initializes NDash) to be used in modular multiplication (inversion,...
uint64_t mcuxClMath_Status_Protected_t
Type for error codes used by code-flow protected Math component functions.
Definition: mcuxClMath_Types.h:49
mcuxClMath_Status_Protected_t mcuxClMath_TrailingZeros(uint8_t iX, uint32_t *nTrailingZeros)
Counts number of trailing zeros of operand in the given buffer (length = ps1 OPLEN).
mcuxClMath_Status_Protected_t mcuxClMath_ModExp_SqrMultL2R(const uint8_t *pExp, uint32_t byteLenExp, uint32_t iR_iX_iN_iT)
Calculates modular exponentiation with left-to-right binary square and multiply algorithm.
mcuxClMath_Status_Protected_t mcuxClMath_ModInv(uint32_t iR_iX_iN_iT)
Calculates modular inversion, X^(-1) mod n.
Top level header of mcuxClPkc component (PKC hardware driver)
mcuxClMath_Status_Protected_t mcuxClMath_LeadingZeros(uint8_t iX, uint32_t *nLeadingZeros)
Counts number of leading zeros of operand in the given buffer (length = ps1 OPLEN).
mcuxClMath_Status_Protected_t mcuxClMath_ReduceModEven(uint32_t iR_iX_iN_iT0, uint32_t iT1_iT2_iT3)
Calculates modular reduction with even modulus, x mod n, where n is even.
Provides the API for the CSSL flow protection mechanism.
mcuxClMath_Status_Protected_t 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 the new UPTRT and returns the address of existing UPTRT.
mcuxClMath_Status_Protected_t mcuxClMath_ExactDivide(uint32_t iR_iX_iY_iT, uint32_t pkcByteLenX, uint32_t pkcByteLenY)
Exact division.
mcuxClMath_Status_Protected_t mcuxClMath_ExactDivideOdd(uint32_t iR_iX_iY_iT, uint32_t pkcByteLenX, uint32_t pkcByteLenY)
TODO 1.pkcByteLenX and pkcByteLenY shall be a multiple of pkc wordsize.
mcuxClMath_Status_Protected_t mcuxClMath_QSquared(uint32_t iQSqr_iNShifted_iN_iT)
Calculates Q^2 mod n, where Q = 256^(ps1 OPLEN) mod n.
#define MCUX_CSSL_FP_FUNCTION_DECL(id)
Declaration of a flow protected function.
Definition: mcuxCsslFlowProtection.h:119
mcuxClMath_Status_Protected_t mcuxClMath_QDash(uint32_t iQDash_iNShifted_iN_iT, uint16_t len)
Calculates Q * Q' mod n, where Q = 256^(ps1 OPLEN) mod n, and Q' = 256^len mod n.