CC26xx Driver Library
[pka.h] Public Key Accelerator

Data Structures

union  PKA_EccParam224
 
union  PKA_EccParam256
 
union  PKA_EccParam384
 
union  PKA_EccParam512
 
union  PKA_EccParam521
 
struct  PKA_EccPoint224_
 
struct  PKA_EccPoint256_
 
struct  PKA_EccPoint384_
 
struct  PKA_EccPoint512_
 
struct  PKA_EccPoint521_
 

Functions

uint32_t PKAGetOpsStatus (void)
 Gets the PKA operation status. More...
 
bool PKAArrayAllZeros (const uint8_t *array, uint32_t arrayLength)
 Checks whether and array only consists of zeros. More...
 
void PKAZeroOutArray (const uint8_t *array, uint32_t arrayLength)
 Zeros-out an array. More...
 
uint32_t PKABigNumModStart (const uint8_t *bigNum, uint32_t bigNumLength, const uint8_t *modulus, uint32_t modulusLength, uint32_t *resultPKAMemAddr)
 Starts a big number modulus operation. More...
 
uint32_t PKABigNumModGetResult (uint8_t *resultBuf, uint32_t length, uint32_t resultPKAMemAddr)
 Gets the result of the big number modulus operation. More...
 
uint32_t PKABigNumDivideStart (const uint8_t *dividend, uint32_t dividendLength, const uint8_t *divisor, uint32_t divisorLength, uint32_t *resultQuotientMemAddr, uint32_t *resultRemainderMemAddr)
 Starts a big number divide operation. More...
 
uint32_t PKABigNumDivideGetQuotient (uint8_t *resultBuf, uint32_t *length, uint32_t resultQuotientMemAddr)
 Gets the quotient of the big number divide operation. More...
 
uint32_t PKABigNumDivideGetRemainder (uint8_t *resultBuf, uint32_t *length, uint32_t resultRemainderMemAddr)
 Gets the remainder of the big number divide operation. More...
 
uint32_t PKABigNumCmpStart (const uint8_t *bigNum1, const uint8_t *bigNum2, uint32_t length)
 Starts the comparison of two big numbers. More...
 
uint32_t PKABigNumCmpGetResult (void)
 Gets the result of the comparison operation of two big numbers. More...
 
uint32_t PKABigNumInvModStart (const uint8_t *bigNum, uint32_t bigNumLength, const uint8_t *modulus, uint32_t modulusLength, uint32_t *resultPKAMemAddr)
 Starts a big number inverse modulo operation. More...
 
uint32_t PKABigNumInvModGetResult (uint8_t *resultBuf, uint32_t length, uint32_t resultPKAMemAddr)
 Gets the result of the big number inverse modulo operation. More...
 
uint32_t PKABigNumMultiplyStart (const uint8_t *multiplicand, uint32_t multiplicandLength, const uint8_t *multiplier, uint32_t multiplierLength, uint32_t *resultPKAMemAddr)
 Starts the multiplication of two big numbers. More...
 
uint32_t PKABigNumMultGetResult (uint8_t *resultBuf, uint32_t *resultLength, uint32_t resultPKAMemAddr)
 Gets the result of the big number multiplication. More...
 
uint32_t PKABigNumAddStart (const uint8_t *bigNum1, uint32_t bigNum1Length, const uint8_t *bigNum2, uint32_t bigNum2Length, uint32_t *resultPKAMemAddr)
 Starts the addition of two big numbers. More...
 
uint32_t PKABigNumAddGetResult (uint8_t *resultBuf, uint32_t *resultLength, uint32_t resultPKAMemAddr)
 Gets the result of the addition operation on two big numbers. More...
 
uint32_t PKABigNumSubStart (const uint8_t *minuend, uint32_t minuendLength, const uint8_t *subtrahend, uint32_t subtrahendLength, uint32_t *resultPKAMemAddr)
 Starts the subtraction of one big number from another. More...
 
uint32_t PKABigNumSubGetResult (uint8_t *resultBuf, uint32_t *resultLength, uint32_t resultPKAMemAddr)
 Gets the result of the subtraction operation on two big numbers. More...
 
uint32_t PKAEccMultiplyStart (const uint8_t *scalar, const uint8_t *curvePointX, const uint8_t *curvePointY, const uint8_t *prime, const uint8_t *a, const uint8_t *b, uint32_t length, uint32_t *resultPKAMemAddr)
 Starts ECC multiplication. More...
 
uint32_t PKAEccMontgomeryMultiplyStart (const uint8_t *scalar, const uint8_t *curvePointX, const uint8_t *prime, const uint8_t *a, uint32_t length, uint32_t *resultPKAMemAddr)
 Starts ECC Montgomery multiplication. More...
 
uint32_t PKAEccMultiplyGetResult (uint8_t *curvePointX, uint8_t *curvePointY, uint32_t resultPKAMemAddr, uint32_t length)
 Gets the result of ECC multiplication. More...
 
uint32_t PKAEccAddStart (const uint8_t *curvePoint1X, const uint8_t *curvePoint1Y, const uint8_t *curvePoint2X, const uint8_t *curvePoint2Y, const uint8_t *prime, const uint8_t *a, uint32_t length, uint32_t *resultPKAMemAddr)
 Starts the ECC addition. More...
 
uint32_t PKAEccAddGetResult (uint8_t *curvePointX, uint8_t *curvePointY, uint32_t resultPKAMemAddr, uint32_t length)
 Gets the result of the ECC addition. More...
 
uint32_t PKAEccVerifyPublicKeyWeierstrassStart (const uint8_t *curvePointX, const uint8_t *curvePointY, const uint8_t *prime, const uint8_t *a, const uint8_t *b, const uint8_t *order, uint32_t length)
 Begins the validation of a public key against a Short-Weierstrass curve. More...
 

Variables

const PKA_EccPoint224 NISTP224_generator
 X coordinate of the generator point of the NISTP224 curve. More...
 
const PKA_EccParam224 NISTP224_prime
 Prime of the NISTP224 curve. More...
 
const PKA_EccParam224 NISTP224_a
 a constant of the NISTP224 curve when expressed in short Weierstrass form (y^3 = x^2 + a*x + b). More...
 
const PKA_EccParam224 NISTP224_b
 b constant of the NISTP224 curve when expressed in short Weierstrass form (y^3 = x^2 + a*x + b). More...
 
const PKA_EccParam224 NISTP224_order
 Order of the NISTP224 curve. More...
 
const PKA_EccPoint256 NISTP256_generator
 X coordinate of the generator point of the NISTP256 curve. More...
 
const PKA_EccParam256 NISTP256_prime
 Prime of the NISTP256 curve. More...
 
const PKA_EccParam256 NISTP256_a
 a constant of the NISTP256 curve when expressed in short Weierstrass form (y^3 = x^2 + a*x + b). More...
 
const PKA_EccParam256 NISTP256_b
 b constant of the NISTP256 curve when expressed in short Weierstrass form (y^3 = x^2 + a*x + b). More...
 
const PKA_EccParam256 NISTP256_order
 Order of the NISTP256 curve. More...
 
const PKA_EccPoint384 NISTP384_generator
 X coordinate of the generator point of the NISTP384 curve. More...
 
const PKA_EccParam384 NISTP384_prime
 Prime of the NISTP384 curve. More...
 
const PKA_EccParam384 NISTP384_a
 a constant of the NISTP384 curve when expressed in short Weierstrass form (y^3 = x^2 + a*x + b). More...
 
const PKA_EccParam384 NISTP384_b
 b constant of the NISTP384 curve when expressed in short Weierstrass form (y^3 = x^2 + a*x + b). More...
 
const PKA_EccParam384 NISTP384_order
 Order of the NISTP384 curve. More...
 
const PKA_EccPoint521 NISTP521_generator
 X coordinate of the generator point of the NISTP521 curve. More...
 
const PKA_EccParam521 NISTP521_prime
 Prime of the NISTP521 curve. More...
 
const PKA_EccParam521 NISTP521_a
 a constant of the NISTP521 curve when expressed in short Weierstrass form (y^3 = x^2 + a*x + b). More...
 
const PKA_EccParam521 NISTP521_b
 b constant of the NISTP521 curve when expressed in short Weierstrass form (y^3 = x^2 + a*x + b). More...
 
const PKA_EccParam521 NISTP521_order
 Order of the NISTP521 curve. More...
 
const PKA_EccPoint256 BrainpoolP256R1_generator
 X coordinate of the generator point of the BrainpoolP256R1 curve. More...
 
const PKA_EccParam256 BrainpoolP256R1_prime
 Prime of the BrainpoolP256R1 curve. More...
 
const PKA_EccParam256 BrainpoolP256R1_a
 a constant of the BrainpoolP256R1 curve when expressed in short Weierstrass form (y^3 = x^2 + a*x + b). More...
 
const PKA_EccParam256 BrainpoolP256R1_b
 b constant of the BrainpoolP256R1 curve when expressed in short Weierstrass form (y^3 = x^2 + a*x + b). More...
 
const PKA_EccParam256 BrainpoolP256R1_order
 Order of the BrainpoolP256R1 curve. More...
 
const PKA_EccPoint384 BrainpoolP384R1_generator
 X coordinate of the generator point of the BrainpoolP384R1 curve. More...
 
const PKA_EccParam384 BrainpoolP384R1_prime
 Prime of the BrainpoolP384R1 curve. More...
 
const PKA_EccParam384 BrainpoolP384R1_a
 a constant of the BrainpoolP384R1 curve when expressed in short Weierstrass form (y^3 = x^2 + a*x + b). More...
 
const PKA_EccParam384 BrainpoolP384R1_b
 b constant of the BrainpoolP384R1 curve when expressed in short Weierstrass form (y^3 = x^2 + a*x + b). More...
 
const PKA_EccParam384 BrainpoolP384R1_order
 Order of the BrainpoolP384R1 curve. More...
 
const PKA_EccPoint512 BrainpoolP512R1_generator
 X coordinate of the generator point of the BrainpoolP512R1 curve. More...
 
const PKA_EccParam512 BrainpoolP512R1_prime
 Prime of the BrainpoolP512R1 curve. More...
 
const PKA_EccParam512 BrainpoolP512R1_a
 a constant of the BrainpoolP512R1 curve when expressed in short Weierstrass form (y^3 = x^2 + a*x + b). More...
 
const PKA_EccParam512 BrainpoolP512R1_b
 b constant of the BrainpoolP512R1 curve when expressed in short Weierstrass form (y^3 = x^2 + a*x + b). More...
 
const PKA_EccParam512 BrainpoolP512R1_order
 Order of the BrainpoolP512R1 curve. More...
 
const PKA_EccPoint256 Curve25519_generator
 X coordinate of the generator point of the Curve25519 curve. More...
 
const PKA_EccParam256 Curve25519_prime
 Prime of the Curve25519 curve. More...
 
const PKA_EccParam256 Curve25519_a
 a constant of the Curve25519 curve when expressed in Montgomery form (By^2 = x^3 + a*x^2 + x). More...
 
const PKA_EccParam256 Curve25519_b
 b constant of the Curve25519 curve when expressed in Montgomery form (By^2 = x^3 + a*x^2 + x). More...
 
const PKA_EccParam256 Curve25519_order
 Order of the Curve25519 curve. More...
 

Detailed Description

Introduction

The PKA (Public Key Accelerator) API provides access to the Large Number Engine (LNME). The LNME allows for efficient math operations on numbers larger than those that fit within the ALU of the system CPU. It is significantly faster to perform these operations using the LNME than implementing the same functionality in software using regular word-wise math operations. While the LNME runs in the background, the system CPU may perform other operations or be turned off.

The LNME supports both primitive math operations and serialized primitive operations (sequencer operations).

These primitives and sequencer operations can be used to implement various public key encryption schemes. It is possible to implement the following schemes using the operations mentioned above:

The DriverLib PKA functions copy the relevant parameters into the dedicated PKA RAM. The LNME requires these parameters be present and correctly formatted in the PKA RAM and not system RAM. They are copied word-wise as the PKA RAM does not support byte-wise access. The CPU handles the alignment differences during the memory copy operation. Forcing buffer alignment in system RAM results in a significant speedup of the copy operation compared to unaligned buffers.

When the operation completes, the result is copied back into a buffer in system RAM specified by the application. The PKA RAM is then cleared to prevent sensitive keying material from remaining in PKA RAM.

Function Documentation

bool PKAArrayAllZeros ( const uint8_t *  array,
uint32_t  arrayLength 
)

Checks whether and array only consists of zeros.

Parameters
[in]arrayis the array to check.
[in]arrayLengthis the length of the array.
Returns
Returns true if the array contains only zeros and false if one or more bits are set.
897 {
898  uint32_t i;
899  uint8_t arrayBits = 0;
900 
901  // We could speed things up by comparing word-wise rather than byte-wise.
902  // However, this extra overhead is inconsequential compared to running an
903  // actual PKA operation. Especially ECC operations.
904  for (i = 0; i < arrayLength; i++) {
905  arrayBits |= array[i];
906  }
907 
908  if (arrayBits) {
909  return false;
910  }
911  else {
912  return true;
913  }
914 
915 }
uint32_t PKABigNumAddGetResult ( uint8_t *  resultBuf,
uint32_t *  resultLength,
uint32_t  resultPKAMemAddr 
)

Gets the result of the addition operation on two big numbers.

Parameters
[out]resultBufis the pointer to buffer where the result needs to be stored.
[in,out]resultLengthis the address of the variable containing the length of the buffer. After the operation the actual length of the resultant is stored at this address.
[in]resultPKAMemAddris the address of the result location which was provided by the start function PKABigNumAddStart().
Returns
Returns a status code.
See also
PKABigNumAddStart()

Referenced by PKAEccVerifyPublicKeyWeierstrassStart().

1303 {
1304  return PKAGetBigNumResult(resultBuf, resultLength, resultPKAMemAddr);
1305 }
static uint32_t PKAGetBigNumResult(uint8_t *resultBuf, uint32_t *resultLength, uint32_t resultPKAMemAddr)
Definition: pka.c:658

Here is the call graph for this function:

uint32_t PKABigNumAddStart ( const uint8_t *  bigNum1,
uint32_t  bigNum1Length,
const uint8_t *  bigNum2,
uint32_t  bigNum2Length,
uint32_t *  resultPKAMemAddr 
)

Starts the addition of two big numbers.

Parameters
[in]bigNum1is the pointer to the buffer containing the first big number.
[in]bigNum1Lengthis the size of the first big number in bytes.
[in]bigNum2is the pointer to the buffer containing the second big number.
[in]bigNum2Lengthis the size of the second big number in bytes.
[out]resultPKAMemAddris the pointer to the result vector location which will be set by this function.
Returns
Returns a status code.
See also
PKABigNumAddGetResult()

Referenced by PKAEccVerifyPublicKeyWeierstrassStart().

1222 {
1223  uint32_t offset = 0;
1224 
1225  // Check for arguments.
1226  ASSERT(bigNum1);
1227  ASSERT(bigNum2);
1228  ASSERT(resultPKAMemAddr);
1229 
1230  // Make sure no operation is in progress.
1231  if (HWREG(PKA_BASE + PKA_O_FUNCTION) & PKA_FUNCTION_RUN) {
1233  }
1234 
1235  offset = PKAWritePkaParam(bigNum1, bigNum1Length, offset, PKA_O_APTR);
1236 
1237  offset = PKAWritePkaParam(bigNum2, bigNum2Length, offset, PKA_O_BPTR);
1238 
1239  // Copy the result vector address location.
1240  *resultPKAMemAddr = PKA_RAM_BASE + offset;
1241 
1242  // Load C pointer with the result location in PKA RAM.
1243  HWREG(PKA_BASE + PKA_O_CPTR) = offset >> 2;
1244 
1245  // Set the function for the add operation and start the operation.
1247 
1248  return PKA_STATUS_SUCCESS;
1249 }
static uint32_t PKAWritePkaParam(const uint8_t *param, uint32_t paramLength, uint32_t paramOffset, uint32_t ptrRegOffset)
Definition: pka.c:577
#define PKA_STATUS_OPERATION_BUSY
PKA operation is in progress.
Definition: pka.h:128
#define PKA_STATUS_SUCCESS
Success.
Definition: pka.h:120
#define ASSERT(expr)
Definition: debug.h:73

Here is the call graph for this function:

uint32_t PKABigNumCmpGetResult ( void  )

Gets the result of the comparison operation of two big numbers.

This function provides the results of the comparison of two big numbers which was started using the PKABigNumCmpStart().

Returns
Returns a status code.
See also
PKABigNumCmpStart()

Referenced by PKAEccVerifyPublicKeyWeierstrassStart().

1092 {
1093  uint32_t status;
1094 
1095  // verify that the operation is complete.
1096  if (HWREG(PKA_BASE + PKA_O_FUNCTION) & PKA_FUNCTION_RUN) {
1098  }
1099 
1100  // Check the COMPARE register.
1101  switch(HWREG(PKA_BASE + PKA_O_COMPARE)) {
1103  status = PKA_STATUS_EQUAL;
1104  break;
1105 
1107  status = PKA_STATUS_A_GREATER_THAN_B;
1108  break;
1109 
1111  status = PKA_STATUS_A_LESS_THAN_B;
1112  break;
1113 
1114  default:
1115  status = PKA_STATUS_FAILURE;
1116  break;
1117  }
1118 
1119  return status;
1120 }
#define PKA_STATUS_FAILURE
Failure.
Definition: pka.h:121
#define PKA_STATUS_EQUAL
Big number compare return status if the first big number is equal to the second.
Definition: pka.h:127
#define PKA_STATUS_OPERATION_BUSY
PKA operation is in progress.
Definition: pka.h:128
#define PKA_STATUS_A_LESS_THAN_B
Big number compare return status if the first big number is less than the second. ...
Definition: pka.h:126
#define PKA_STATUS_A_GREATER_THAN_B
Big number compare return status if the first big number is greater than the second.
Definition: pka.h:125
uint32_t PKABigNumCmpStart ( const uint8_t *  bigNum1,
const uint8_t *  bigNum2,
uint32_t  length 
)

Starts the comparison of two big numbers.

This function starts the comparison of two big numbers pointed by bigNum1 and bigNum2.

Note
bigNum1 and bigNum2 must have same size.
Parameters
[in]bigNum1is the pointer to the first big number.
[in]bigNum2is the pointer to the second big number.
[in]lengthis the size of the big numbers in bytes.
Returns
Returns a status code.
See also
PKABigNumCmpGetResult()

Referenced by PKAEccVerifyPublicKeyWeierstrassStart().

1063 {
1064  uint32_t offset = 0;
1065 
1066  // Check the arguments.
1067  ASSERT(bigNum1);
1068  ASSERT(bigNum2);
1069 
1070  // Make sure no operation is in progress.
1071  if (HWREG(PKA_BASE + PKA_O_FUNCTION) & PKA_FUNCTION_RUN) {
1073  }
1074 
1075  offset = PKAWritePkaParam(bigNum1, length, offset, PKA_O_APTR);
1076 
1077  offset = PKAWritePkaParam(bigNum2, length, offset, PKA_O_BPTR);
1078 
1079  // Set the PKA Function register for the Compare operation
1080  // and start the operation.
1082 
1083  return PKA_STATUS_SUCCESS;
1084 }
static uint32_t PKAWritePkaParam(const uint8_t *param, uint32_t paramLength, uint32_t paramOffset, uint32_t ptrRegOffset)
Definition: pka.c:577
#define PKA_STATUS_OPERATION_BUSY
PKA operation is in progress.
Definition: pka.h:128
#define PKA_STATUS_SUCCESS
Success.
Definition: pka.h:120
#define ASSERT(expr)
Definition: debug.h:73

Here is the call graph for this function:

uint32_t PKABigNumDivideGetQuotient ( uint8_t *  resultBuf,
uint32_t *  length,
uint32_t  resultQuotientMemAddr 
)

Gets the quotient of the big number divide operation.

This function gets the quotient of the big number divide operation which was previously started using the function PKABigNumDivideStart().

Parameters
[out]resultBufis the pointer to buffer where the result needs to be stored.
[in]lengthis the size of the provided buffer in bytes.
[in]resultQuotientMemAddris the address of the result location which was provided by the start function PKABigNumDivideStart().
Returns
Returns a status code.
See also
PKABigNumDivideStart()
1042 {
1043  return PKAGetBigNumResult(resultBuf, length, resultQuotientMemAddr);
1044 }
static uint32_t PKAGetBigNumResult(uint8_t *resultBuf, uint32_t *resultLength, uint32_t resultPKAMemAddr)
Definition: pka.c:658

Here is the call graph for this function:

uint32_t PKABigNumDivideGetRemainder ( uint8_t *  resultBuf,
uint32_t *  length,
uint32_t  resultRemainderMemAddr 
)

Gets the remainder of the big number divide operation.

This function gets the remainder of the big number divide operation which was previously started using the function PKABigNumDivideStart().

Parameters
[out]resultBufis the pointer to buffer where the result needs to be stored.
[in]lengthis the size of the provided buffer in bytes.
[in]resultRemainderMemAddris the address of the result location which was provided by the start function PKABigNumDivideStart().
Returns
Returns a status code.
See also
PKABigNumDivideStart()
1052 {
1053  return PKAGetBigNumResultRemainder(resultBuf, length, resultQuotientMemAddr);
1054 }
static uint32_t PKAGetBigNumResultRemainder(uint8_t *resultBuf, uint32_t *resultLength, uint32_t resultPKAMemAddr)
Definition: pka.c:729

Here is the call graph for this function:

uint32_t PKABigNumDivideStart ( const uint8_t *  dividend,
uint32_t  dividendLength,
const uint8_t *  divisor,
uint32_t  divisorLength,
uint32_t *  resultQuotientMemAddr,
uint32_t *  resultRemainderMemAddr 
)

Starts a big number divide operation.

This function starts the dive operation on the big number bigNum using the divisor. The PKA RAM location where the result will be available is stored in resultPKAMemAddr.

Parameters
[in]dividendis the pointer to the big number to be divided.
[in]dividendLengthis the size of the big number dividend in bytes.
[in]divisoris the pointer to the divisor.
[in]divisorLengthis the size of the divisor in bytes.
[out]resultQuotientMemAddris the pointer to the quotient vector location which will be set by this function.
[out]resultRemainderMemAddris the pointer to the remainder vector location which will be set by this function.
Returns
Returns a status code.
See also
PKABigNumDivideGetResult()
996 {
997  uint32_t offset = 0;
998 
999  // Check the arguments.
1000  ASSERT(dividend);
1001  ASSERT(divisor);
1002  ASSERT(resultPKAMemAddr);
1003 
1004  // Make sure no operation is in progress.
1005  if (HWREG(PKA_BASE + PKA_O_FUNCTION) & PKA_FUNCTION_RUN) {
1007  }
1008 
1009  offset = PKAWritePkaParam(dividend, dividendLength, offset, PKA_O_APTR);
1010 
1011  offset = PKAWritePkaParamExtraOffset(divisor, divisorLength, offset, PKA_O_BPTR);
1012 
1013  // Copy the remainder result vector address location.
1014  if (resultRemainderMemAddr) {
1015  *resultRemainderMemAddr = PKA_RAM_BASE + offset;
1016  }
1017 
1018  // The remainder cannot ever be larger than the divisor. It should fit inside
1019  // a buffer of that size.
1020  offset = PKAWritePkaParamExtraOffset(0, divisorLength, offset, PKA_O_CPTR);
1021 
1022  // Copy the remainder result vector address location.
1023  if (resultQuotientMemAddr) {
1024  *resultQuotientMemAddr = PKA_RAM_BASE + offset;
1025  }
1026 
1027  // Load D pointer with the quotient location in PKA RAM
1028  HWREG(PKA_BASE + PKA_O_DPTR) = offset >> 2;
1029 
1030  // Start the PKCP modulo operation by setting the PKA Function register.
1032 
1033  return PKA_STATUS_SUCCESS;
1034 }
static uint32_t PKAWritePkaParam(const uint8_t *param, uint32_t paramLength, uint32_t paramOffset, uint32_t ptrRegOffset)
Definition: pka.c:577
#define PKA_STATUS_OPERATION_BUSY
PKA operation is in progress.
Definition: pka.h:128
#define PKA_STATUS_SUCCESS
Success.
Definition: pka.h:120
static uint32_t PKAWritePkaParamExtraOffset(const uint8_t *param, uint32_t paramLength, uint32_t paramOffset, uint32_t ptrRegOffset)
Definition: pka.c:647
#define ASSERT(expr)
Definition: debug.h:73

Here is the call graph for this function:

uint32_t PKABigNumInvModGetResult ( uint8_t *  resultBuf,
uint32_t  length,
uint32_t  resultPKAMemAddr 
)

Gets the result of the big number inverse modulo operation.

This function gets the result of the big number inverse modulo operation previously started using the function PKABigNumInvModStart(). The function will zero-out resultBuf prior to copying in the result of the inverse modulo operation.

Parameters
[out]resultBufis the pointer to buffer where the result needs to be stored.
[in]lengthis the size of the provided buffer in bytes.
[in]resultPKAMemAddris the address of the result location which was provided by the start function PKABigNumInvModStart().
Returns
Returns a status code.
See also
PKABigNumInvModStart()
1163 {
1164  // Zero-out array in case modulo result is shorter than length
1165  PKAZeroOutArray(resultBuf, length);
1166 
1167  return PKAGetBigNumResult(resultBuf, &length, resultPKAMemAddr);
1168 }
static uint32_t PKAGetBigNumResult(uint8_t *resultBuf, uint32_t *resultLength, uint32_t resultPKAMemAddr)
Definition: pka.c:658
void PKAZeroOutArray(const uint8_t *array, uint32_t arrayLength)
Zeros-out an array.
Definition: pka.c:922

Here is the call graph for this function:

uint32_t PKABigNumInvModStart ( const uint8_t *  bigNum,
uint32_t  bigNumLength,
const uint8_t *  modulus,
uint32_t  modulusLength,
uint32_t *  resultPKAMemAddr 
)

Starts a big number inverse modulo operation.

This function starts the inverse modulo operation on bigNum using the divisor modulus.

Parameters
[in]bigNumis the pointer to the buffer containing the big number (dividend).
[in]bigNumLengthis the size of the bigNum in bytes.
[in]modulusis the pointer to the buffer containing the divisor.
[in]modulusLengthis the size of the divisor in bytes.
[out]resultPKAMemAddris the pointer to the result vector location which will be set by this function.
Returns
Returns a status code.
See also
PKABigNumInvModGetResult()
1128 {
1129  uint32_t offset = 0;
1130 
1131  // Check the arguments.
1132  ASSERT(bigNum);
1133  ASSERT(modulus);
1134  ASSERT(resultPKAMemAddr);
1135 
1136  // Make sure no operation is in progress.
1137  if (HWREG(PKA_BASE + PKA_O_FUNCTION) & PKA_FUNCTION_RUN) {
1139  }
1140 
1141  offset = PKAWritePkaParam(bigNum, bigNumLength, offset, PKA_O_APTR);
1142 
1143  offset = PKAWritePkaParam(modulus, modulusLength, offset, PKA_O_BPTR);
1144 
1145  // Copy the result vector address location.
1146  *resultPKAMemAddr = PKA_RAM_BASE + offset;
1147 
1148  // Load D pointer with the result location in PKA RAM.
1149  HWREG(PKA_BASE + PKA_O_DPTR) = offset >> 2;
1150 
1151  // set the PKA function to InvMod operation and the start the operation.
1152  HWREG(PKA_BASE + PKA_O_FUNCTION) = 0x0000F000;
1153 
1154  return PKA_STATUS_SUCCESS;
1155 }
static uint32_t PKAWritePkaParam(const uint8_t *param, uint32_t paramLength, uint32_t paramOffset, uint32_t ptrRegOffset)
Definition: pka.c:577
#define PKA_STATUS_OPERATION_BUSY
PKA operation is in progress.
Definition: pka.h:128
#define PKA_STATUS_SUCCESS
Success.
Definition: pka.h:120
#define ASSERT(expr)
Definition: debug.h:73

Here is the call graph for this function:

uint32_t PKABigNumModGetResult ( uint8_t *  resultBuf,
uint32_t  length,
uint32_t  resultPKAMemAddr 
)

Gets the result of the big number modulus operation.

This function gets the result of the big number modulus operation which was previously started using the function PKABigNumModStart(). The function will zero-out resultBuf prior to copying in the result of the modulo operation.

Parameters
[out]resultBufis the pointer to buffer where the result needs to be stored.
[in]lengthis the size of the provided buffer in bytes.
[in]resultPKAMemAddris the address of the result location which was provided by the start function PKABigNumModStart().
Returns
Returns a status code.
See also
PKABigNumModStart()

Referenced by PKAEccVerifyPublicKeyWeierstrassStart().

983 {
984  // Zero-out array in case modulo result is shorter than length
985  PKAZeroOutArray(resultBuf, length);
986 
987  return PKAGetBigNumResultRemainder(resultBuf, &length, resultPKAMemAddr);
988 }
static uint32_t PKAGetBigNumResultRemainder(uint8_t *resultBuf, uint32_t *resultLength, uint32_t resultPKAMemAddr)
Definition: pka.c:729
void PKAZeroOutArray(const uint8_t *array, uint32_t arrayLength)
Zeros-out an array.
Definition: pka.c:922

Here is the call graph for this function:

uint32_t PKABigNumModStart ( const uint8_t *  bigNum,
uint32_t  bigNumLength,
const uint8_t *  modulus,
uint32_t  modulusLength,
uint32_t *  resultPKAMemAddr 
)

Starts a big number modulus operation.

This function starts the modulo operation on the big number bigNum using the divisor modulus. The PKA RAM location where the result will be available is stored in resultPKAMemAddr.

Parameters
[in]bigNumis the pointer to the big number on which modulo operation needs to be carried out.
[in]bigNumLengthis the size of the big number bigNum in bytes.
[in]modulusis the pointer to the divisor.
[in]modulusLengthis the size of the divisor modulus in bytes.
[out]resultPKAMemAddris the pointer to the result vector location which will be set by this function.
Returns
Returns a status code.
See also
PKABigNumModGetResult()

Referenced by PKAEccVerifyPublicKeyWeierstrassStart().

948 {
949  uint32_t offset = 0;
950 
951  // Check the arguments.
952  ASSERT(bigNum);
953  ASSERT(modulus);
954  ASSERT(resultPKAMemAddr);
955 
956  // Make sure no operation is in progress.
957  if (HWREG(PKA_BASE + PKA_O_FUNCTION) & PKA_FUNCTION_RUN) {
959  }
960 
961  offset = PKAWritePkaParam(bigNum, bigNumLength, offset, PKA_O_APTR);
962 
963  offset = PKAWritePkaParamExtraOffset(modulus, modulusLength, offset, PKA_O_BPTR);
964 
965  // Copy the result vector address location.
966  *resultPKAMemAddr = PKA_RAM_BASE + offset;
967 
968  // Load C pointer with the result location in PKA RAM
969  HWREG(PKA_BASE + PKA_O_CPTR) = offset >> 2;
970 
971  // Start the PKCP modulo operation by setting the PKA Function register.
973 
974  return PKA_STATUS_SUCCESS;
975 }
static uint32_t PKAWritePkaParam(const uint8_t *param, uint32_t paramLength, uint32_t paramOffset, uint32_t ptrRegOffset)
Definition: pka.c:577
#define PKA_STATUS_OPERATION_BUSY
PKA operation is in progress.
Definition: pka.h:128
#define PKA_STATUS_SUCCESS
Success.
Definition: pka.h:120
static uint32_t PKAWritePkaParamExtraOffset(const uint8_t *param, uint32_t paramLength, uint32_t paramOffset, uint32_t ptrRegOffset)
Definition: pka.c:647
#define ASSERT(expr)
Definition: debug.h:73

Here is the call graph for this function:

uint32_t PKABigNumMultGetResult ( uint8_t *  resultBuf,
uint32_t *  resultLength,
uint32_t  resultPKAMemAddr 
)

Gets the result of the big number multiplication.

This function gets the result of the multiplication of two big numbers operation previously started using the function PKABigNumMultiplyStart().

Parameters
[out]resultBufis the pointer to buffer where the result needs to be stored.
[in,out]resultLengthis the address of the variable containing the length of the buffer in bytes. After the operation, the actual length of the resultant is stored at this address.
[in]resultPKAMemAddris the address of the result location which was provided by the start function PKABigNumMultiplyStart().
Returns
Returns a status code.
See also
PKABigNumMultiplyStart()

Referenced by PKAEccVerifyPublicKeyWeierstrassStart().

1212 {
1213  return PKAGetBigNumResult(resultBuf, resultLength, resultPKAMemAddr);
1214 }
static uint32_t PKAGetBigNumResult(uint8_t *resultBuf, uint32_t *resultLength, uint32_t resultPKAMemAddr)
Definition: pka.c:658

Here is the call graph for this function:

uint32_t PKABigNumMultiplyStart ( const uint8_t *  multiplicand,
uint32_t  multiplicandLength,
const uint8_t *  multiplier,
uint32_t  multiplierLength,
uint32_t *  resultPKAMemAddr 
)

Starts the multiplication of two big numbers.

Parameters
[in]multiplicandis the pointer to the buffer containing the big number multiplicand.
[in]multiplicandLengthis the size of the multiplicand in bytes.
[in]multiplieris the pointer to the buffer containing the big number multiplier.
[in]multiplierLengthis the size of the multiplier in bytes.
[out]resultPKAMemAddris the pointer to the result vector location which will be set by this function.
Returns
Returns a status code.
See also
PKABigNumMultGetResult()

Referenced by PKAEccVerifyPublicKeyWeierstrassStart().

1176 {
1177  uint32_t offset = 0;
1178 
1179  // Check for the arguments.
1180  ASSERT(multiplicand);
1181  ASSERT(multiplier);
1182  ASSERT(resultPKAMemAddr);
1183 
1184  // Make sure no operation is in progress.
1185  if (HWREG(PKA_BASE + PKA_O_FUNCTION) & PKA_FUNCTION_RUN) {
1187  }
1188 
1189  offset = PKAWritePkaParam(multiplicand, multiplicandLength, offset, PKA_O_APTR);
1190 
1191  offset = PKAWritePkaParam(multiplier, multiplierLength, offset, PKA_O_BPTR);
1192 
1193 
1194  // Copy the result vector address location.
1195  *resultPKAMemAddr = PKA_RAM_BASE + offset;
1196 
1197  // Load C pointer with the result location in PKA RAM.
1198  HWREG(PKA_BASE + PKA_O_CPTR) = offset >> 2;
1199 
1200  // Set the PKA function to the multiplication and start it.
1202 
1203  return PKA_STATUS_SUCCESS;
1204 }
static uint32_t PKAWritePkaParam(const uint8_t *param, uint32_t paramLength, uint32_t paramOffset, uint32_t ptrRegOffset)
Definition: pka.c:577
#define PKA_STATUS_OPERATION_BUSY
PKA operation is in progress.
Definition: pka.h:128
#define PKA_STATUS_SUCCESS
Success.
Definition: pka.h:120
#define ASSERT(expr)
Definition: debug.h:73

Here is the call graph for this function:

uint32_t PKABigNumSubGetResult ( uint8_t *  resultBuf,
uint32_t *  resultLength,
uint32_t  resultPKAMemAddr 
)

Gets the result of the subtraction operation on two big numbers.

Parameters
[out]resultBufis the pointer to buffer where the result needs to be stored.
[in,out]resultLengthis the address of the variable containing the length of the buffer. After the operation the actual length of the resultant is stored at this address.
[in]resultPKAMemAddris the address of the result location which was provided by the start function PKABigNumAddStart().
Returns
Returns a status code.
See also
PKABigNumSubStart()
1257 {
1258  return PKAGetBigNumResult(resultBuf, resultLength, resultPKAMemAddr);
1259 }
static uint32_t PKAGetBigNumResult(uint8_t *resultBuf, uint32_t *resultLength, uint32_t resultPKAMemAddr)
Definition: pka.c:658

Here is the call graph for this function:

uint32_t PKABigNumSubStart ( const uint8_t *  minuend,
uint32_t  minuendLength,
const uint8_t *  subtrahend,
uint32_t  subtrahendLength,
uint32_t *  resultPKAMemAddr 
)

Starts the subtraction of one big number from another.

Parameters
[in]minuendis the pointer to the buffer containing the big number to be subtracted from.
[in]minuendLengthis the size of the minuend in bytes.
[in]subtrahendis the pointer to the buffer containing the big number to subtract from the minuend.
[in]subtrahendLengthis the size of the subtrahend in bytes.
[out]resultPKAMemAddris the pointer to the result vector location which will be set by this function.
Returns
Returns a status code.
See also
PKABigNumSubGetResult()
1267 {
1268  uint32_t offset = 0;
1269 
1270  // Check for arguments.
1271  ASSERT(minuend);
1272  ASSERT(subtrahend);
1273  ASSERT(resultPKAMemAddr);
1274 
1275 
1276  // Make sure no operation is in progress.
1277  if (HWREG(PKA_BASE + PKA_O_FUNCTION) & PKA_FUNCTION_RUN) {
1279  }
1280 
1281  offset = PKAWritePkaParam(minuend, minuendLength, offset, PKA_O_APTR);
1282 
1283  offset = PKAWritePkaParam(subtrahend, subtrahendLength, offset, PKA_O_BPTR);
1284 
1285  // Copy the result vector address location.
1286  *resultPKAMemAddr = PKA_RAM_BASE + offset;
1287 
1288  // Load C pointer with the result location in PKA RAM.
1289  HWREG(PKA_BASE + PKA_O_CPTR) = offset >> 2;
1290 
1291  // Set the function for the add operation and start the operation.
1293 
1294  return PKA_STATUS_SUCCESS;
1295 }
static uint32_t PKAWritePkaParam(const uint8_t *param, uint32_t paramLength, uint32_t paramOffset, uint32_t ptrRegOffset)
Definition: pka.c:577
#define PKA_STATUS_OPERATION_BUSY
PKA operation is in progress.
Definition: pka.h:128
#define PKA_STATUS_SUCCESS
Success.
Definition: pka.h:120
#define ASSERT(expr)
Definition: debug.h:73

Here is the call graph for this function:

uint32_t PKAEccAddGetResult ( uint8_t *  curvePointX,
uint8_t *  curvePointY,
uint32_t  resultPKAMemAddr,
uint32_t  length 
)

Gets the result of the ECC addition.

This function gets the result of ECC point addition operation on the on the two given EC points, previously started using the function PKAEccAddStart().

Parameters
[out]curvePointXis the pointer to the structure where the X coordinate of the resultant EC point will be stored.
[out]curvePointYis the pointer to the structure where the Y coordinate of the resultant EC point will be stored.
[in]resultPKAMemAddris the address of the result location which was provided by the start function PKAEccAddGetResult().
[in]lengthis the length of the curve parameters in bytes.
Returns
Returns a status code.
See also
PKAEccAddStart()
1461 {
1462  return PKAGetECCResult(curvePointX, curvePointY, resultPKAMemAddr, length);
1463 }
static uint32_t PKAGetECCResult(uint8_t *curvePointX, uint8_t *curvePointY, uint32_t resultPKAMemAddr, uint32_t length)
Definition: pka.c:792

Here is the call graph for this function:

uint32_t PKAEccAddStart ( const uint8_t *  curvePoint1X,
const uint8_t *  curvePoint1Y,
const uint8_t *  curvePoint2X,
const uint8_t *  curvePoint2Y,
const uint8_t *  prime,
const uint8_t *  a,
uint32_t  length,
uint32_t *  resultPKAMemAddr 
)

Starts the ECC addition.

Parameters
[in]curvePoint1Xis the pointer to the buffer containing the X coordinate of the first elliptic curve point to be added. The point must be on the given curve.
[in]curvePoint1Yis the pointer to the buffer containing the Y coordinate of the first elliptic curve point to be added. The point must be on the given curve.
[in]curvePoint2Xis the pointer to the buffer containing the X coordinate of the second elliptic curve point to be added. The point must be on the given curve.
[in]curvePoint2Yis the pointer to the buffer containing the Y coordinate of the second elliptic curve point to be added. The point must be on the given curve.
[in]primeis the prime of the curve.
[in]ais the a constant of the curve when the curve equation is expressed in short Weierstrass form (y^3 = x^2 + a*x + b).
[in]lengthis the length of the curve parameters in bytes.
[out]resultPKAMemAddris the pointer to the result vector location which will be set by this function.
Returns
Returns a status code.
See also
PKAEccAddGetResult()
1416 {
1417  uint32_t offset = 0;
1418 
1419  // Check for the arguments.
1420  ASSERT(curvePoint1X);
1421  ASSERT(curvePoint1Y);
1422  ASSERT(curvePoint2X);
1423  ASSERT(curvePoint2Y);
1424  ASSERT(prime);
1425  ASSERT(a);
1426  ASSERT(resultPKAMemAddr);
1427 
1428  // Make sure no operation is in progress.
1429  if (HWREG(PKA_BASE + PKA_O_FUNCTION) & PKA_FUNCTION_RUN) {
1431  }
1432 
1433  offset = PKAWritePkaParamExtraOffset(curvePoint1X, length, offset, PKA_O_APTR);
1434  offset = PKAWritePkaParamExtraOffset(curvePoint1Y, length, offset, PKA_NO_POINTER_REG);
1435 
1436 
1437  offset = PKAWritePkaParamExtraOffset(prime, length, offset, PKA_O_BPTR);
1438  offset = PKAWritePkaParamExtraOffset(a, length, offset, PKA_NO_POINTER_REG);
1439 
1440  offset = PKAWritePkaParamExtraOffset(curvePoint2X, length, offset, PKA_O_CPTR);
1441  offset = PKAWritePkaParamExtraOffset(curvePoint2Y, length, offset, PKA_NO_POINTER_REG);
1442 
1443  // Copy the result vector location.
1444  *resultPKAMemAddr = PKA_RAM_BASE + offset;
1445 
1446  // Load D pointer with the result location in PKA RAM.
1447  HWREG(PKA_BASE + PKA_O_DPTR) = offset >> 2;
1448 
1449  // Set the PKA Function to ECC-ADD and start the operation.
1451 
1452  return PKA_STATUS_SUCCESS;
1453 }
#define PKA_STATUS_OPERATION_BUSY
PKA operation is in progress.
Definition: pka.h:128
#define PKA_STATUS_SUCCESS
Success.
Definition: pka.h:120
static uint32_t PKAWritePkaParamExtraOffset(const uint8_t *param, uint32_t paramLength, uint32_t paramOffset, uint32_t ptrRegOffset)
Definition: pka.c:647
#define ASSERT(expr)
Definition: debug.h:73
#define PKA_NO_POINTER_REG
Definition: pka.c:186

Here is the call graph for this function:

uint32_t PKAEccMontgomeryMultiplyStart ( const uint8_t *  scalar,
const uint8_t *  curvePointX,
const uint8_t *  prime,
const uint8_t *  a,
uint32_t  length,
uint32_t *  resultPKAMemAddr 
)

Starts ECC Montgomery multiplication.

Parameters
[in]scalaris pointer to the buffer containing the scalar value to be multiplied.
[in]curvePointXis the pointer to the buffer containing the X coordinate of the elliptic curve point to be multiplied. The point must be on the given curve.
[in]primeis the prime of the curve.
[in]ais the a constant of the curve when the curve equation is expressed in short Weierstrass form (y^3 = x^2 + a*x + b).
[in]lengthis the length of the curve parameters in bytes.
[out]resultPKAMemAddris the pointer to the result vector location which will be set by this function.
Returns
Returns a status code.
See also
PKAEccMultiplyGetResult()
1362 {
1363  uint32_t offset = 0;
1364 
1365  // Check for the arguments.
1366  ASSERT(scalar);
1367  ASSERT(curvePointX);
1368  ASSERT(curve);
1369  ASSERT(length <= PKA_MAX_CURVE_SIZE_32_BIT_WORD * sizeof(uint32_t));
1370  ASSERT(resultPKAMemAddr);
1371 
1372  // Make sure no PKA operation is in progress.
1373  if (HWREG(PKA_BASE + PKA_O_FUNCTION) & PKA_FUNCTION_RUN) {
1375  }
1376 
1377  offset = PKAWritePkaParam(scalar, length, offset, PKA_O_APTR);
1378 
1379  offset = PKAWritePkaParamExtraOffset(prime, length, offset, PKA_O_BPTR);
1380  offset = PKAWritePkaParamExtraOffset(a, length, offset, PKA_NO_POINTER_REG);
1381 
1382  offset = PKAWritePkaParamExtraOffset(curvePointX, length, offset, PKA_O_CPTR);
1383 
1384  // Update the result location.
1385  // The resultPKAMemAddr may be 0 if we only want to check that we generated the point at infinity
1386  if (resultPKAMemAddr) {
1387  *resultPKAMemAddr = PKA_RAM_BASE + offset;
1388  }
1389 
1390  // Load D pointer with the result location in PKA RAM.
1391  HWREG(PKA_BASE + PKA_O_DPTR) = offset >> 2;
1392 
1393  // Set the PKA function to Montgomery ECC-MULT and start the operation.
1395 
1396  return PKA_STATUS_SUCCESS;
1397 }
static uint32_t PKAWritePkaParam(const uint8_t *param, uint32_t paramLength, uint32_t paramOffset, uint32_t ptrRegOffset)
Definition: pka.c:577
#define PKA_STATUS_OPERATION_BUSY
PKA operation is in progress.
Definition: pka.h:128
#define PKA_STATUS_SUCCESS
Success.
Definition: pka.h:120
static uint32_t PKAWritePkaParamExtraOffset(const uint8_t *param, uint32_t paramLength, uint32_t paramOffset, uint32_t ptrRegOffset)
Definition: pka.c:647
#define ASSERT(expr)
Definition: debug.h:73
#define PKA_NO_POINTER_REG
Definition: pka.c:186
#define PKA_MAX_CURVE_SIZE_32_BIT_WORD
Definition: pka.c:170

Here is the call graph for this function:

uint32_t PKAEccMultiplyGetResult ( uint8_t *  curvePointX,
uint8_t *  curvePointY,
uint32_t  resultPKAMemAddr,
uint32_t  length 
)

Gets the result of ECC multiplication.

This function gets the result of ECC point multiplication operation on the EC point and the scalar value, previously started using the function PKAEccMultiplyStart().

Parameters
[out]curvePointXis the pointer to the structure where the X coordinate of the resultant EC point will be stored.
[out]curvePointYis the pointer to the structure where the Y coordinate of the resultant EC point will be stored.
[in]resultPKAMemAddris the address of the result location which was provided by the start function PKAEccMultiplyStart().
[in]lengthis the length of the curve parameters in bytes.
Returns
Returns a status code.
See also
PKAEccMultiplyStart()
1406 {
1407  return PKAGetECCResult(curvePointX, curvePointY, resultPKAMemAddr, length);
1408 }
static uint32_t PKAGetECCResult(uint8_t *curvePointX, uint8_t *curvePointY, uint32_t resultPKAMemAddr, uint32_t length)
Definition: pka.c:792

Here is the call graph for this function:

uint32_t PKAEccMultiplyStart ( const uint8_t *  scalar,
const uint8_t *  curvePointX,
const uint8_t *  curvePointY,
const uint8_t *  prime,
const uint8_t *  a,
const uint8_t *  b,
uint32_t  length,
uint32_t *  resultPKAMemAddr 
)

Starts ECC multiplication.

Parameters
[in]scalaris pointer to the buffer containing the scalar value to be multiplied.
[in]curvePointXis the pointer to the buffer containing the X coordinate of the elliptic curve point to be multiplied. The point must be on the given curve.
[in]curvePointYis the pointer to the buffer containing the Y coordinate of the elliptic curve point to be multiplied. The point must be on the given curve.
[in]primeis the prime of the curve.
[in]ais the a constant of the curve when the curve equation is expressed in short Weierstrass form (y^3 = x^2 + a*x + b).
[in]bis the b constant of the curve when the curve equation is expressed in short Weierstrass form (y^3 = x^2 + a*x + b).
[in]lengthis the length of the curve parameters in bytes.
[out]resultPKAMemAddris the pointer to the result vector location which will be set by this function.
Returns
Returns a status code.
See also
PKAEccMultiplyGetResult()
1314 {
1315  uint32_t offset = 0;
1316 
1317  // Check for the arguments.
1318  ASSERT(scalar);
1319  ASSERT(curvePoint);
1320  ASSERT(curvePointX);
1321  ASSERT(curvePointY);
1322  ASSERT(curve);
1323  ASSERT(length <= PKA_MAX_CURVE_SIZE_32_BIT_WORD * sizeof(uint32_t));
1324  ASSERT(resultPKAMemAddr);
1325 
1326  // Make sure no PKA operation is in progress.
1327  if (HWREG(PKA_BASE + PKA_O_FUNCTION) & PKA_FUNCTION_RUN) {
1329  }
1330 
1331  offset = PKAWritePkaParam(scalar, length, offset, PKA_O_APTR);
1332 
1333  offset = PKAWritePkaParamExtraOffset(prime, length, offset, PKA_O_BPTR);
1334  offset = PKAWritePkaParamExtraOffset(a, length, offset, PKA_NO_POINTER_REG);
1335  offset = PKAWritePkaParamExtraOffset(b, length, offset, PKA_NO_POINTER_REG);
1336 
1337  offset = PKAWritePkaParamExtraOffset(curvePointX, length, offset, PKA_O_CPTR);
1338  offset = PKAWritePkaParamExtraOffset(curvePointY, length, offset, PKA_NO_POINTER_REG);
1339 
1340  // Update the result location.
1341  // The resultPKAMemAddr may be 0 if we only want to check that we generated the point at infinity
1342  if (resultPKAMemAddr) {
1343  *resultPKAMemAddr = PKA_RAM_BASE + offset;
1344  }
1345 
1346  // Load D pointer with the result location in PKA RAM.
1347  HWREG(PKA_BASE + PKA_O_DPTR) = offset >> 2;
1348 
1349  // Set the PKA function to ECC-MULT and start the operation.
1351 
1352  return PKA_STATUS_SUCCESS;
1353 }
static uint32_t PKAWritePkaParam(const uint8_t *param, uint32_t paramLength, uint32_t paramOffset, uint32_t ptrRegOffset)
Definition: pka.c:577
#define PKA_STATUS_OPERATION_BUSY
PKA operation is in progress.
Definition: pka.h:128
#define PKA_STATUS_SUCCESS
Success.
Definition: pka.h:120
static uint32_t PKAWritePkaParamExtraOffset(const uint8_t *param, uint32_t paramLength, uint32_t paramOffset, uint32_t ptrRegOffset)
Definition: pka.c:647
#define ASSERT(expr)
Definition: debug.h:73
#define PKA_NO_POINTER_REG
Definition: pka.c:186
#define PKA_MAX_CURVE_SIZE_32_BIT_WORD
Definition: pka.c:170

Here is the call graph for this function:

uint32_t PKAEccVerifyPublicKeyWeierstrassStart ( const uint8_t *  curvePointX,
const uint8_t *  curvePointY,
const uint8_t *  prime,
const uint8_t *  a,
const uint8_t *  b,
const uint8_t *  order,
uint32_t  length 
)

Begins the validation of a public key against a Short-Weierstrass curve.

This function validates a public key against a curve. After performing multiple smaller PKA operations in polling mode, it starts an ECC scalar multiplication.

The function verifies that:

  • X and Y are in the range [1, prime - 1]
  • The point is not the point at infinity
  • X and Y satisfy the Short-Weierstrass curve equation Y^2 = X^3 + a*X + b mod P
  • Multiplying the point by the order of the curve yields the point at infinity
Parameters
[in]curvePointXis the pointer to the buffer containing the X coordinate of the elliptic curve point to verify.
[in]curvePointYis the pointer to the buffer containing the Y coordinate of the elliptic curve point to verify.
[in]primeis the prime of the curve.
[in]ais the a constant of the curve when the curve equation is expressed in Short-Weierstrass form (y^3 = x^2 + a*x + b).
[in]bis the b constant of the curve when the curve equation is expressed in Short-Weierstrass form (y^3 = x^2 + a*x + b).
[in]orderis the order of the curve.
[in]lengthis the length of the curve parameters in bytes.
Returns
Returns a status code.
See also
PKAEccVerifyPublicKeyGetResult()
1471 {
1472  uint32_t pkaResult;
1473  uint32_t resultAddress;
1474  uint32_t resultLength;
1475  uint8_t *scratchBuffer = (uint8_t *)(PKA_RAM_BASE + PKA_RAM_TOT_BYTE_SIZE / 2);
1476  uint8_t *scratchBuffer2 = scratchBuffer + 512;
1477 
1478 
1479  // Verify X in range [0, prime - 1]
1480  PKABigNumCmpStart(curvePointX,
1481  prime,
1482  length);
1483 
1485 
1486  pkaResult = PKABigNumCmpGetResult();
1487 
1488  if (pkaResult != PKA_STATUS_A_LESS_THAN_B) {
1490  }
1491 
1492  // Verify Y in range [0, prime - 1]
1493  PKABigNumCmpStart(curvePointY,
1494  prime,
1495  length);
1496 
1498 
1499  pkaResult = PKABigNumCmpGetResult();
1500 
1501  if (pkaResult != PKA_STATUS_A_LESS_THAN_B) {
1503  }
1504 
1505  // Verify point on curve
1506  // Short-Weierstrass equation: Y ^ 2 = X ^3 + a * X + b mod P
1507  // Reduced: Y ^ 2 = X * (X ^ 2 + a) + b
1508 
1509  // tmp = X ^ 2
1510  PKABigNumMultiplyStart(curvePointX, length, curvePointX, length, &resultAddress);
1511 
1513 
1514  resultLength = 200;
1515  pkaResult = PKABigNumMultGetResult(scratchBuffer, &resultLength, resultAddress);
1516 
1517  if (pkaResult != PKA_STATUS_SUCCESS) {
1518  return PKA_STATUS_FAILURE;
1519  }
1520 
1521  // tmp += a
1522  PKABigNumAddStart(scratchBuffer, resultLength, a, length, &resultAddress);
1523 
1525 
1526  resultLength = 200;
1527  pkaResult = PKABigNumAddGetResult(scratchBuffer, &resultLength, resultAddress);
1528 
1529  if (pkaResult != PKA_STATUS_SUCCESS) {
1530  return PKA_STATUS_FAILURE;
1531  }
1532 
1533  // tmp *= x
1534  PKABigNumMultiplyStart(scratchBuffer, resultLength, curvePointX, length, &resultAddress);
1535 
1537 
1538  resultLength = 200;
1539  pkaResult = PKABigNumMultGetResult(scratchBuffer, &resultLength, resultAddress);
1540 
1541  if (pkaResult != PKA_STATUS_SUCCESS) {
1542  return PKA_STATUS_FAILURE;
1543  }
1544 
1545  // tmp += b
1546  PKABigNumAddStart(scratchBuffer, resultLength, b, length, &resultAddress);
1547 
1549 
1550  resultLength = 200;
1551  pkaResult = PKABigNumAddGetResult(scratchBuffer, &resultLength, resultAddress);
1552 
1553  if (pkaResult != PKA_STATUS_SUCCESS) {
1554  return PKA_STATUS_FAILURE;
1555  }
1556 
1557 
1558  // tmp2 = tmp % prime to ensure we have no fraction in the division.
1559  // The number will only shrink from here on out.
1560  PKABigNumModStart(scratchBuffer, resultLength, prime, length, &resultAddress);
1561 
1563 
1564  // If the result is not a multiple of the word-length, the PKA HW will round up
1565  // because it deals in words only. That means that using 'length' directly
1566  // would cause and underflow, since length refers to the actual length in bytes of
1567  // the curve parameters while the PKA HW reports that rounded up to the next
1568  // word boundary.
1569  // Use 200 as the resultLength instead since we are copying to the scratch buffer
1570  // anyway.
1571  // Practically, this only happens with curves such as NIST-P521 that are not word
1572  // multiples.
1573  resultLength = 200;
1574  pkaResult = PKABigNumModGetResult(scratchBuffer2, resultLength, resultAddress);
1575 
1576  if (pkaResult != PKA_STATUS_SUCCESS) {
1577  return PKA_STATUS_FAILURE;
1578  }
1579 
1580  // tmp = y^2
1581  PKABigNumMultiplyStart(curvePointY, length, curvePointY, length, &resultAddress);
1582 
1584 
1585  resultLength = 200;
1586  pkaResult = PKABigNumMultGetResult(scratchBuffer, &resultLength, resultAddress);
1587 
1588  if (pkaResult != PKA_STATUS_SUCCESS) {
1589  return PKA_STATUS_FAILURE;
1590  }
1591 
1592  // tmp %= prime
1593  PKABigNumModStart(scratchBuffer, resultLength, prime, length, &resultAddress);
1594 
1596 
1597  // If the result is not a multiple of the word-length, the PKA HW will round up
1598  // because it deals in words only. That means that using 'length' directly
1599  // would cause and underflow, since length refers to the actual length in bytes of
1600  // the curve parameters while the PKA HW reports that rounded up to the next
1601  // word boundary.
1602  // Use 200 as the resultLength instead since we are copying to the scratch buffer
1603  // anyway.
1604  // Practically, this only happens with curves such as NIST-P521 that are not word
1605  // multiples.
1606  resultLength = 200;
1607  pkaResult = PKABigNumModGetResult(scratchBuffer, resultLength, resultAddress);
1608 
1609  if (pkaResult != PKA_STATUS_SUCCESS) {
1610  return PKA_STATUS_FAILURE;
1611  }
1612 
1613  // tmp ?= tmp2
1614  PKABigNumCmpStart(scratchBuffer,
1615  scratchBuffer2,
1616  length);
1617 
1619 
1620  pkaResult = PKABigNumCmpGetResult();
1621 
1622  if (pkaResult != PKA_STATUS_EQUAL) {
1624  }
1625  else {
1626  return PKA_STATUS_SUCCESS;
1627  }
1628 }
#define PKA_STATUS_POINT_NOT_ON_CURVE
The public key is not on the specified elliptic curve.
Definition: pka.h:135
uint32_t PKABigNumModGetResult(uint8_t *resultBuf, uint32_t length, uint32_t resultPKAMemAddr)
Gets the result of the big number modulus operation.
Definition: pka.c:982
uint32_t PKABigNumAddGetResult(uint8_t *resultBuf, uint32_t *resultLength, uint32_t resultPKAMemAddr)
Gets the result of the addition operation on two big numbers.
Definition: pka.c:1302
uint32_t PKABigNumAddStart(const uint8_t *bigNum1, uint32_t bigNum1Length, const uint8_t *bigNum2, uint32_t bigNum2Length, uint32_t *resultPKAMemAddr)
Starts the addition of two big numbers.
Definition: pka.c:1221
uint32_t PKABigNumCmpStart(const uint8_t *bigNum1, const uint8_t *bigNum2, uint32_t length)
Starts the comparison of two big numbers.
Definition: pka.c:1062
#define PKA_STATUS_FAILURE
Failure.
Definition: pka.h:121
#define PKA_STATUS_Y_LARGER_THAN_PRIME
Y coordinate of public key is larger than the curve prime.
Definition: pka.h:134
#define PKA_STATUS_EQUAL
Big number compare return status if the first big number is equal to the second.
Definition: pka.h:127
#define PKA_STATUS_OPERATION_BUSY
PKA operation is in progress.
Definition: pka.h:128
#define PKA_STATUS_X_LARGER_THAN_PRIME
X coordinate of public key is larger than the curve prime.
Definition: pka.h:133
#define PKA_STATUS_SUCCESS
Success.
Definition: pka.h:120
uint32_t PKABigNumMultGetResult(uint8_t *resultBuf, uint32_t *resultLength, uint32_t resultPKAMemAddr)
Gets the result of the big number multiplication.
Definition: pka.c:1211
uint32_t PKABigNumModStart(const uint8_t *bigNum, uint32_t bigNumLength, const uint8_t *modulus, uint32_t modulusLength, uint32_t *resultPKAMemAddr)
Starts a big number modulus operation.
Definition: pka.c:947
uint32_t PKABigNumMultiplyStart(const uint8_t *multiplicand, uint32_t multiplicandLength, const uint8_t *multiplier, uint32_t multiplierLength, uint32_t *resultPKAMemAddr)
Starts the multiplication of two big numbers.
Definition: pka.c:1175
#define PKA_STATUS_A_LESS_THAN_B
Big number compare return status if the first big number is less than the second. ...
Definition: pka.h:126
uint32_t PKAGetOpsStatus(void)
Gets the PKA operation status.
Definition: pka.c:881
uint32_t PKABigNumCmpGetResult(void)
Gets the result of the comparison operation of two big numbers.
Definition: pka.c:1091

Here is the call graph for this function:

uint32_t PKAGetOpsStatus ( void  )

Gets the PKA operation status.

This function gets information on whether any PKA operation is in progress or not. This function allows to check the PKA operation status before starting any new PKA operation.

Returns
Returns a status code.

Referenced by PKAEccVerifyPublicKeyWeierstrassStart().

882 {
883  if (HWREG(PKA_BASE + PKA_O_FUNCTION) & PKA_FUNCTION_RUN_M) {
885  }
886  else {
888  }
889 }
#define PKA_STATUS_OPERATION_BUSY
PKA operation is in progress.
Definition: pka.h:128
#define PKA_STATUS_OPERATION_RDY
No PKA operation is in progress.
Definition: pka.h:129
void PKAZeroOutArray ( const uint8_t *  array,
uint32_t  arrayLength 
)

Zeros-out an array.

Parameters
[in]arrayis the array to zero-out.
[in]arrayLengthis the length of the array.

Referenced by PKABigNumInvModGetResult(), and PKABigNumModGetResult().

923 {
924  uint32_t i;
925  // Take the floor of paramLength in 32-bit words
926  uint32_t arrayLengthInWords = arrayLength / sizeof(uint32_t);
927 
928  // Zero-out the array word-wise until i >= arrayLength
929  for (i = 0; i < arrayLengthInWords * sizeof(uint32_t); i += 4) {
930  HWREG(array + i) = 0;
931  }
932 
933  // If i != arrayLength, there are some remaining bytes to zero-out
934  if (arrayLength % sizeof(uint32_t)) {
935  // Subtract 4 from i, since i has already overshot the array
936  for (i -= 4; i < arrayLength; i++) {
937  HWREGB(array + i * sizeof(uint32_t));
938  }
939  }
940 }

Macro Definition Documentation

#define BrainpoolP256R1_PARAM_SIZE_BYTES   32
#define BrainpoolP384R1_PARAM_SIZE_BYTES   48
#define BrainpoolP512R1_PARAM_SIZE_BYTES   64
#define Curve25519_PARAM_SIZE_BYTES   32
#define NISTP224_PARAM_SIZE_BYTES   28
#define NISTP256_PARAM_SIZE_BYTES   32
#define NISTP384_PARAM_SIZE_BYTES   48
#define NISTP521_PARAM_SIZE_BYTES   66
#define PKA_STATUS_A_GREATER_THAN_B   5

Big number compare return status if the first big number is greater than the second.

Referenced by PKABigNumCmpGetResult().

#define PKA_STATUS_A_LESS_THAN_B   6

Big number compare return status if the first big number is less than the second.

Referenced by PKABigNumCmpGetResult(), and PKAEccVerifyPublicKeyWeierstrassStart().

#define PKA_STATUS_BUF_UNDERFLOW   3

Buffer underflow.

Referenced by PKAGetBigNumResult(), and PKAGetBigNumResultRemainder().

#define PKA_STATUS_EQUAL   7

Big number compare return status if the first big number is equal to the second.

Referenced by PKABigNumCmpGetResult(), and PKAEccVerifyPublicKeyWeierstrassStart().

#define PKA_STATUS_FAILURE   1
#define PKA_STATUS_INVALID_PARAM   2

Invalid parameter.

#define PKA_STATUS_LOCATION_IN_USE   10

Location in PKA RAM is not available.

#define PKA_STATUS_OPERATION_RDY   9

No PKA operation is in progress.

Referenced by PKAGetOpsStatus().

#define PKA_STATUS_POINT_AT_INFINITY   17

The ECC operation resulted in the point at infinity.

Referenced by PKAGetECCResult().

#define PKA_STATUS_POINT_NOT_ON_CURVE   15

The public key is not on the specified elliptic curve.

Referenced by PKAEccVerifyPublicKeyWeierstrassStart().

#define PKA_STATUS_RESULT_0   4

Result is all zeros.

#define PKA_STATUS_RESULT_ADDRESS_INCORRECT   16

The address of the result passed into one of the PKA*GetResult functions is incorrect.

Referenced by PKAGetBigNumResult().

#define PKA_STATUS_X_LARGER_THAN_PRIME   13

X coordinate of public key is larger than the curve prime.

Referenced by PKAEccVerifyPublicKeyWeierstrassStart().

#define PKA_STATUS_X_ZERO   11

X coordinate of public key is 0.

#define PKA_STATUS_Y_LARGER_THAN_PRIME   14

Y coordinate of public key is larger than the curve prime.

Referenced by PKAEccVerifyPublicKeyWeierstrassStart().

#define PKA_STATUS_Y_ZERO   12

Y coordinate of public key is 0.

Variable Documentation

const PKA_EccParam256 BrainpoolP256R1_a

a constant of the BrainpoolP256R1 curve when expressed in short Weierstrass form (y^3 = x^2 + a*x + b).

const PKA_EccParam256 BrainpoolP256R1_b

b constant of the BrainpoolP256R1 curve when expressed in short Weierstrass form (y^3 = x^2 + a*x + b).

const PKA_EccPoint256 BrainpoolP256R1_generator

X coordinate of the generator point of the BrainpoolP256R1 curve.

const PKA_EccParam256 BrainpoolP256R1_order

Order of the BrainpoolP256R1 curve.

const PKA_EccParam256 BrainpoolP256R1_prime

Prime of the BrainpoolP256R1 curve.

const PKA_EccParam384 BrainpoolP384R1_a

a constant of the BrainpoolP384R1 curve when expressed in short Weierstrass form (y^3 = x^2 + a*x + b).

const PKA_EccParam384 BrainpoolP384R1_b

b constant of the BrainpoolP384R1 curve when expressed in short Weierstrass form (y^3 = x^2 + a*x + b).

const PKA_EccPoint384 BrainpoolP384R1_generator

X coordinate of the generator point of the BrainpoolP384R1 curve.

const PKA_EccParam384 BrainpoolP384R1_order

Order of the BrainpoolP384R1 curve.

const PKA_EccParam384 BrainpoolP384R1_prime

Prime of the BrainpoolP384R1 curve.

const PKA_EccParam512 BrainpoolP512R1_a

a constant of the BrainpoolP512R1 curve when expressed in short Weierstrass form (y^3 = x^2 + a*x + b).

const PKA_EccParam512 BrainpoolP512R1_b

b constant of the BrainpoolP512R1 curve when expressed in short Weierstrass form (y^3 = x^2 + a*x + b).

const PKA_EccPoint512 BrainpoolP512R1_generator

X coordinate of the generator point of the BrainpoolP512R1 curve.

const PKA_EccParam512 BrainpoolP512R1_order

Order of the BrainpoolP512R1 curve.

const PKA_EccParam512 BrainpoolP512R1_prime

Prime of the BrainpoolP512R1 curve.

const PKA_EccParam256 Curve25519_a

a constant of the Curve25519 curve when expressed in Montgomery form (By^2 = x^3 + a*x^2 + x).

const PKA_EccParam256 Curve25519_b

b constant of the Curve25519 curve when expressed in Montgomery form (By^2 = x^3 + a*x^2 + x).

const PKA_EccPoint256 Curve25519_generator

X coordinate of the generator point of the Curve25519 curve.

const PKA_EccParam256 Curve25519_order

Order of the Curve25519 curve.

const PKA_EccParam256 Curve25519_prime

Prime of the Curve25519 curve.

const PKA_EccParam224 NISTP224_a

a constant of the NISTP224 curve when expressed in short Weierstrass form (y^3 = x^2 + a*x + b).

const PKA_EccParam224 NISTP224_b

b constant of the NISTP224 curve when expressed in short Weierstrass form (y^3 = x^2 + a*x + b).

const PKA_EccPoint224 NISTP224_generator

X coordinate of the generator point of the NISTP224 curve.

const PKA_EccParam224 NISTP224_order

Order of the NISTP224 curve.

const PKA_EccParam224 NISTP224_prime

Prime of the NISTP224 curve.

const PKA_EccParam256 NISTP256_a

a constant of the NISTP256 curve when expressed in short Weierstrass form (y^3 = x^2 + a*x + b).

const PKA_EccParam256 NISTP256_b

b constant of the NISTP256 curve when expressed in short Weierstrass form (y^3 = x^2 + a*x + b).

const PKA_EccPoint256 NISTP256_generator

X coordinate of the generator point of the NISTP256 curve.

const PKA_EccParam256 NISTP256_order

Order of the NISTP256 curve.

const PKA_EccParam256 NISTP256_prime

Prime of the NISTP256 curve.

const PKA_EccParam384 NISTP384_a

a constant of the NISTP384 curve when expressed in short Weierstrass form (y^3 = x^2 + a*x + b).

const PKA_EccParam384 NISTP384_b

b constant of the NISTP384 curve when expressed in short Weierstrass form (y^3 = x^2 + a*x + b).

const PKA_EccPoint384 NISTP384_generator

X coordinate of the generator point of the NISTP384 curve.

const PKA_EccParam384 NISTP384_order

Order of the NISTP384 curve.

const PKA_EccParam384 NISTP384_prime

Prime of the NISTP384 curve.

const PKA_EccParam521 NISTP521_a

a constant of the NISTP521 curve when expressed in short Weierstrass form (y^3 = x^2 + a*x + b).

const PKA_EccParam521 NISTP521_b

b constant of the NISTP521 curve when expressed in short Weierstrass form (y^3 = x^2 + a*x + b).

const PKA_EccPoint521 NISTP521_generator

X coordinate of the generator point of the NISTP521 curve.

const PKA_EccParam521 NISTP521_order

Order of the NISTP521 curve.

const PKA_EccParam521 NISTP521_prime

Prime of the NISTP521 curve.