Defines all functions of mcuxClMath. More...
Macros | |
| #define | MCUXCLMATH_SHIFTMODULUS(iNShifted, iN) |
| Helper macro for mcuxClMath_ShiftModulus. | |
| #define | MCUXCLMATH_FP_SHIFTMODULUS(iNShifted, iN) |
| Helper macro for mcuxClMath_ShiftModulus with flow protection. | |
| #define | MCUXCLMATH_NDASH(iN, iT) |
| Helper macro for mcuxClMath_NDash. | |
| #define | MCUXCLMATH_FP_NDASH(iN, iT) |
| Helper macro for mcuxClMath_NDash with flow protection. | |
| #define | MCUXCLMATH_QDASH(iQDash, iNShifted, iN, iT, len) |
| Helper macro for mcuxClMath_QDash. | |
| #define | MCUXCLMATH_FP_QDASH(iQDash, iNShifted, iN, iT, len) |
| Helper macro for mcuxClMath_QDash with flow protection. | |
| #define | MCUXCLMATH_QSQUARED(iQSqr, iNShifted, iN, iT) |
| Helper macro for mcuxClMath_QSquared. | |
| #define | MCUXCLMATH_FP_QSQUARED(iQSqr, iNShifted, iN, iT) |
| Helper macro for mcuxClMath_QSquared with flow protection. | |
| #define | MCUXCLMATH_MODINV(iR, iX, iN, iT) |
| Helper macro for mcuxClMath_ModInv. | |
| #define | MCUXCLMATH_FP_MODINV(iR, iX, iN, iT) |
| Helper macro for mcuxClMath_ModInv with flow protection. | |
| #define | MCUXCLMATH_REDUCEMODEVEN(iR, iX, iN, iT0, iT1, iT2, iT3) |
| Helper macro for mcuxClMath_ReduceModEven. | |
| #define | MCUXCLMATH_FP_REDUCEMODEVEN(iR, iX, iN, iT0, iT1, iT2, iT3) |
| Helper macro for mcuxClMath_ReduceModEven with flow protection. | |
| #define | MCUXCLMATH_MODEXP_SQRMULTL2R(pExp, byteLenExp, iR, iX, iN, iT) |
| Helper macro for mcuxClMath_ModExp_SqrMultL2R. | |
| #define | MCUXCLMATH_FP_MODEXP_SQRMULTL2R(pExp, byteLenExp, iR, iX, iN, iT) |
| Helper macro for mcuxClMath_ModExp_SqrMultL2R with flow protection. | |
| #define | MCUXCLMATH_SECMODEXP(session, pExp, pExpTemp, byteLenExp, iR, iX, iN, iTE, iT0, iT1, iT2, iT3) |
| Helper macro for mcuxClMath_SecModExp. | |
| #define | MCUXCLMATH_EXACTDIVIDEODD(iR, iX, iN, iT, xPkcByteLen, yPkcByteLen) |
| Helper macro for mcuxClMath_ExactDivideOdd. | |
| #define | MCUXCLMATH_FP_EXACTDIVIDEODD(iR, iX, iN, iT, xPkcByteLen, yPkcByteLen) |
| Helper macro for mcuxClMath_ExactDivideOdd with flow protection. | |
| #define | MCUXCLMATH_EXACTDIVIDE(iR, iX, iN, iT, xPkcByteLen, yPkcByteLen) |
| Helper macro for mcuxClMath_ExactDivide. | |
| #define | MCUXCLMATH_FP_EXACTDIVIDE(iR, iX, iN, iT, xPkcByteLen, yPkcByteLen) |
| Helper macro for mcuxClMath_ExactDivide with flow protection. | |
Functions | |
| 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_LeadingZeros (uint8_t iX) |
| Counts number of leading zero bits of a PKC operand. | |
| uint32_t | mcuxClMath_TrailingZeros (uint8_t iX) |
| Counts number of trailing zero bits of a PKC operand. | |
| void | mcuxClMath_ShiftModulus (uint16_t iNShifted_iN) |
| Prepares shifted modulus. | |
| void | mcuxClMath_NDash (uint16_t iN_iT) |
| Prepares modulus (calculates NDash) for PKC modular multiplication. | |
| 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_QSquared (uint32_t iQSqr_iNShifted_iN_iT) |
| Calculates QSquared = Q^2 mod n, where Q = 256^(operandSize) mod n. | |
| void | mcuxClMath_ModInv (uint32_t iR_iX_iN_iT) |
| Calculates modular inversion, with odd 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. | |
| 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) |
| Securely calculates modular exponentiation. | |
| void | mcuxClMath_ExactDivideOdd (uint32_t iR_iX_iY_iT, uint32_t xPkcByteLength, uint32_t yPkcByteLength) |
| Calculates exact division with odd divisor. | |
| void | mcuxClMath_ExactDivide (uint32_t iR_iX_iY_iT, uint32_t xPkcByteLength, uint32_t yPkcByteLength) |
| Calculates exact division (supporting even divisor). | |
Defines all functions of mcuxClMath.
| #define MCUXCLMATH_SHIFTMODULUS | ( | iNShifted, | |
| iN | |||
| ) |
Helper macro for mcuxClMath_ShiftModulus.
| #define MCUXCLMATH_FP_SHIFTMODULUS | ( | iNShifted, | |
| iN | |||
| ) |
Helper macro for mcuxClMath_ShiftModulus with flow protection.
| #define MCUXCLMATH_NDASH | ( | iN, | |
| iT | |||
| ) |
Helper macro for mcuxClMath_NDash.
| #define MCUXCLMATH_FP_NDASH | ( | iN, | |
| iT | |||
| ) |
Helper macro for mcuxClMath_NDash with flow protection.
| #define MCUXCLMATH_QDASH | ( | iQDash, | |
| iNShifted, | |||
| iN, | |||
| iT, | |||
| len | |||
| ) |
Helper macro for mcuxClMath_QDash.
| #define MCUXCLMATH_FP_QDASH | ( | iQDash, | |
| iNShifted, | |||
| iN, | |||
| iT, | |||
| len | |||
| ) |
Helper macro for mcuxClMath_QDash with flow protection.
| #define MCUXCLMATH_QSQUARED | ( | iQSqr, | |
| iNShifted, | |||
| iN, | |||
| iT | |||
| ) |
Helper macro for mcuxClMath_QSquared.
| #define MCUXCLMATH_FP_QSQUARED | ( | iQSqr, | |
| iNShifted, | |||
| iN, | |||
| iT | |||
| ) |
Helper macro for mcuxClMath_QSquared with flow protection.
| #define MCUXCLMATH_MODINV | ( | iR, | |
| iX, | |||
| iN, | |||
| iT | |||
| ) |
Helper macro for mcuxClMath_ModInv.
| #define MCUXCLMATH_FP_MODINV | ( | iR, | |
| iX, | |||
| iN, | |||
| iT | |||
| ) |
Helper macro for mcuxClMath_ModInv with flow protection.
| #define MCUXCLMATH_REDUCEMODEVEN | ( | iR, | |
| iX, | |||
| iN, | |||
| iT0, | |||
| iT1, | |||
| iT2, | |||
| iT3 | |||
| ) |
Helper macro for mcuxClMath_ReduceModEven.
| #define MCUXCLMATH_FP_REDUCEMODEVEN | ( | iR, | |
| iX, | |||
| iN, | |||
| iT0, | |||
| iT1, | |||
| iT2, | |||
| iT3 | |||
| ) |
Helper macro for mcuxClMath_ReduceModEven with flow protection.
| #define MCUXCLMATH_MODEXP_SQRMULTL2R | ( | pExp, | |
| byteLenExp, | |||
| iR, | |||
| iX, | |||
| iN, | |||
| iT | |||
| ) |
Helper macro for mcuxClMath_ModExp_SqrMultL2R.
| #define MCUXCLMATH_FP_MODEXP_SQRMULTL2R | ( | pExp, | |
| byteLenExp, | |||
| iR, | |||
| iX, | |||
| iN, | |||
| iT | |||
| ) |
Helper macro for mcuxClMath_ModExp_SqrMultL2R with flow protection.
| #define MCUXCLMATH_SECMODEXP | ( | session, | |
| pExp, | |||
| pExpTemp, | |||
| byteLenExp, | |||
| iR, | |||
| iX, | |||
| iN, | |||
| iTE, | |||
| iT0, | |||
| iT1, | |||
| iT2, | |||
| iT3 | |||
| ) |
Helper macro for mcuxClMath_SecModExp.
| #define MCUXCLMATH_EXACTDIVIDEODD | ( | iR, | |
| iX, | |||
| iN, | |||
| iT, | |||
| xPkcByteLen, | |||
| yPkcByteLen | |||
| ) |
Helper macro for mcuxClMath_ExactDivideOdd.
| #define MCUXCLMATH_FP_EXACTDIVIDEODD | ( | iR, | |
| iX, | |||
| iN, | |||
| iT, | |||
| xPkcByteLen, | |||
| yPkcByteLen | |||
| ) |
Helper macro for mcuxClMath_ExactDivideOdd with flow protection.
| #define MCUXCLMATH_EXACTDIVIDE | ( | iR, | |
| iX, | |||
| iN, | |||
| iT, | |||
| xPkcByteLen, | |||
| yPkcByteLen | |||
| ) |
Helper macro for mcuxClMath_ExactDivide.
| #define MCUXCLMATH_FP_EXACTDIVIDE | ( | iR, | |
| iX, | |||
| iN, | |||
| iT, | |||
| xPkcByteLen, | |||
| yPkcByteLen | |||
| ) |
Helper macro for mcuxClMath_ExactDivide with flow protection.
| 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.
This function copies up to 8 offsets of PKC operands from current UPTRT to the new UPTRT, sets PKC to use the new UPTRT, and returns the address of original UPTRT.
| [in] | i3_i2_i1_i0 | the first 4 indices of offsets to be copied |
| [in] | i7_i6_i5_i4 | the second 4 indices of offsets to be copied |
| [in,out] | localPtrUptrt | address of the new UPTRT to be filled |
| [in] | noOfIndices | number of offsets to be copied from original UPTRT to new UPTRT |
| [out] | oldPtrUptrt | pointer to where receives the original UPTRT address |
i3_i2_i1_i0 i0 (bits 0~7): originalUptrt[i0] will be copied to localPtrUptrt[0], if noOfIndices >= 1. i1 (bits 8~15): originalUptrt[i1] will be copied to localPtrUptrt[1], if noOfIndices >= 2. i2 (bits 16~23): originalUptrt[i2] will be copied to localPtrUptrt[2], if noOfIndices >= 3. i3 (bits 24~31): originalUptrt[i3] will be copied to localPtrUptrt[3], if noOfIndices >= 4. i7_i6_i5_i4 i4 (bits 0~7): originalUptrt[i4] will be copied to localPtrUptrt[4], if noOfIndices >= 5. i5 (bits 8~15): originalUptrt[i5] will be copied to localPtrUptrt[5], if noOfIndices >= 6. i6 (bits 16~23): originalUptrt[i6] will be copied to localPtrUptrt[6], if noOfIndices >= 7. i7 (bits 24~31): originalUptrt[i7] will be copied to localPtrUptrt[7], if noOfIndices >= 8. localPtrUptrt noOfIndices 2-byte entries in this table. oldPtrUptrt. localPtrUptrt. | uint32_t mcuxClMath_LeadingZeros | ( | uint8_t | iX | ) |
Counts number of leading zero bits of a PKC operand.
This function counts the number of leading zero bits of a PKC operand at offset UPTRT[iX] and of size PS1 OPLEN.
| [in] | iX | index of PKC operand |
| [out] | pNumLeadingZeros | pointer to where the number of leading zero bits will be stored |
iX | uint32_t mcuxClMath_TrailingZeros | ( | uint8_t | iX | ) |
Counts number of trailing zero bits of a PKC operand.
This function counts the number of trailing zero bits of a PKC operand at offset UPTRT[iX] and of size PS1 OPLEN.
| [in] | iX | index of PKC operand |
iX | #numTrailingZeroes | Number of trailing zeroes |
| void mcuxClMath_ShiftModulus | ( | uint16_t | iNShifted_iN | ) |
Prepares shifted modulus.
This function left shifts modulus (PKC operand iN) until there is no leading zero and stores the result in PKC operand iNShifted.
| [in] | iNShifted_iN | indices of PKC operands |
iNShifted_iN iN (bits 0~7): index of modulus (PKC operand), size = operandSize. iNShifted (bits 8~15): index of shifted modulus (PKC operand), size = operandSize. | void mcuxClMath_NDash | ( | uint16_t | iN_iT | ) |
Prepares modulus (calculates NDash) for PKC modular multiplication.
This function calculates NDash = (-modulus)^(-1) mod 256^(MCUXCLPKC_WORDSIZE) and stores NDash in the PKC word in front of the PKC operand of modulus (iN).
| [in] | iN_iT | indices of PKC operands |
iN_iT iT (bits 0~7): index of temp (PKC operand). iN (bits 8~15): index of modulus (PKC operand). | 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.
This function computes QDash which can be used to convert a PKC operand (of the size length) to its Montgomery representation (of the size operandSize).
| [in] | iQDash_iNShifted_iN_iT | indices of PKC operands |
| [in] | length | specify Q' = 256^length mod n |
iQDash_iNShifted_iN_iT iT (bits 0~7): index of temp (PKC operand). iN (bits 8~15): index of modulus (PKC operand), size = operandSize. iNShifted (bits 16~23): index of shifted modulus (PKC operand), size = operandSize. iQDash (bits 24~31): index of result QDash (PKC operand), size = operandSize. length | void mcuxClMath_QSquared | ( | uint32_t | iQSqr_iNShifted_iN_iT | ) |
Calculates QSquared = Q^2 mod n, where Q = 256^(operandSize) mod n.
This function computes QSquared which can be used to convert a PKC operand to its Montgomery representation (both are of the size operandSize).
| [in] | iQSqr_iNShifted_iN_iT | indices of PKC operands |
iQSqr_iNShifted_iN_iT iT (bits 0~7): index of temp (PKC operand). iN (bits 8~15): index of modulus (PKC operand), size = operandSize. iNShifted (bits 16~23): index of shifted modulus (PKC operand), size = operandSize. iQSqr (bits 24~31): index of result QSquared (PKC operand), size = operandSize. | void mcuxClMath_ModInv | ( | uint32_t | iR_iX_iN_iT | ) |
Calculates modular inversion, with odd modulus.
This function calculates modular inversion, result = X^(-1) mod n.
| [in] | iR_iX_iN_iT | indices of PKC operands |
iR_iX_iN_iT iT (bits 0~7): index of temp (PKC operand). iN (bits 8~15): index of modulus (PKC operand), size = operandSize. iX (bits 16~23): index of X (PKC operand), size = operandSize. iR (bits 24~31): index of result (PKC operand). | void mcuxClMath_ReduceModEven | ( | uint32_t | iR_iX_iN_iT0, |
| uint32_t | iT1_iT2_iT3 | ||
| ) |
Calculates modular reduction with even modulus.
This function calculates modular reduction result = X mod n, where the modulus n is even.
| [in] | iR_iX_iN_iT0 | indices of PKC operands |
| [in] | iT1_iT2_iT3 | indices of PKC operands |
iR_iX_iN_iT0 iT0 (bits 0~7): index of temp0 (PKC operand). iN (bits 8~15): index of modulus (PKC operand), size = lenN. iX (bits 16~23): index of X (PKC operand). iR (bits 24~31): index of result (PKC operand). iT1_iT2_iT3 iT3 (bits 0~7): index of temp3 (PKC operand). iT2 (bits 8~15): index of temp2 (PKC operand). iT1 (bits 16~23): index of temp1 (PKC operand). | void mcuxClMath_ModExp_SqrMultL2R | ( | const uint8_t * | pExp, |
| uint32_t | expByteLength, | ||
| uint32_t | iR_iX_iN_iT | ||
| ) |
Calculates modular exponentiation.
This function calculates modular exponentiation with left-to-right binary square-and-multiply algorithm.
| [in] | pExp | pointer to exponent |
| [in] | expByteLength | byte length of exponent |
| [in] | iR_iX_iN_iT | indices of PKC operands |
pExp iR_iX_iN_iT iT (bits 0~7): index of temp operand (PKC operand). iN (bits 8~15): index of modulus (PKC operand), size = operandSize. iX (bits 16~23): index of base number (PKC operand), size = operandSize. iR (bits 24~31): index of result (PKC operand). | 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 | ||
| ) |
Securely calculates modular exponentiation.
This function calculates modular exponentiation in a secure manner. It randomizes the computation by Euclidean splitting: exponent = b * q + r, where b is a 64-bit odd random number (with both MSbit and LSbit set), and r = exponent % b. The exponentiation is calculated by two steps: (1) m0 = m^q mod n; and (2) result = m0^b * m^r mod n. In addition, base operands are re-randomized, by adding random multiples of the modulus to them before performing modular multiplications.
| [in] | pSession | handle for the current CL session. |
| [in] | pExp | pointer to exponent |
| [in] | pExpTemp | pointer to temporary buffer |
| [in] | expByteLength | byte length of exponent |
| [in] | iT3_iX_iT2_iT1 | indices of PKC operands |
| [in] | iN_iTE_iT0_iR | indices of PKC operands |
session: pExp pExpTemp expByteLength. iT3_iX_iT2_iT1 iT1 (bits 0~7): index of temp1 (PKC operand). expByteLength + 1), lenN + MCUXCLPKC_WORDSIZE, 2 * MCUXCLPKC_WORDSIZE). iT2 (bits 8~15): index of temp2 (PKC operand). iX (bits 16~23): index of base number (PKC operand), size = operandSize + MCUXCLPKC_WORDSIZE (= lenN + MCUXCLPKC_WORDSIZE). iT3 (bits 24~31): index of temp3 (PKC operand). iN_iTE_iT0_iR iR (bits 0~7): index of result (PKC operand). expByteLength + 1), lenN + MCUXCLPKC_WORDSIZE). iT0 (bits 8~15): index of temp0 (PKC operand). expByteLength + 1), lenN + MCUXCLPKC_WORDSIZE). iTE (bits 16~23): index of temp4 (PKC operand). iN (bits 24~31): index of modulus (PKC operand), size = operandSize (= lenN). | MCUXCLMATH_STATUS_OK | function executed successfully |
| MCUXCLMATH_STATUS_ERROR | error occurred during operation |
| void mcuxClMath_ExactDivideOdd | ( | uint32_t | iR_iX_iY_iT, |
| uint32_t | xPkcByteLength, | ||
| uint32_t | yPkcByteLength | ||
| ) |
Calculates exact division with odd divisor.
This function calculates exact division R = X/Y, where divisor Y is odd and dividend X shall be exactly a multiple of Y. If X is not a multiple of Y, result will be incorrect.
| [in] | iR_iX_iY_iT | indices of PKC operands |
| [in] | xPkcByteLength | length of X |
| [in] | yPkcByteLength | length of Y |
iR_iX_iY_iT iT (bits 0~7): index of temp (PKC operand). iY (bits 8~15): index of divisor Y (PKC operand), size = yPkcByteLength. iX (bits 16~23): index of dividend X (PKC operand), size = xPkcByteLength. iR (bits 24~31): index of result R (PKC operand), size = (xPkcByteLength - yPkcByteLength + MCUXCLPKC_WORDSIZE). xPkcByteLength yPkcByteLength. yPkcByteLength | void mcuxClMath_ExactDivide | ( | uint32_t | iR_iX_iY_iT, |
| uint32_t | xPkcByteLength, | ||
| uint32_t | yPkcByteLength | ||
| ) |
Calculates exact division (supporting even divisor).
This function calculates exact division R = X/Y, where dividend X shall be exactly a multiple of divisor Y. If X is not a multiple of Y, result will be incorrect.
This function trims trailing zero bits of Y and gets Y' = Y >> trailingZeros(Y), and X' = X >> ((trailingZeros(Y) / 8*MCUXCLPKC_WORDSIZE) * 8*MCUXCLPKC_WORDSIZE). It relies on mcuxClMath_ExactDivideOdd to calculate R' = X'/Y', and then calculates R = R' >> (trailingZeros(Y) % (8*MCUXCLPKC_WORDSIZE)).
| [in] | iR_iX_iY_iT | Pointer table indices of parameters |
| [in] | xPkcByteLength | length of X |
| [in] | yPkcByteLength | length of Y |
iR_iX_iY_iT iT (bits 0~7): index of temp (PKC operand). iY (bits 8~15): index of divisor Y (PKC operand), size = yPkcByteLength. iX (bits 16~23): index of dividend X (PKC operand), size = xPkcByteLength. iR (bits 24~31): index of result R (PKC operand). Its buffer size shall be at least (xPkcByteLength - yPkcByteLength + 2*MCUXCLPKC_WORDSIZE). The result fits in size = (xPkcByteLength - yPkcByteLength + MCUXCLPKC_WORDSIZE). xPkcByteLength yPkcByteLength