Kinetis SDK v.1.3 API Reference Manual  Rev. 0
Freescale Semiconductor, Inc.
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
LTC PKHA driver

Overview

This section describes the programming interface of the LTC PKHA driver.

Data Structures

struct  ltc_pkha_ecc_point
 PKHA ECC point structure. More...
 

Functions

ltc_status_t LTC_DRV_PKHA_Clear_RegABNE (uint32_t instance, bool A, bool B, bool N, bool E)
 Clears PKHA memory function. More...
 
ltc_status_t LTC_DRV_PKHA_NormalToMontgomery (uint32_t instance, const uint8_t *N, uint16_t sizeN, uint8_t *A, uint16_t *sizeA, uint8_t *B, uint16_t *sizeB, uint8_t *R2, uint16_t *sizeR2, ltc_hal_pkha_timing_t equalTime, ltc_hal_pkha_f2m_t arithType)
 Converts from int to Montgomery format. More...
 
ltc_status_t LTC_DRV_PKHA_MontgomeryToNormal (uint32_t instance, const uint8_t *N, uint16_t sizeN, uint8_t *A, uint16_t *sizeA, uint8_t *B, uint16_t *sizeB, ltc_hal_pkha_timing_t equalTime, ltc_hal_pkha_f2m_t arithType)
 Converts from Montgomery format to int. More...
 
ltc_status_t LTC_DRV_PKHA_ModAdd (uint32_t instance, const uint8_t *A, uint16_t sizeA, const uint8_t *B, uint16_t sizeB, const uint8_t *N, uint16_t sizeN, uint8_t *result, uint16_t *resultSize, ltc_hal_pkha_f2m_t arithType)
 Performs modular addition - (A + B) mod N. More...
 
ltc_status_t LTC_DRV_PKHA_ModSub1 (uint32_t instance, const uint8_t *A, uint16_t sizeA, const uint8_t *B, uint16_t sizeB, const uint8_t *N, uint16_t sizeN, uint8_t *result, uint16_t *resultSize)
 Performs modular subtraction - (A - B) mod N. More...
 
ltc_status_t LTC_DRV_PKHA_ModSub2 (uint32_t instance, const uint8_t *A, uint16_t sizeA, const uint8_t *B, uint16_t sizeB, const uint8_t *N, uint16_t sizeN, uint8_t *result, uint16_t *resultSize)
 Performs modular subtraction - (B - A) mod N. More...
 
ltc_status_t LTC_DRV_PKHA_ModMul (uint32_t instance, const uint8_t *A, uint16_t sizeA, const uint8_t *B, uint16_t sizeB, const uint8_t *N, uint16_t sizeN, uint8_t *result, uint16_t *resultSize, ltc_hal_pkha_f2m_t arithType, ltc_hal_pkha_montgomery_form_t montIn, ltc_hal_pkha_montgomery_form_t montOut, ltc_hal_pkha_timing_t equalTime)
 Performs modular multiplication - (A x B) mod N. More...
 
ltc_status_t LTC_DRV_PKHA_ModExp (uint32_t instance, const uint8_t *A, uint16_t sizeA, const uint8_t *N, uint16_t sizeN, const uint8_t *E, uint16_t sizeE, uint8_t *result, uint16_t *resultSize, ltc_hal_pkha_f2m_t arithType, ltc_hal_pkha_montgomery_form_t montIn, ltc_hal_pkha_timing_t equalTime)
 Performs modular exponentiation - (A^E) mod N. More...
 
ltc_status_t LTC_DRV_PKHA_ModRed (uint32_t instance, const uint8_t *A, uint16_t sizeA, const uint8_t *N, uint16_t sizeN, uint8_t *result, uint16_t *resultSize, ltc_hal_pkha_f2m_t arithType)
 Performs modular reduction - (A) mod N. More...
 
ltc_status_t LTC_DRV_PKHA_ModInv (uint32_t instance, const uint8_t *A, uint16_t sizeA, const uint8_t *N, uint16_t sizeN, uint8_t *result, uint16_t *resultSize, ltc_hal_pkha_f2m_t arithType)
 Performs modular inversion - (A^-1) mod N. More...
 
ltc_status_t LTC_DRV_PKHA_ModR2 (uint32_t instance, const uint8_t *N, uint16_t sizeN, uint8_t *result, uint16_t *resultSize, ltc_hal_pkha_f2m_t arithType)
 Computes integer Montgomery factor R^2 mod N. More...
 
ltc_status_t LTC_DRV_PKHA_GCD (uint32_t instance, const uint8_t *A, uint16_t sizeA, const uint8_t *N, uint16_t sizeN, uint8_t *result, uint16_t *resultSize, ltc_hal_pkha_f2m_t arithType)
 Calculates the greatest common divisor - GCD (A, N). More...
 
ltc_status_t LTC_DRV_PKHA_PrimalityTest (uint32_t instance, const uint8_t *A, uint16_t sizeA, const uint8_t *B, uint16_t sizeB, const uint8_t *N, uint16_t sizeN, bool *res)
 Executes Miller-Rabin primality test. More...
 
ltc_status_t LTC_DRV_PKHA_ECC_PointAdd (uint32_t instance, const ltc_pkha_ecc_point *A, const ltc_pkha_ecc_point *B, const uint8_t *N, const uint8_t *R2modN, const uint8_t *aCurveParam, const uint8_t *bCurveParam, uint8_t size, ltc_hal_pkha_f2m_t arithType, ltc_pkha_ecc_point *result)
 Adds elliptic curve points - A + B. More...
 
ltc_status_t LTC_DRV_PKHA_ECC_PointDouble (uint32_t instance, const ltc_pkha_ecc_point *B, const uint8_t *N, const uint8_t *aCurveParam, const uint8_t *bCurveParam, uint8_t size, ltc_hal_pkha_f2m_t arithType, ltc_pkha_ecc_point *result)
 Doubles elliptic curve points - B + B. More...
 
ltc_status_t LTC_DRV_PKHA_ECC_PointMul (uint32_t instance, const ltc_pkha_ecc_point *A, const uint8_t *E, uint8_t sizeE, const uint8_t *N, const uint8_t *R2modN, const uint8_t *aCurveParam, const uint8_t *bCurveParam, uint8_t size, ltc_hal_pkha_timing_t equalTime, ltc_hal_pkha_f2m_t arithType, ltc_pkha_ecc_point *result, bool *infinity)
 Multiplies an elliptic curve point by a scalar - E x (A0, A1). More...
 

Data Structure Documentation

struct ltc_pkha_ecc_point

Data Fields

uint8_t * X
 X coordinate (affine)
 
uint8_t * Y
 Y coordinate (affine)
 

Function Documentation

ltc_status_t LTC_DRV_PKHA_Clear_RegABNE ( uint32_t  instance,
bool  A,
bool  B,
bool  N,
bool  E 
)

This function clears the selected PKHA memory area.

Parameters
instanceLTC peripheral instance number
ABoolean value True (LTC_PKA shall be cleared) or false (LTC_PKA is left untouched).
BBoolean value True (LTC_PKB shall be cleared) or False (LTC_PKB is left untouched).
NBoolean value True (LTC_PKN shall be cleared) or False (LTC_PKN is left untouched).
EBoolean value True (LTC_PKE shall be cleared) or False (LTC_PKE is left untouched).
Returns
Operation status.
ltc_status_t LTC_DRV_PKHA_NormalToMontgomery ( uint32_t  instance,
const uint8_t *  N,
uint16_t  sizeN,
uint8_t *  A,
uint16_t *  sizeA,
uint8_t *  B,
uint16_t *  sizeB,
uint8_t *  R2,
uint16_t *  sizeR2,
ltc_hal_pkha_timing_t  equalTime,
ltc_hal_pkha_f2m_t  arithType 
)

This function computes R2 mod N and optionally converts A or B into Montgomery format of A or B.

Parameters
instanceLTC peripheral instance number
Nmodulus
sizeNsize of N in bytes
[in,out]Thefirst input in non-Montgomery format. Output Montgomery format of the first input.
[in,out]sizeApointer to size variable. On input it holds size of input A in bytes. On output it holds size of Montgomery format of A in bytes.
[in,out]BSecond input in non-Montgomery format. Output Montgomery format of the second input.
[in,out]sizeBpointer to size variable. On input it holds size of input B in bytes. On output it holds size of Montgomery format of B in bytes.
[out]R2Output Montgomery factor R2 mod N.
[out]sizeR2pointer to size variable. On output it holds size of Montgomery factor R2 mod N in bytes.
equalTimeRun the function time equalized or no timing equalization.
arithTypeType of arithmetic to perform (integer or F2m)
Returns
Operation status.
ltc_status_t LTC_DRV_PKHA_MontgomeryToNormal ( uint32_t  instance,
const uint8_t *  N,
uint16_t  sizeN,
uint8_t *  A,
uint16_t *  sizeA,
uint8_t *  B,
uint16_t *  sizeB,
ltc_hal_pkha_timing_t  equalTime,
ltc_hal_pkha_f2m_t  arithType 
)

This function converts Montgomery format of A or B into int A or B.

Parameters
instanceLTC peripheral instance number
Nmodulus.
sizeNsize of N modulus in bytes.
[in,out]AInput first number in Montgomery format. Output is non-Montgomery format.
[in,out]sizeApointer to size variable. On input it holds size of the input A in bytes. On output it holds size of non-Montgomery A in bytes.
[in,out]BInput first number in Montgomery format. Output is non-Montgomery format.
[in,out]sizeBpointer to size variable. On input it holds size of the input B in bytes. On output it holds size of non-Montgomery B in bytes.
equalTimeRun the function time equalized or no timing equalization.
arithTypeType of arithmetic to perform (integer or F2m)
Returns
Operation status.
ltc_status_t LTC_DRV_PKHA_ModAdd ( uint32_t  instance,
const uint8_t *  A,
uint16_t  sizeA,
const uint8_t *  B,
uint16_t  sizeB,
const uint8_t *  N,
uint16_t  sizeN,
uint8_t *  result,
uint16_t *  resultSize,
ltc_hal_pkha_f2m_t  arithType 
)

This function performs modular addition of (A + B) mod N, with either integer or binary polynomial (F2m) inputs. In the F2m form, this function is equivalent to a bitwise XOR and it is functionally the same as subtraction.

Parameters
instanceLTC peripheral instance number
Afirst addend (integer or binary polynomial)
sizeASize of A in bytes
Bsecond addend (integer or binary polynomial)
sizeBSize of B in bytes
Nmodulus. For F2m operation this can be NULL, as N is ignored during F2m polynomial addition.
sizeNSize of N in bytes. This must be given for both integer and F2m polynomial additions.
[out]resultOutput array to store result of operation
[out]resultSizeOutput size of operation in bytes
arithTypeType of arithmetic to perform (integer or F2m)
Returns
Operation status.
ltc_status_t LTC_DRV_PKHA_ModSub1 ( uint32_t  instance,
const uint8_t *  A,
uint16_t  sizeA,
const uint8_t *  B,
uint16_t  sizeB,
const uint8_t *  N,
uint16_t  sizeN,
uint8_t *  result,
uint16_t *  resultSize 
)

This function performs modular subtraction of (A - B) mod N with integer inputs.

Parameters
instanceLTC peripheral instance number
Afirst addend (integer or binary polynomial)
sizeASize of A in bytes
Bsecond addend (integer or binary polynomial)
sizeBSize of B in bytes
Nmodulus
sizeNSize of N in bytes
[out]resultOutput array to store result of operation
[out]resultSizeOutput size of operation in bytes
Returns
Operation status.
ltc_status_t LTC_DRV_PKHA_ModSub2 ( uint32_t  instance,
const uint8_t *  A,
uint16_t  sizeA,
const uint8_t *  B,
uint16_t  sizeB,
const uint8_t *  N,
uint16_t  sizeN,
uint8_t *  result,
uint16_t *  resultSize 
)

This function performs modular subtraction of (B - A) mod N, with integer inputs.

Parameters
instanceLTC peripheral instance number
Afirst addend (integer or binary polynomial)
sizeASize of A in bytes
Bsecond addend (integer or binary polynomial)
sizeBSize of B in bytes
Nmodulus
sizeNSize of N in bytes
[out]resultOutput array to store result of operation
[out]resultSizeOutput size of operation in bytes
Returns
Operation status.
ltc_status_t LTC_DRV_PKHA_ModMul ( uint32_t  instance,
const uint8_t *  A,
uint16_t  sizeA,
const uint8_t *  B,
uint16_t  sizeB,
const uint8_t *  N,
uint16_t  sizeN,
uint8_t *  result,
uint16_t *  resultSize,
ltc_hal_pkha_f2m_t  arithType,
ltc_hal_pkha_montgomery_form_t  montIn,
ltc_hal_pkha_montgomery_form_t  montOut,
ltc_hal_pkha_timing_t  equalTime 
)

This function performs modular multiplication with either integer or binary polynomial (F2m) inputs. It can optionally specify whether inputs and/or outputs will be in Montgomery form or not.

Parameters
instanceLTC peripheral instance number
Afirst addend (integer or binary polynomial)
sizeASize of A in bytes
Bsecond addend (integer or binary polynomial)
sizeBSize of B in bytes
Nmodulus.
sizeNSize of N in bytes
[out]resultOutput array to store result of operation
[out]resultSizeOutput size of operation in bytes
arithTypeType of arithmetic to perform (integer or F2m)
montInFormat of inputs
montOutFormat of output
equalTimeRun the function time equalized or no timing equalization. This argument is ignored for F2m modular multiplication.
Returns
Operation status.
ltc_status_t LTC_DRV_PKHA_ModExp ( uint32_t  instance,
const uint8_t *  A,
uint16_t  sizeA,
const uint8_t *  N,
uint16_t  sizeN,
const uint8_t *  E,
uint16_t  sizeE,
uint8_t *  result,
uint16_t *  resultSize,
ltc_hal_pkha_f2m_t  arithType,
ltc_hal_pkha_montgomery_form_t  montIn,
ltc_hal_pkha_timing_t  equalTime 
)

This function performs modular exponentiation with either integer or binary polynomial (F2m) inputs.

Parameters
instanceLTC peripheral instance number
Afirst addend (integer or binary polynomial)
sizeASize of A in bytes
Nmodulus
sizeNSize of N in bytes
Eexponent
sizeESize of E in bytes
[out]resultOutput array to store result of operation
[out]resultSizeOutput size of operation in bytes
montIntFormat of A input (normal or Montgomery)
arithTypeType of arithmetic to perform (integer or F2m)
equalTimeRun the function time equalized or no timing equalization.
Returns
Operation status.
ltc_status_t LTC_DRV_PKHA_ModRed ( uint32_t  instance,
const uint8_t *  A,
uint16_t  sizeA,
const uint8_t *  N,
uint16_t  sizeN,
uint8_t *  result,
uint16_t *  resultSize,
ltc_hal_pkha_f2m_t  arithType 
)

This function performs modular reduction with either integer or binary polynomial (F2m) inputs.

Parameters
instanceLTC peripheral instance number
Afirst addend (integer or binary polynomial)
sizeASize of A in bytes
Nmodulus
sizeNSize of N in bytes
[out]resultOutput array to store result of operation
[out]resultSizeOutput size of operation in bytes
arithTypeType of arithmetic to perform (integer or F2m)
Returns
Operation status.
ltc_status_t LTC_DRV_PKHA_ModInv ( uint32_t  instance,
const uint8_t *  A,
uint16_t  sizeA,
const uint8_t *  N,
uint16_t  sizeN,
uint8_t *  result,
uint16_t *  resultSize,
ltc_hal_pkha_f2m_t  arithType 
)

This function performs modular inversion with either integer or binary polynomial (F2m) inputs.

Parameters
instanceLTC peripheral instance number
Afirst addend (integer or binary polynomial)
sizeASize of A in bytes
Nmodulus
sizeNSize of N in bytes
[out]resultOutput array to store result of operation
[out]resultSizeOutput size of operation in bytes
arithTypeType of arithmetic to perform (integer or F2m)
Returns
Operation status.
ltc_status_t LTC_DRV_PKHA_ModR2 ( uint32_t  instance,
const uint8_t *  N,
uint16_t  sizeN,
uint8_t *  result,
uint16_t *  resultSize,
ltc_hal_pkha_f2m_t  arithType 
)

This function computes a constant to assist in converting operands into the Montgomery residue system representation.

Parameters
instanceLTC peripheral instance number
Nmodulus
sizeNSize of N in bytes
[out]resultOutput array to store result of operation
[out]resultSizeOutput size of operation in bytes
arithTypeType of arithmetic to perform (integer or F2m)
Returns
Operation status.
ltc_status_t LTC_DRV_PKHA_GCD ( uint32_t  instance,
const uint8_t *  A,
uint16_t  sizeA,
const uint8_t *  N,
uint16_t  sizeN,
uint8_t *  result,
uint16_t *  resultSize,
ltc_hal_pkha_f2m_t  arithType 
)

This function calculates the greatest common divisor of two inputs with either integer or binary polynomial (F2m) inputs.

Parameters
instanceLTC peripheral instance number
Afirst value (must be smaller than or equal to N)
sizeASize of A in bytes
Nsecond value (must be non-zero)
sizeNSize of N in bytes
[out]resultOutput array to store result of operation
[out]resultSizeOutput size of operation in bytes
arithTypeType of arithmetic to perform (integer or F2m)
Returns
Operation status.
ltc_status_t LTC_DRV_PKHA_PrimalityTest ( uint32_t  instance,
const uint8_t *  A,
uint16_t  sizeA,
const uint8_t *  B,
uint16_t  sizeB,
const uint8_t *  N,
uint16_t  sizeN,
bool *  res 
)

This function calculates whether or not a candidate prime number is likely to be a prime.

Parameters
instanceLTC peripheral instance number
Ainitial random seed
sizeASize of A in bytes
Bnumber of trial runs
sizeBSize of B in bytes
Ncandidate prime integer
sizeNSize of N in bytes
[out]resTrue if the value is likely prime or false otherwise
Returns
Operation status.
ltc_status_t LTC_DRV_PKHA_ECC_PointAdd ( uint32_t  instance,
const ltc_pkha_ecc_point A,
const ltc_pkha_ecc_point B,
const uint8_t *  N,
const uint8_t *  R2modN,
const uint8_t *  aCurveParam,
const uint8_t *  bCurveParam,
uint8_t  size,
ltc_hal_pkha_f2m_t  arithType,
ltc_pkha_ecc_point result 
)

This function performs ECC point addition over a prime field (Fp) or binary field (F2m) using affine coordinates.

Parameters
instanceLTC peripheral instance number
ALeft-hand point
BRight-hand point
NPrime modulus of the field
R2modNNULL (the function computes R2modN internally) or pointer to pre-computed R2modN (obtained from LTC_DRV_PKHA_ModR2() function).
aCurveParamA parameter from curve equation
aCurveParamB parameter from curve equation (constant)
sizeSize in bytes of curve points and parameters
arithTypeType of arithmetic to perform (integer or F2m)
[out]resultResult point
Returns
Operation status.
ltc_status_t LTC_DRV_PKHA_ECC_PointDouble ( uint32_t  instance,
const ltc_pkha_ecc_point B,
const uint8_t *  N,
const uint8_t *  aCurveParam,
const uint8_t *  bCurveParam,
uint8_t  size,
ltc_hal_pkha_f2m_t  arithType,
ltc_pkha_ecc_point result 
)

This function performs ECC point doubling over a prime field (Fp) or binary field (F2m) using affine coordinates.

Parameters
instanceLTC peripheral instance number
BPoint to double
NPrime modulus of the field
aCurveParamA parameter from curve equation
aCurveParamB parameter from curve equation (constant)
sizeSize in bytes of curve points and parameters
arithTypeType of arithmetic to perform (integer or F2m)
[out]resultResult point
Returns
Operation status.
ltc_status_t LTC_DRV_PKHA_ECC_PointMul ( uint32_t  instance,
const ltc_pkha_ecc_point A,
const uint8_t *  E,
uint8_t  sizeE,
const uint8_t *  N,
const uint8_t *  R2modN,
const uint8_t *  aCurveParam,
const uint8_t *  bCurveParam,
uint8_t  size,
ltc_hal_pkha_timing_t  equalTime,
ltc_hal_pkha_f2m_t  arithType,
ltc_pkha_ecc_point result,
bool *  infinity 
)

This function performs ECC point multiplication to multiply an ECC point by a scalar integer multiplier over a prime field (Fp) or a binary field (F2m).

Parameters
instanceLTC peripheral instance number
APoint as multiplicand
EScalar multiple
sizeEThe size of E, in bytes
NModulus, a prime number for the Fp field or Irreducible polynomial for F2m field.
NULL(the function computes R2modN internally) or pointer to pre-computed R2modN (obtained from LTC_DRV_PKHA_ModR2() function).
aCurveParamA parameter from curve equation
bCurveParamB parameter from curve equation (C parameter for operation over F2m).
sizeSize in bytes of curve points and parameters
equalTimeRun the function time equalized or no timing equalization.
arithTypeType of arithmetic to perform (integer or F2m)
[out]resultResult point
[out]infinityOutput true if the result is point of infinity, and false otherwise. Writing of this output will be ignored if the argument is NULL.
Returns
Operation status.