Defines all functions of mcuxClMath. More...
Macros | |
#define | MCUXCLMATH_FP_INITLOCALUPTRT(i3_i2_i1_i0, i7_i6_i5_i4, localPtrUptrt, noOfIndices) |
Helper macro to call mcuxClMath_InitLocalUptrt with flow protection. More... | |
#define | MCUXCLMATH_FP_LEADINGZEROS(iX) |
Helper macro to call mcuxClMath_LeadingZeros with flow protection. More... | |
#define | MCUXCLMATH_FP_TRAILINGZEROS(iX) |
Helper macro to call mcuxClMath_TrailingZeros with flow protection. More... | |
#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(pExp, pExpTemp, byteLenExp, iR, iX, iN, iTE, iT0, iT1, iT2, iT3) |
Helper macro for mcuxClMath_SecModExp. More... | |
#define | MCUXCLMATH_FP_SECMODEXP(pExp, pExpTemp, byteLenExp, iR, iX, iN, iTE, iT0, iT1, iT2, iT3) |
Helper macro for mcuxClMath_SecModExp with flow protection. More... | |
#define | MCUXCLMATH_EXACTDIVIDEODD(iR, iX, iN, iT, pkcByteLenX, pkcByteLenY) |
Helper macro for mcuxClMath_ExactDivideOdd. More... | |
#define | MCUXCLMATH_FP_EXACTDIVIDEODD(iR, iX, iN, iT, pkcByteLenX, pkcByteLenY) |
Helper macro for mcuxClMath_ExactDivideOdd with flow protection. More... | |
#define | MCUXCLMATH_EXACTDIVIDE(iR, iX, iN, iT, pkcByteLenX, pkcByteLenY) |
Helper macro for mcuxClMath_ExactDivide. More... | |
#define | MCUXCLMATH_FP_EXACTDIVIDE(iR, iX, iN, iT, pkcByteLenX, pkcByteLenY) |
Helper macro for mcuxClMath_ExactDivide with flow protection. More... | |
Functions | |
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. More... | |
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). More... | |
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). More... | |
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, and stores the result in the buffer specified. More... | |
mcuxClMath_Status_Protected_t | mcuxClMath_NDash (uint16_t iN_iT) |
Prepares modulus buffer (initializes NDash) to be used in modular multiplication (inversion, ...) with odd modulus. More... | |
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. More... | |
mcuxClMath_Status_Protected_t | mcuxClMath_QSquared (uint32_t iQSqr_iNShifted_iN_iT) |
Calculates Q^2 mod n, where Q = 256^(ps1 OPLEN) mod n. More... | |
mcuxClMath_Status_Protected_t | mcuxClMath_ModInv (uint32_t iR_iX_iN_iT) |
Calculates modular inversion, X^(-1) mod n. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
mcuxClMath_Status_Protected_t | mcuxClMath_ExactDivide (uint32_t iR_iX_iY_iT, uint32_t pkcByteLenX, uint32_t pkcByteLenY) |
Exact division. More... | |
Defines all functions of mcuxClMath.
#define MCUXCLMATH_FP_INITLOCALUPTRT | ( | i3_i2_i1_i0, | |
i7_i6_i5_i4, | |||
localPtrUptrt, | |||
noOfIndices | |||
) |
Helper macro to call mcuxClMath_InitLocalUptrt with flow protection.
#define MCUXCLMATH_FP_LEADINGZEROS | ( | iX | ) |
Helper macro to call mcuxClMath_LeadingZeros with flow protection.
#define MCUXCLMATH_FP_TRAILINGZEROS | ( | iX | ) |
Helper macro to call mcuxClMath_TrailingZeros with flow protection.
#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 | ( | pExp, | |
pExpTemp, | |||
byteLenExp, | |||
iR, | |||
iX, | |||
iN, | |||
iTE, | |||
iT0, | |||
iT1, | |||
iT2, | |||
iT3 | |||
) |
Helper macro for mcuxClMath_SecModExp.
#define MCUXCLMATH_FP_SECMODEXP | ( | pExp, | |
pExpTemp, | |||
byteLenExp, | |||
iR, | |||
iX, | |||
iN, | |||
iTE, | |||
iT0, | |||
iT1, | |||
iT2, | |||
iT3 | |||
) |
Helper macro for mcuxClMath_SecModExp with flow protection.
#define MCUXCLMATH_EXACTDIVIDEODD | ( | iR, | |
iX, | |||
iN, | |||
iT, | |||
pkcByteLenX, | |||
pkcByteLenY | |||
) |
Helper macro for mcuxClMath_ExactDivideOdd.
#define MCUXCLMATH_FP_EXACTDIVIDEODD | ( | iR, | |
iX, | |||
iN, | |||
iT, | |||
pkcByteLenX, | |||
pkcByteLenY | |||
) |
Helper macro for mcuxClMath_ExactDivideOdd with flow protection.
#define MCUXCLMATH_EXACTDIVIDE | ( | iR, | |
iX, | |||
iN, | |||
iT, | |||
pkcByteLenX, | |||
pkcByteLenY | |||
) |
Helper macro for mcuxClMath_ExactDivide.
#define MCUXCLMATH_FP_EXACTDIVIDE | ( | iR, | |
iX, | |||
iN, | |||
iT, | |||
pkcByteLenX, | |||
pkcByteLenY | |||
) |
Helper macro for mcuxClMath_ExactDivide with flow protection.
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.
This function copies up to 8 offsets of PKC operands from existing UPTRT to the new UPTRT, sets PKC to be with 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. |
[out] | localPtrUptrt | pointer to the new UPTRT to be filled. |
[in] | noOfIndices | number of offsets to be copied from existing UPTRT to new UPTRT. |
[out] | oldPtrUptrt | pointer which receives the pointer to the old UPTRT. |
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).
[in] | iX | index of operand buffer. |
[out] | nLeadingZeros | the number of leading zero bits. |
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).
[in] | iX | index of operand buffer. |
[out] | nTrailingZeros | the number of trailing zero bits. |
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, and stores the result in the buffer specified.
[in] | iNShifted_iN | iNShifted: index of buffer in which the result will be stored. iN: index of modulus buffer. |
mcuxClMath_Status_Protected_t mcuxClMath_NDash | ( | uint16_t | iN_iT | ) |
Prepares modulus buffer (initializes NDash) to be used in modular multiplication (inversion, ...) with odd modulus.
This function calculates NDash = (-n)^(-1) mod 256^("PKC wordsize"), and stores the result in the PKC word in front of the modulus (n) buffer.
[in] | iN_iT | iN: index of modulus buffer. The result (NDash) will be stored in the PKC word in front of the modulus buffer. iT: index of temp buffer, of which the size should be at least 2 PKC words. |
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.
[in] | iQDash_iNShifted_iN_iT | iQDash: index of QDash buffer, in which the result will be stored. iNShifted: index of shifted modulus. If the bit length of modulus is equal to the operand size (i.e., most significant bit is 1), it can be the same as iN. iN: index of modulus buffer. NDash of the modulus should be store in front of it. iT: index of temp buffer, of which the size should be at least operandSize + PKC wordsize. |
[in] | len | specify Q' = 256^len mod n. |
mcuxClMath_Status_Protected_t mcuxClMath_QSquared | ( | uint32_t | iQSqr_iNShifted_iN_iT | ) |
Calculates Q^2 mod n, where Q = 256^(ps1 OPLEN) mod n.
[in] | iQSqr_iNShifted_iN_iT | iQSqr: index of QSqr buffer, in which the result will be stored. iNShifted: index of shifted modulus. If the bit length of modulus is equal to the operand size (i.e., most significant bit is 1), it can be the same as iN. iN: index of modulus buffer. NDash of the modulus should be store in front of it. iT: index of temp buffer, of which the size should be at least operandSize + PKC wordsize. |
mcuxClMath_Status_Protected_t mcuxClMath_ModInv | ( | uint32_t | iR_iX_iN_iT | ) |
Calculates modular inversion, X^(-1) mod n.
[in] | iR_iX_iN_iT | iR: index of result buffer, of which the size should be at least operandSize + PKC wordsize. iX: index of X buffer, of which the content (X) will be destroyed. iN: index of modulus buffer. NDash of the modulus should be store in front of it. iT: index of temp buffer, of which the size should be at least operandSize + PKC wordsize. |
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.
[in] | iR_iX_iN_iT0 | (bits 31~24) iR: index of result buffer, of which the size shall be at least (lenN + PKC wordsize). (bits 23~16) iX: index of input buffer, of which the size shall be at least (lenX + PKC wordsize). (bits 15~8) iN: index of modulus buffer, of which the size is lenN. (bits 7~0) iT0: index of temp buffer, of which the size shall be at least (lenN + PKC wordsize). Buffer N can be used as T0. |
[in] | iT1_iT2_iT3 | (bits 23~16) iT1: index of temp buffer, of which the size shall be at least lenN. Buffer R can be used as T1. TODO: use R (any reason not using R?) (bits 15~8) iT2: index of temp buffer, of which the size shall be at least lenN. (bits 7~0) iT3: index of temp buffer, of which the size shall be at least (lenN + PKC wordsize). |
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.
[in] | pExp | pointer to exponent, which is stored as a big-endian octet string. |
[in] | byteLenExp | byte length of exponent. |
[in] | iR_iX_iN_iT | indices of operands in PKC workarea. |
pExp
iR_iX_iN_iT
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.
[in] | pExp | pointer to exponent, which is stored as a big-endian octet string. |
[in] | pExpTemp | pointer to temporary buffer, in either CPU or PKC workarea. |
[in] | byteLenExp | byte length of exponent. |
[in] | iT3_iX_iT2_iT1 | indices of operands in PKC workarea. |
[in] | iN_iTE_iT0_iR | indices of operands in PKC workarea. |
pExp
pExpTemp
byteLenExp
. iT3_iX_iT2_iT1
byteLenExp
+ 1, 2 * PKC wordsize). iN_iTE_iT0_iR
byteLenExp
+ 1, lenN + PKC wordsize). byteLenExp
+ 1, lenN + PKC wordsize). 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.
2.the most significant PKC word of Y shall be nonzero. 3.size of temp (iT) is 3 pkc wordsizes. 4.if lenX = lenY = pkc wordsize, this function will access to one extra pkc word on top of X. (i.e., read/write to X[pkc word 0], read X[pkc word 1]).
mcuxClMath_Status_Protected_t mcuxClMath_ExactDivide | ( | uint32_t | iR_iX_iY_iT, |
uint32_t | pkcByteLenX, | ||
uint32_t | pkcByteLenY | ||
) |
Exact division.
This function computes the exact division r = x / y.
This function relies on mcuxClMath_ExactDivideOdd to compute the exact division of x / y. Suppose X is a multiple of Y, this function finds R such that (-X) + Y * R = 0. If there is a remainder to this division, this function will fail. The function destroys the content of buffer x. If this content is needed after the function call, it has to be backed up by the caller of this function.
iR_iX_iY_iT | Pointer table indices of parameters |
pkcByteLenX | Bytelength of parameter X |
pkcByteLenY | Bytelength of parameter Y |
MCUXCLMATH_ERRORCODE_OK | Division successful |
MCUXCLMATH_ERRORCODE_ERROR | Error occured during divide operation |