Defines all functions of mcuxClMath. More...
Macros | |
#define | MCUXCLMATH_SHIFTMODULUS(iNShifted, iN) |
Helper macro for #mcuxClMath_ShiftModulus. More... | |
#define | MCUXCLMATH_FP_SHIFTMODULUS(iNShifted, iN) |
Helper macro for #mcuxClMath_ShiftModulus with flow protection. More... | |
#define | MCUXCLMATH_NDASH(iN, iT) |
Helper macro for #mcuxClMath_NDash. More... | |
#define | MCUXCLMATH_FP_NDASH(iN, iT) |
Helper macro for #mcuxClMath_NDash with flow protection. More... | |
#define | MCUXCLMATH_QDASH(iQDash, iNShifted, iN, iT, len) |
Helper macro for #mcuxClMath_QDash. More... | |
#define | MCUXCLMATH_FP_QDASH(iQDash, iNShifted, iN, iT, len) |
Helper macro for #mcuxClMath_QDash with flow protection. More... | |
#define | MCUXCLMATH_QSQUARED(iQSqr, iNShifted, iN, iT) |
Helper macro for #mcuxClMath_QSquared. More... | |
#define | MCUXCLMATH_FP_QSQUARED(iQSqr, iNShifted, iN, iT) |
Helper macro for #mcuxClMath_QSquared with flow protection. More... | |
#define | MCUXCLMATH_MODINV(iR, iX, iN, iT) |
Helper macro for #mcuxClMath_ModInv. More... | |
#define | MCUXCLMATH_FP_MODINV(iR, iX, iN, iT) |
Helper macro for #mcuxClMath_ModInv with flow protection. More... | |
#define | MCUXCLMATH_REDUCEMODEVEN(iR, iX, iN, iT0, iT1, iT2, iT3) |
Helper macro for #mcuxClMath_ReduceModEven. More... | |
#define | MCUXCLMATH_FP_REDUCEMODEVEN(iR, iX, iN, iT0, iT1, iT2, iT3) |
Helper macro for #mcuxClMath_ReduceModEven with flow protection. More... | |
#define | MCUXCLMATH_MODEXP_SQRMULTL2R(pExp, byteLenExp, iR, iX, iN, iT) |
Helper macro for #mcuxClMath_ModExp_SqrMultL2R. More... | |
#define | MCUXCLMATH_FP_MODEXP_SQRMULTL2R(pExp, byteLenExp, iR, iX, iN, iT) |
Helper macro for #mcuxClMath_ModExp_SqrMultL2R with flow protection. More... | |
#define | MCUXCLMATH_SECMODEXP(session, pExp, pExpTemp, byteLenExp, iR, iX, iN, iTE, iT0, iT1, iT2, iT3) |
Helper macro for #mcuxClMath_SecModExp. More... | |
#define | MCUXCLMATH_SECMODEXP_WITHOUT_RERANDOMIZATION(session, pExp, pExpTemp, byteLenExp, iR, iX, iN, iTE, iT0, iT1, iT2, iT3) |
Helper macro for #mcuxClMath_SecModExp with disabled operand re-randomization. More... | |
#define | MCUXCLMATH_EXACTDIVIDEODD(iR, iX, iN, iT, xPkcByteLen, yPkcByteLen) |
Helper macro for #mcuxClMath_ExactDivideOdd. More... | |
#define | MCUXCLMATH_FP_EXACTDIVIDEODD(iR, iX, iN, iT, xPkcByteLen, yPkcByteLen) |
Helper macro for #mcuxClMath_ExactDivideOdd with flow protection. More... | |
#define | MCUXCLMATH_EXACTDIVIDE(iR, iX, iN, iT, xPkcByteLen, yPkcByteLen) |
Helper macro for #mcuxClMath_ExactDivide. More... | |
#define | MCUXCLMATH_FP_EXACTDIVIDE(iR, iX, iN, iT, xPkcByteLen, yPkcByteLen) |
Helper macro for #mcuxClMath_ExactDivide with flow protection. More... | |
Functions | |
MCUX_CSSL_FP_PROTECTED_TYPE (void) mcuxClMath_InitLocalUptrt(uint32_t i3_i2_i1_i0 | |
Initializes and uses the new UPTRT and returns the address of original UPTRT. More... | |
MCUX_CSSL_FP_PROTECTED_TYPE (uint32_t) mcuxClMath_TrailingZeros(uint8_t iX) | |
Counts number of trailing zero bits of a PKC operand. More... | |
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_SECMODEXP_WITHOUT_RERANDOMIZATION | ( | session, | |
pExp, | |||
pExpTemp, | |||
byteLenExp, | |||
iR, | |||
iX, | |||
iN, | |||
iTE, | |||
iT0, | |||
iT1, | |||
iT2, | |||
iT3 | |||
) |
Helper macro for #mcuxClMath_SecModExp with disabled operand re-randomization.
TODO CLNS-7824: analyze how to use the SecModExp in RsaKg MillerRabinTest, and remove secOption to always re-randomize
#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.
MCUX_CSSL_FP_PROTECTED_TYPE | ( | void | ) |
Initializes and uses the new UPTRT and returns the address of original UPTRT.
Wait until PKC is ready to accept new calculation.
Wait until PKC finishes calculations.
Start a PKC FUP program calculation.
Start a PKC calculation with one constant parameter.
Start a PKC calculation.
Initialize UPTR table.
deinitialize PKC hardware
Calculates exact division (supporting even divisor).
Calculates exact division with odd divisor.
Calculates modular exponentiation.
Calculates modular reduction with even modulus.
Calculates modular inversion, with odd modulus.
Calculates QSquared = Q^2 mod n, where Q = 256^(operandSize) mod n.
Calculates QDash = Q * Q' mod n, where Q = 256^(operandSize) mod n, and Q' = 256^length mod n.
Prepares modulus (calculates NDash) for PKC modular multiplication.
Prepares shifted modulus.
Counts number of leading zero bits of a PKC operand.
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
. 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
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. 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). 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
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. 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). 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). 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). 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
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
This function deinitializes PKC hardware, and optionally restores PKC configuration (except STOP bit).
[in] | pState | pointer to PKC state backup structure. If it's not a NULL pointer, PKC state will be restored from this structure. |
This function initializes elements in UPTR table. UPTR table contains the address (16-bit offset in PKC workarea) of each buffer (PKC operand). Each element of the table will be initialized with a 16-bit offset, associated with a buffer allocated in sequence in PKC workarea. When calling this function, there shall be no on-going and pending PKC calculations using the specified UPTR table elements.
[out] | pUPTRT | pointer to the first element to be initialized in UPTR table. |
[in] | pBaseBuffer | address of the buffer in PKC workarea, with which the first element will be associated. |
[in] | bufferLength | byte length of each buffer in PKC workarea. |
[in] | noOfBuffer | number of elements to be initialized. |
pUPTRT
pBaseBuffer
bufferLength
This function performs one specified PKC calculation, of which the operand(s) and result are specified by the indices of UPTR table.
[in] | param_mode | param (the higher 8 bits) indicates the type of the calculation (L0 or L1) and the parameter set (PS1 or PS2). mode (the lower 8 bits) indicates the calculation, either an L0 operation or L1 microcode. |
[in] | iR_iX_iY_iZ | indices of the operand(s) and the result in UPTR table. |
This function performs one specified PKC calculation, of which the operand(s) and result are specified by the indices of UPTR table, and a 8-bit constant parameter is directly provided. This function can also be used to perform an L0 operation without using Z operand, e.g., OP_MUL, R = X0 * Y.
[in] | param_mode | param (the higher 8 bits) indicates the type of the calculation (always L0) and the parameter set (PS1 or PS2). mode (the lower 8 bits) indicates the calculation, an L0 operation. |
[in] | iR_iX_iY_C | indices of the operand(s) and the result in UPTR table, and a direct 8-bit constant. |
This function triggers PKC to start the calculation of a FUP program.
[in] | pUPTR | 2-byte aligned address of the FUP program. |
[in] | uLength | length (number of calculation) of the FUP program. |
This function waits until PKC finishes on-going and pending calculations (if there is any). When returning to caller, PKC is in idle state, and result in PKC workarea is ready.
This function waits until PKC is ready to accept next calculation (i.e., no pending calculation).
MCUX_CSSL_FP_PROTECTED_TYPE | ( | uint32_t | ) |
Counts number of trailing zero bits of a PKC operand.
Deprecated type for mcuxClSession protected status codes.
Deprecated type for RSA protected status codes.
Deprecated type for error codes used by code-flow protected PKC component functions.
Deprecated type for error codes used by code-flow protected mcuxClMemory component functions.
Deprecated type for error codes used by code-flow protected Math component functions.
Deprecated type for Key component error codes, returned by functions with code-flow protection.
Deprecated type for ELS driver protected status codes.
Deprecated type for mcuxClEcc component return codes.
Securely calculates modular exponentiation.
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 |
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 |
[in] | secOption | option to disable the operand re-randomization |
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_ERRORCODE_OK | function executed successfully |
MCUXCLMATH_ERRORCODE_ERROR | error occurred during operation |