| Kinetis SDK v.2.0 API Reference Manual Rev. 0 Freescale Semiconductor, Inc.

- Main Page
- Related Pages
- API Reference

All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
Data Structures | Enumerations | Functions
LTC PKHA driver
LTC Blocking APIs

## Overview

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

## Data Structures
struct | ltc_pkha_ecc_point_t
| PKHA ECC point structure. More...

## Enumerations
enum | ltc_pkha_timing_t
| Use of timing equalized version of a PKHA function. More...
enum | ltc_pkha_f2m_t { kLTC_PKHA_IntegerArith = 0U, kLTC_PKHA_F2mArith = 1U }
| Integer vs binary polynomial arithmetic selection. More...
enum | ltc_pkha_montgomery_form_t
| Montgomery or normal PKHA input format. More...

## Functions
int | LTC_PKHA_CompareBigNum (const uint8_t *a, size_t sizeA, const uint8_t *b, size_t sizeB)
| Compare two PKHA big numbers. More...
status_t | LTC_PKHA_NormalToMontgomery (LTC_Type *base, 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_pkha_timing_t equalTime, ltc_pkha_f2m_t arithType)
| Converts from integer to Montgomery format. More...
status_t | LTC_PKHA_MontgomeryToNormal (LTC_Type *base, const uint8_t *N, uint16_t sizeN, uint8_t *A, uint16_t *sizeA, uint8_t *B, uint16_t *sizeB, ltc_pkha_timing_t equalTime, ltc_pkha_f2m_t arithType)
| Converts from Montgomery format to int. More...
status_t | LTC_PKHA_ModAdd (LTC_Type *base, 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_pkha_f2m_t arithType)
| Performs modular addition - (A + B) mod N. More...
status_t | LTC_PKHA_ModSub1 (LTC_Type *base, 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...
status_t | LTC_PKHA_ModSub2 (LTC_Type *base, 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...
status_t | LTC_PKHA_ModMul (LTC_Type *base, 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_pkha_f2m_t arithType, ltc_pkha_montgomery_form_t montIn, ltc_pkha_montgomery_form_t montOut, ltc_pkha_timing_t equalTime)
| Performs modular multiplication - (A x B) mod N. More...
status_t | LTC_PKHA_ModExp (LTC_Type *base, 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_pkha_f2m_t arithType, ltc_pkha_montgomery_form_t montIn, ltc_pkha_timing_t equalTime)
| Performs modular exponentiation - (A^E) mod N. More...
status_t | LTC_PKHA_ModRed (LTC_Type *base, const uint8_t *A, uint16_t sizeA, const uint8_t *N, uint16_t sizeN, uint8_t *result, uint16_t *resultSize, ltc_pkha_f2m_t arithType)
| Performs modular reduction - (A) mod N. More...
status_t | LTC_PKHA_ModInv (LTC_Type *base, const uint8_t *A, uint16_t sizeA, const uint8_t *N, uint16_t sizeN, uint8_t *result, uint16_t *resultSize, ltc_pkha_f2m_t arithType)
| Performs modular inversion - (A^-1) mod N. More...
status_t | LTC_PKHA_ModR2 (LTC_Type *base, const uint8_t *N, uint16_t sizeN, uint8_t *result, uint16_t *resultSize, ltc_pkha_f2m_t arithType)
| Computes integer Montgomery factor R^2 mod N. More...
status_t | LTC_PKHA_GCD (LTC_Type *base, const uint8_t *A, uint16_t sizeA, const uint8_t *N, uint16_t sizeN, uint8_t *result, uint16_t *resultSize, ltc_pkha_f2m_t arithType)
| Calculates the greatest common divisor - GCD (A, N). More...
status_t | LTC_PKHA_PrimalityTest (LTC_Type *base, 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...
status_t | LTC_PKHA_ECC_PointAdd (LTC_Type *base, const ltc_pkha_ecc_point_t *A, const ltc_pkha_ecc_point_t *B, const uint8_t *N, const uint8_t *R2modN, const uint8_t *aCurveParam, const uint8_t *bCurveParam, uint8_t size, ltc_pkha_f2m_t arithType, ltc_pkha_ecc_point_t *result)
| Adds elliptic curve points - A + B. More...
status_t | LTC_PKHA_ECC_PointDouble (LTC_Type *base, const ltc_pkha_ecc_point_t *B, const uint8_t *N, const uint8_t *aCurveParam, const uint8_t *bCurveParam, uint8_t size, ltc_pkha_f2m_t arithType, ltc_pkha_ecc_point_t *result)
| Doubles elliptic curve points - B + B. More...
status_t | LTC_PKHA_ECC_PointMul (LTC_Type *base, const ltc_pkha_ecc_point_t *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_pkha_timing_t equalTime, ltc_pkha_f2m_t arithType, ltc_pkha_ecc_point_t *result, bool *infinity)
| Multiplies an elliptic curve point by a scalar - E x (A0, A1). More...

## Data Structure Documentation

struct ltc_pkha_ecc_point_t

### Data Fields
uint8_t * | X
| X coordinate (affine)
uint8_t * | Y
| Y coordinate (affine)

## Enumeration Type Documentation

enum ltc_pkha_timing_t

enum ltc_pkha_f2m_t

Enumerator
kLTC_PKHA_IntegerArith | Use integer arithmetic.
kLTC_PKHA_F2mArith | Use binary polynomial arithmetic.

enum ltc_pkha_montgomery_form_t

## Function Documentation

int LTC_PKHA_CompareBigNum | ( | const uint8_t * | a,
|  | size_t | sizeA,
|  | const uint8_t * | b,
|  | size_t | sizeB
| ) |  |

Compare two PKHA big numbers. Return 1 for a > b, -1 for a < b and 0 if they are same. PKHA big number is lsbyte first. Thus the comparison starts at msbyte which is the last member of tested arrays.

Parameters

  a | First integer represented as an array of bytes, lsbyte first.
  sizeA | Size in bytes of the first integer.
  b | Second integer represented as an array of bytes, lsbyte first.
  sizeB | Size in bytes of the second integer.

Returns
  1 if a > b.
  -1 if a < b.
  0 if a = b.

status_t LTC_PKHA_NormalToMontgomery | ( | LTC_Type * | base,
|  | 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_pkha_timing_t | equalTime,
|  | ltc_pkha_f2m_t | arithType
| ) |  |

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

Parameters

  | base | LTC peripheral base address
  | N | modulus
  | sizeN | size of N in bytes
  [in,out] | A | The first input in non-Montgomery format. Output Montgomery format of the first input.
  [in,out] | sizeA | pointer 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] | B | Second input in non-Montgomery format. Output Montgomery format of the second input.
  [in,out] | sizeB | pointer 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] | R2 | Output Montgomery factor R2 mod N.
  [out] | sizeR2 | pointer to size variable. On output it holds size of Montgomery factor R2 mod N in bytes.
  | equalTime | Run the function time equalized or no timing equalization.
  | arithType | Type of arithmetic to perform (integer or F2m)

Returns
  Operation status.

status_t LTC_PKHA_MontgomeryToNormal | ( | LTC_Type * | base,
|  | const uint8_t * | N,
|  | uint16_t | sizeN,
|  | uint8_t * | A,
|  | uint16_t * | sizeA,
|  | uint8_t * | B,
|  | uint16_t * | sizeB,
|  | ltc_pkha_timing_t | equalTime,
|  | ltc_pkha_f2m_t | arithType
| ) |  |

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

Parameters

  | base | LTC peripheral base address
  | N | modulus.
  | sizeN | size of N modulus in bytes.
  [in,out] | A | Input first number in Montgomery format. Output is non-Montgomery format.
  [in,out] | sizeA | pointer 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] | B | Input first number in Montgomery format. Output is non-Montgomery format.
  [in,out] | sizeB | pointer 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.
  | equalTime | Run the function time equalized or no timing equalization.
  | arithType | Type of arithmetic to perform (integer or F2m)

Returns
  Operation status.

status_t LTC_PKHA_ModAdd | ( | LTC_Type * | base,
|  | 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_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

  | base | LTC peripheral base address
  | A | first addend (integer or binary polynomial)
  | sizeA | Size of A in bytes
  | B | second addend (integer or binary polynomial)
  | sizeB | Size of B in bytes
  | N | modulus. For F2m operation this can be NULL, as N is ignored during F2m polynomial addition.
  | sizeN | Size of N in bytes. This must be given for both integer and F2m polynomial additions.
  [out] | result | Output array to store result of operation
  [out] | resultSize | Output size of operation in bytes
  | arithType | Type of arithmetic to perform (integer or F2m)

Returns
  Operation status.

status_t LTC_PKHA_ModSub1 | ( | LTC_Type * | base,
|  | 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

  | base | LTC peripheral base address
  | A | first addend (integer or binary polynomial)
  | sizeA | Size of A in bytes
  | B | second addend (integer or binary polynomial)
  | sizeB | Size of B in bytes
  | N | modulus
  | sizeN | Size of N in bytes
  [out] | result | Output array to store result of operation
  [out] | resultSize | Output size of operation in bytes

Returns
  Operation status.

status_t LTC_PKHA_ModSub2 | ( | LTC_Type * | base,
|  | 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

  | base | LTC peripheral base address
  | A | first addend (integer or binary polynomial)
  | sizeA | Size of A in bytes
  | B | second addend (integer or binary polynomial)
  | sizeB | Size of B in bytes
  | N | modulus
  | sizeN | Size of N in bytes
  [out] | result | Output array to store result of operation
  [out] | resultSize | Output size of operation in bytes

Returns
  Operation status.

status_t LTC_PKHA_ModMul | ( | LTC_Type * | base,
|  | 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_pkha_f2m_t | arithType,
|  | ltc_pkha_montgomery_form_t | montIn,
|  | ltc_pkha_montgomery_form_t | montOut,
|  | ltc_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

  | base | LTC peripheral base address
  | A | first addend (integer or binary polynomial)
  | sizeA | Size of A in bytes
  | B | second addend (integer or binary polynomial)
  | sizeB | Size of B in bytes
  | N | modulus.
  | sizeN | Size of N in bytes
  [out] | result | Output array to store result of operation
  [out] | resultSize | Output size of operation in bytes
  | arithType | Type of arithmetic to perform (integer or F2m)
  | montIn | Format of inputs
  | montOut | Format of output
  | equalTime | Run the function time equalized or no timing equalization. This argument is ignored for F2m modular multiplication.

Returns
  Operation status.

status_t LTC_PKHA_ModExp | ( | LTC_Type * | base,
|  | 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_pkha_f2m_t | arithType,
|  | ltc_pkha_montgomery_form_t | montIn,
|  | ltc_pkha_timing_t | equalTime
| ) |  |

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

Parameters

  | base | LTC peripheral base address
  | A | first addend (integer or binary polynomial)
  | sizeA | Size of A in bytes
  | N | modulus
  | sizeN | Size of N in bytes
  | E | exponent
  | sizeE | Size of E in bytes
  [out] | result | Output array to store result of operation
  [out] | resultSize | Output size of operation in bytes
  | montIn | Format of A input (normal or Montgomery)
  | arithType | Type of arithmetic to perform (integer or F2m)
  | equalTime | Run the function time equalized or no timing equalization.

Returns
  Operation status.

status_t LTC_PKHA_ModRed | ( | LTC_Type * | base,
|  | const uint8_t * | A,
|  | uint16_t | sizeA,
|  | const uint8_t * | N,
|  | uint16_t | sizeN,
|  | uint8_t * | result,
|  | uint16_t * | resultSize,
|  | ltc_pkha_f2m_t | arithType
| ) |  |

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

Parameters

  | base | LTC peripheral base address
  | A | first addend (integer or binary polynomial)
  | sizeA | Size of A in bytes
  | N | modulus
  | sizeN | Size of N in bytes
  [out] | result | Output array to store result of operation
  [out] | resultSize | Output size of operation in bytes
  | arithType | Type of arithmetic to perform (integer or F2m)

Returns
  Operation status.

status_t LTC_PKHA_ModInv | ( | LTC_Type * | base,
|  | const uint8_t * | A,
|  | uint16_t | sizeA,
|  | const uint8_t * | N,
|  | uint16_t | sizeN,
|  | uint8_t * | result,
|  | uint16_t * | resultSize,
|  | ltc_pkha_f2m_t | arithType
| ) |  |

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

Parameters

  | base | LTC peripheral base address
  | A | first addend (integer or binary polynomial)
  | sizeA | Size of A in bytes
  | N | modulus
  | sizeN | Size of N in bytes
  [out] | result | Output array to store result of operation
  [out] | resultSize | Output size of operation in bytes
  | arithType | Type of arithmetic to perform (integer or F2m)

Returns
  Operation status.

status_t LTC_PKHA_ModR2 | ( | LTC_Type * | base,
|  | const uint8_t * | N,
|  | uint16_t | sizeN,
|  | uint8_t * | result,
|  | uint16_t * | resultSize,
|  | ltc_pkha_f2m_t | arithType
| ) |  |

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

Parameters

  | base | LTC peripheral base address
  | N | modulus
  | sizeN | Size of N in bytes
  [out] | result | Output array to store result of operation
  [out] | resultSize | Output size of operation in bytes
  | arithType | Type of arithmetic to perform (integer or F2m)

Returns
  Operation status.

status_t LTC_PKHA_GCD | ( | LTC_Type * | base,
|  | const uint8_t * | A,
|  | uint16_t | sizeA,
|  | const uint8_t * | N,
|  | uint16_t | sizeN,
|  | uint8_t * | result,
|  | uint16_t * | resultSize,
|  | ltc_pkha_f2m_t | arithType
| ) |  |

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

Parameters

  | base | LTC peripheral base address
  | A | first value (must be smaller than or equal to N)
  | sizeA | Size of A in bytes
  | N | second value (must be non-zero)
  | sizeN | Size of N in bytes
  [out] | result | Output array to store result of operation
  [out] | resultSize | Output size of operation in bytes
  | arithType | Type of arithmetic to perform (integer or F2m)

Returns
  Operation status.

status_t LTC_PKHA_PrimalityTest | ( | LTC_Type * | base,
|  | 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

  | base | LTC peripheral base address
  | A | initial random seed
  | sizeA | Size of A in bytes
  | B | number of trial runs
  | sizeB | Size of B in bytes
  | N | candidate prime integer
  | sizeN | Size of N in bytes
  [out] | res | True if the value is likely prime or false otherwise

Returns
  Operation status.

status_t LTC_PKHA_ECC_PointAdd | ( | LTC_Type * | base,
|  | const ltc_pkha_ecc_point_t * | A,
|  | const ltc_pkha_ecc_point_t * | B,
|  | const uint8_t * | N,
|  | const uint8_t * | R2modN,
|  | const uint8_t * | aCurveParam,
|  | const uint8_t * | bCurveParam,
|  | uint8_t | size,
|  | ltc_pkha_f2m_t | arithType,
|  | ltc_pkha_ecc_point_t * | result
| ) |  |

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

Parameters

  | base | LTC peripheral base address
  | A | Left-hand point
  | B | Right-hand point
  | N | Prime modulus of the field
  | R2modN | NULL (the function computes R2modN internally) or pointer to pre-computed R2modN (obtained from LTC_PKHA_ModR2() function).
  | aCurveParam | A parameter from curve equation
  | bCurveParam | B parameter from curve equation (constant)
  | size | Size in bytes of curve points and parameters
  | arithType | Type of arithmetic to perform (integer or F2m)
  [out] | result | Result point

Returns
  Operation status.

status_t LTC_PKHA_ECC_PointDouble | ( | LTC_Type * | base,
|  | const ltc_pkha_ecc_point_t * | B,
|  | const uint8_t * | N,
|  | const uint8_t * | aCurveParam,
|  | const uint8_t * | bCurveParam,
|  | uint8_t | size,
|  | ltc_pkha_f2m_t | arithType,
|  | ltc_pkha_ecc_point_t * | result
| ) |  |

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

Parameters

  | base | LTC peripheral base address
  | B | Point to double
  | N | Prime modulus of the field
  | aCurveParam | A parameter from curve equation
  | bCurveParam | B parameter from curve equation (constant)
  | size | Size in bytes of curve points and parameters
  | arithType | Type of arithmetic to perform (integer or F2m)
  [out] | result | Result point

Returns
  Operation status.

status_t LTC_PKHA_ECC_PointMul | ( | LTC_Type * | base,
|  | const ltc_pkha_ecc_point_t * | 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_pkha_timing_t | equalTime,
|  | ltc_pkha_f2m_t | arithType,
|  | ltc_pkha_ecc_point_t * | 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

  | base | LTC peripheral base address
  | A | Point as multiplicand
  | E | Scalar multiple
  | sizeE | The size of E, in bytes
  | N | Modulus, a prime number for the Fp field or Irreducible polynomial for F2m field.
  | R2modN | NULL (the function computes R2modN internally) or pointer to pre-computed R2modN (obtained from LTC_PKHA_ModR2() function).
  | aCurveParam | A parameter from curve equation
  | bCurveParam | B parameter from curve equation (C parameter for operation over F2m).
  | size | Size in bytes of curve points and parameters
  | equalTime | Run the function time equalized or no timing equalization.
  | arithType | Type of arithmetic to perform (integer or F2m)
  [out] | result | Result point
  [out] | infinity | Output 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.