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.
900 {
901  uint32_t i;
902  uint8_t arrayBits = 0;
903 
904  // We could speed things up by comparing word-wise rather than byte-wise.
905  // However, this extra overhead is inconsequential compared to running an
906  // actual PKA operation. Especially ECC operations.
907  for (i = 0; i < arrayLength; i++) {
908  arrayBits |= array[i];
909  }
910 
911  if (arrayBits) {
912  return false;
913  }
914  else {
915  return true;
916  }
917 
918 }
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().

1307 {
1308  return PKAGetBigNumResult(resultBuf, resultLength, resultPKAMemAddr);
1309 }
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().

1226 {
1227  uint32_t offset = 0;
1228 
1229  // Check for arguments.
1230  ASSERT(bigNum1);
1231  ASSERT(bigNum2);
1232  ASSERT(resultPKAMemAddr);
1233 
1234  // Make sure no operation is in progress.
1235  if (HWREG(PKA_BASE + PKA_O_FUNCTION) & PKA_FUNCTION_RUN) {
1237  }
1238 
1239  offset = PKAWritePkaParam(bigNum1, bigNum1Length, offset, PKA_O_APTR);
1240 
1241  offset = PKAWritePkaParam(bigNum2, bigNum2Length, offset, PKA_O_BPTR);
1242 
1243  // Copy the result vector address location.
1244  *resultPKAMemAddr = PKA_RAM_BASE + offset;
1245 
1246  // Load C pointer with the result location in PKA RAM.
1247  HWREG(PKA_BASE + PKA_O_CPTR) = offset >> 2;
1248 
1249  // Set the function for the add operation and start the operation.
1251 
1252  return PKA_STATUS_SUCCESS;
1253 }
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().

1096 {
1097  uint32_t status;
1098 
1099  // verify that the operation is complete.
1100  if (HWREG(PKA_BASE + PKA_O_FUNCTION) & PKA_FUNCTION_RUN) {
1102  }
1103 
1104  // Check the COMPARE register.
1105  switch(HWREG(PKA_BASE + PKA_O_COMPARE)) {
1107  status = PKA_STATUS_EQUAL;
1108  break;
1109 
1111  status = PKA_STATUS_A_GREATER_THAN_B;
1112  break;
1113 
1115  status = PKA_STATUS_A_LESS_THAN_B;
1116  break;
1117 
1118  default:
1119  status = PKA_STATUS_FAILURE;
1120  break;
1121  }
1122 
1123  return status;
1124 }
#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().

1067 {
1068  uint32_t offset = 0;
1069 
1070  // Check the arguments.
1071  ASSERT(bigNum1);
1072  ASSERT(bigNum2);
1073 
1074  // Make sure no operation is in progress.
1075  if (HWREG(PKA_BASE + PKA_O_FUNCTION) & PKA_FUNCTION_RUN) {
1077  }
1078 
1079  offset = PKAWritePkaParam(bigNum1, length, offset, PKA_O_APTR);
1080 
1081  offset = PKAWritePkaParam(bigNum2, length, offset, PKA_O_BPTR);
1082 
1083  // Set the PKA Function register for the Compare operation
1084  // and start the operation.
1086 
1087  return PKA_STATUS_SUCCESS;
1088 }
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()
1046 {
1047  return PKAGetBigNumResult(resultBuf, length, resultQuotientMemAddr);
1048 }
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()
1056 {
1057  return PKAGetBigNumResultRemainder(resultBuf, length, resultQuotientMemAddr);
1058 }
static uint32_t PKAGetBigNumResultRemainder(uint8_t *resultBuf, uint32_t *resultLength, uint32_t resultPKAMemAddr)
Definition: pka.c:732

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()
999 {
1000  uint32_t offset = 0;
1001 
1002  // Check the arguments.
1003  ASSERT(dividend);
1004  ASSERT(divisor);
1005  ASSERT(resultQuotientMemAddr);
1006  ASSERT(resultRemainderMemAddr);
1007 
1008  // Make sure no operation is in progress.
1009  if (HWREG(PKA_BASE + PKA_O_FUNCTION) & PKA_FUNCTION_RUN) {
1011  }
1012 
1013  offset = PKAWritePkaParam(dividend, dividendLength, offset, PKA_O_APTR);
1014 
1015  offset = PKAWritePkaParamExtraOffset(divisor, divisorLength, offset, PKA_O_BPTR);
1016 
1017  // Copy the remainder result vector address location.
1018  if (resultRemainderMemAddr) {
1019  *resultRemainderMemAddr = PKA_RAM_BASE + offset;
1020  }
1021 
1022  // The remainder cannot ever be larger than the divisor. It should fit inside
1023  // a buffer of that size.
1024  offset = PKAWritePkaParamExtraOffset(0, divisorLength, offset, PKA_O_CPTR);
1025 
1026  // Copy the remainder result vector address location.
1027  if (resultQuotientMemAddr) {
1028  *resultQuotientMemAddr = PKA_RAM_BASE + offset;
1029  }
1030 
1031  // Load D pointer with the quotient location in PKA RAM
1032  HWREG(PKA_BASE + PKA_O_DPTR) = offset >> 2;
1033 
1034  // Start the PKCP modulo operation by setting the PKA Function register.
1036 
1037  return PKA_STATUS_SUCCESS;
1038 }
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()
1167 {
1168  // Zero-out array in case modulo result is shorter than length
1169  PKAZeroOutArray(resultBuf, length);
1170 
1171  return PKAGetBigNumResult(resultBuf, &length, resultPKAMemAddr);
1172 }
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:925

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()
1132 {
1133  uint32_t offset = 0;
1134 
1135  // Check the arguments.
1136  ASSERT(bigNum);
1137  ASSERT(modulus);
1138  ASSERT(resultPKAMemAddr);
1139 
1140  // Make sure no operation is in progress.
1141  if (HWREG(PKA_BASE + PKA_O_FUNCTION) & PKA_FUNCTION_RUN) {
1143  }
1144 
1145  offset = PKAWritePkaParam(bigNum, bigNumLength, offset, PKA_O_APTR);
1146 
1147  offset = PKAWritePkaParam(modulus, modulusLength, offset, PKA_O_BPTR);
1148 
1149  // Copy the result vector address location.
1150  *resultPKAMemAddr = PKA_RAM_BASE + offset;
1151 
1152  // Load D pointer with the result location in PKA RAM.
1153  HWREG(PKA_BASE + PKA_O_DPTR) = offset >> 2;
1154 
1155  // set the PKA function to InvMod operation and the start the operation.
1156  HWREG(PKA_BASE + PKA_O_FUNCTION) = 0x0000F000;
1157 
1158  return PKA_STATUS_SUCCESS;
1159 }
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().

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

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().

951 {
952  uint32_t offset = 0;
953 
954  // Check the arguments.
955  ASSERT(bigNum);
956  ASSERT(modulus);
957  ASSERT(resultPKAMemAddr);
958 
959  // Make sure no operation is in progress.
960  if (HWREG(PKA_BASE + PKA_O_FUNCTION) & PKA_FUNCTION_RUN) {
962  }
963 
964  offset = PKAWritePkaParam(bigNum, bigNumLength, offset, PKA_O_APTR);
965 
966  offset = PKAWritePkaParamExtraOffset(modulus, modulusLength, offset, PKA_O_BPTR);
967 
968  // Copy the result vector address location.
969  *resultPKAMemAddr = PKA_RAM_BASE + offset;
970 
971  // Load C pointer with the result location in PKA RAM
972  HWREG(PKA_BASE + PKA_O_CPTR) = offset >> 2;
973 
974  // Start the PKCP modulo operation by setting the PKA Function register.
976 
977  return PKA_STATUS_SUCCESS;
978 }
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().

1216 {
1217  return PKAGetBigNumResult(resultBuf, resultLength, resultPKAMemAddr);
1218 }
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().

1180 {
1181  uint32_t offset = 0;
1182 
1183  // Check for the arguments.
1184  ASSERT(multiplicand);
1185  ASSERT(multiplier);
1186  ASSERT(resultPKAMemAddr);
1187 
1188  // Make sure no operation is in progress.
1189  if (HWREG(PKA_BASE + PKA_O_FUNCTION) & PKA_FUNCTION_RUN) {
1191  }
1192 
1193  offset = PKAWritePkaParam(multiplicand, multiplicandLength, offset, PKA_O_APTR);
1194 
1195  offset = PKAWritePkaParam(multiplier, multiplierLength, offset, PKA_O_BPTR);
1196 
1197 
1198  // Copy the result vector address location.
1199  *resultPKAMemAddr = PKA_RAM_BASE + offset;
1200 
1201  // Load C pointer with the result location in PKA RAM.
1202  HWREG(PKA_BASE + PKA_O_CPTR) = offset >> 2;
1203 
1204  // Set the PKA function to the multiplication and start it.
1206 
1207  return PKA_STATUS_SUCCESS;
1208 }
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()
1261 {
1262  return PKAGetBigNumResult(resultBuf, resultLength, resultPKAMemAddr);
1263 }
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()
1271 {
1272  uint32_t offset = 0;
1273 
1274  // Check for arguments.
1275  ASSERT(minuend);
1276  ASSERT(subtrahend);
1277  ASSERT(resultPKAMemAddr);
1278 
1279 
1280  // Make sure no operation is in progress.
1281  if (HWREG(PKA_BASE + PKA_O_FUNCTION) & PKA_FUNCTION_RUN) {
1283  }
1284 
1285  offset = PKAWritePkaParam(minuend, minuendLength, offset, PKA_O_APTR);
1286 
1287  offset = PKAWritePkaParam(subtrahend, subtrahendLength, offset, PKA_O_BPTR);
1288 
1289  // Copy the result vector address location.
1290  *resultPKAMemAddr = PKA_RAM_BASE + offset;
1291 
1292  // Load C pointer with the result location in PKA RAM.
1293  HWREG(PKA_BASE + PKA_O_CPTR) = offset >> 2;
1294 
1295  // Set the function for the add operation and start the operation.
1297 
1298  return PKA_STATUS_SUCCESS;
1299 }
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()
1467 {
1468  return PKAGetECCResult(curvePointX, curvePointY, resultPKAMemAddr, length);
1469 }
static uint32_t PKAGetECCResult(uint8_t *curvePointX, uint8_t *curvePointY, uint32_t resultPKAMemAddr, uint32_t length)
Definition: pka.c:796

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()
1422 {
1423  uint32_t offset = 0;
1424 
1425  // Check for the arguments.
1426  ASSERT(curvePoint1X);
1427  ASSERT(curvePoint1Y);
1428  ASSERT(curvePoint2X);
1429  ASSERT(curvePoint2Y);
1430  ASSERT(prime);
1431  ASSERT(a);
1432  ASSERT(resultPKAMemAddr);
1433 
1434  // Make sure no operation is in progress.
1435  if (HWREG(PKA_BASE + PKA_O_FUNCTION) & PKA_FUNCTION_RUN) {
1437  }
1438 
1439  offset = PKAWritePkaParamExtraOffset(curvePoint1X, length, offset, PKA_O_APTR);
1440  offset = PKAWritePkaParamExtraOffset(curvePoint1Y, length, offset, PKA_NO_POINTER_REG);
1441 
1442 
1443  offset = PKAWritePkaParamExtraOffset(prime, length, offset, PKA_O_BPTR);
1444  offset = PKAWritePkaParamExtraOffset(a, length, offset, PKA_NO_POINTER_REG);
1445 
1446  offset = PKAWritePkaParamExtraOffset(curvePoint2X, length, offset, PKA_O_CPTR);
1447  offset = PKAWritePkaParamExtraOffset(curvePoint2Y, length, offset, PKA_NO_POINTER_REG);
1448 
1449  // Copy the result vector location.
1450  *resultPKAMemAddr = PKA_RAM_BASE + offset;
1451 
1452  // Load D pointer with the result location in PKA RAM.
1453  HWREG(PKA_BASE + PKA_O_DPTR) = offset >> 2;
1454 
1455  // Set the PKA Function to ECC-ADD and start the operation.
1457 
1458  return PKA_STATUS_SUCCESS;
1459 }
#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()
1367 {
1368  uint32_t offset = 0;
1369 
1370  // Check for the arguments.
1371  ASSERT(scalar);
1372  ASSERT(curvePointX);
1373  ASSERT(prime);
1374  ASSERT(a);
1375  ASSERT(length <= PKA_MAX_CURVE_SIZE_32_BIT_WORD * sizeof(uint32_t));
1376  ASSERT(resultPKAMemAddr);
1377 
1378  // Make sure no PKA operation is in progress.
1379  if (HWREG(PKA_BASE + PKA_O_FUNCTION) & PKA_FUNCTION_RUN) {
1381  }
1382 
1383  offset = PKAWritePkaParam(scalar, length, offset, PKA_O_APTR);
1384 
1385  offset = PKAWritePkaParamExtraOffset(prime, length, offset, PKA_O_BPTR);
1386  offset = PKAWritePkaParamExtraOffset(a, length, offset, PKA_NO_POINTER_REG);
1387 
1388  offset = PKAWritePkaParamExtraOffset(curvePointX, length, offset, PKA_O_CPTR);
1389 
1390  // Update the result location.
1391  // The resultPKAMemAddr may be 0 if we only want to check that we generated the point at infinity
1392  if (resultPKAMemAddr) {
1393  *resultPKAMemAddr = PKA_RAM_BASE + offset;
1394  }
1395 
1396  // Load D pointer with the result location in PKA RAM.
1397  HWREG(PKA_BASE + PKA_O_DPTR) = offset >> 2;
1398 
1399  // Set the PKA function to Montgomery ECC-MULT and start the operation.
1401 
1402  return PKA_STATUS_SUCCESS;
1403 }
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()
1412 {
1413  return PKAGetECCResult(curvePointX, curvePointY, resultPKAMemAddr, length);
1414 }
static uint32_t PKAGetECCResult(uint8_t *curvePointX, uint8_t *curvePointY, uint32_t resultPKAMemAddr, uint32_t length)
Definition: pka.c:796

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()
1318 {
1319  uint32_t offset = 0;
1320 
1321  // Check for the arguments.
1322  ASSERT(scalar);
1323  ASSERT(curvePointX);
1324  ASSERT(curvePointY);
1325  ASSERT(prime);
1326  ASSERT(a);
1327  ASSERT(b);
1328  ASSERT(length <= PKA_MAX_CURVE_SIZE_32_BIT_WORD * sizeof(uint32_t));
1329  ASSERT(resultPKAMemAddr);
1330 
1331  // Make sure no PKA operation is in progress.
1332  if (HWREG(PKA_BASE + PKA_O_FUNCTION) & PKA_FUNCTION_RUN) {
1334  }
1335 
1336  offset = PKAWritePkaParam(scalar, length, offset, PKA_O_APTR);
1337 
1338  offset = PKAWritePkaParamExtraOffset(prime, length, offset, PKA_O_BPTR);
1339  offset = PKAWritePkaParamExtraOffset(a, length, offset, PKA_NO_POINTER_REG);
1340  offset = PKAWritePkaParamExtraOffset(b, length, offset, PKA_NO_POINTER_REG);
1341 
1342  offset = PKAWritePkaParamExtraOffset(curvePointX, length, offset, PKA_O_CPTR);
1343  offset = PKAWritePkaParamExtraOffset(curvePointY, length, offset, PKA_NO_POINTER_REG);
1344 
1345  // Update the result location.
1346  // The resultPKAMemAddr may be 0 if we only want to check that we generated the point at infinity
1347  if (resultPKAMemAddr) {
1348  *resultPKAMemAddr = PKA_RAM_BASE + offset;
1349  }
1350 
1351  // Load D pointer with the result location in PKA RAM.
1352  HWREG(PKA_BASE + PKA_O_DPTR) = offset >> 2;
1353 
1354  // Set the PKA function to ECC-MULT and start the operation.
1356 
1357  return PKA_STATUS_SUCCESS;
1358 }
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()
1477 {
1478  uint32_t pkaResult;
1479  uint32_t resultAddress;
1480  uint32_t resultLength;
1481  uint8_t *scratchBuffer = (uint8_t *)(PKA_RAM_BASE + PKA_RAM_TOT_BYTE_SIZE / 2);
1482  uint8_t *scratchBuffer2 = scratchBuffer + 512;
1483 
1484 
1485  // Verify X in range [0, prime - 1]
1486  PKABigNumCmpStart(curvePointX,
1487  prime,
1488  length);
1489 
1491 
1492  pkaResult = PKABigNumCmpGetResult();
1493 
1494  if (pkaResult != PKA_STATUS_A_LESS_THAN_B) {
1496  }
1497 
1498  // Verify Y in range [0, prime - 1]
1499  PKABigNumCmpStart(curvePointY,
1500  prime,
1501  length);
1502 
1504 
1505  pkaResult = PKABigNumCmpGetResult();
1506 
1507  if (pkaResult != PKA_STATUS_A_LESS_THAN_B) {
1509  }
1510 
1511  // Verify point on curve
1512  // Short-Weierstrass equation: Y ^ 2 = X ^3 + a * X + b mod P
1513  // Reduced: Y ^ 2 = X * (X ^ 2 + a) + b
1514 
1515  // tmp = X ^ 2
1516  PKABigNumMultiplyStart(curvePointX, length, curvePointX, length, &resultAddress);
1517 
1519 
1520  resultLength = 200;
1521  pkaResult = PKABigNumMultGetResult(scratchBuffer, &resultLength, resultAddress);
1522 
1523  if (pkaResult != PKA_STATUS_SUCCESS) {
1524  return PKA_STATUS_FAILURE;
1525  }
1526 
1527  // tmp += a
1528  PKABigNumAddStart(scratchBuffer, resultLength, a, length, &resultAddress);
1529 
1531 
1532  resultLength = 200;
1533  pkaResult = PKABigNumAddGetResult(scratchBuffer, &resultLength, resultAddress);
1534 
1535  if (pkaResult != PKA_STATUS_SUCCESS) {
1536  return PKA_STATUS_FAILURE;
1537  }
1538 
1539  // tmp *= x
1540  PKABigNumMultiplyStart(scratchBuffer, resultLength, curvePointX, length, &resultAddress);
1541 
1543 
1544  resultLength = 200;
1545  pkaResult = PKABigNumMultGetResult(scratchBuffer, &resultLength, resultAddress);
1546 
1547  if (pkaResult != PKA_STATUS_SUCCESS) {
1548  return PKA_STATUS_FAILURE;
1549  }
1550 
1551  // tmp += b
1552  PKABigNumAddStart(scratchBuffer, resultLength, b, length, &resultAddress);
1553 
1555 
1556  resultLength = 200;
1557  pkaResult = PKABigNumAddGetResult(scratchBuffer, &resultLength, resultAddress);
1558 
1559  if (pkaResult != PKA_STATUS_SUCCESS) {
1560  return PKA_STATUS_FAILURE;
1561  }
1562 
1563 
1564  // tmp2 = tmp % prime to ensure we have no fraction in the division.
1565  // The number will only shrink from here on out.
1566  PKABigNumModStart(scratchBuffer, resultLength, prime, length, &resultAddress);
1567 
1569 
1570  // If the result is not a multiple of the word-length, the PKA HW will round up
1571  // because it deals in words only. That means that using 'length' directly
1572  // would cause and underflow, since length refers to the actual length in bytes of
1573  // the curve parameters while the PKA HW reports that rounded up to the next
1574  // word boundary.
1575  // Use 200 as the resultLength instead since we are copying to the scratch buffer
1576  // anyway.
1577  // Practically, this only happens with curves such as NIST-P521 that are not word
1578  // multiples.
1579  resultLength = 200;
1580  pkaResult = PKABigNumModGetResult(scratchBuffer2, resultLength, resultAddress);
1581 
1582  if (pkaResult != PKA_STATUS_SUCCESS) {
1583  return PKA_STATUS_FAILURE;
1584  }
1585 
1586  // tmp = y^2
1587  PKABigNumMultiplyStart(curvePointY, length, curvePointY, length, &resultAddress);
1588 
1590 
1591  resultLength = 200;
1592  pkaResult = PKABigNumMultGetResult(scratchBuffer, &resultLength, resultAddress);
1593 
1594  if (pkaResult != PKA_STATUS_SUCCESS) {
1595  return PKA_STATUS_FAILURE;
1596  }
1597 
1598  // tmp %= prime
1599  PKABigNumModStart(scratchBuffer, resultLength, prime, length, &resultAddress);
1600 
1602 
1603  // If the result is not a multiple of the word-length, the PKA HW will round up
1604  // because it deals in words only. That means that using 'length' directly
1605  // would cause and underflow, since length refers to the actual length in bytes of
1606  // the curve parameters while the PKA HW reports that rounded up to the next
1607  // word boundary.
1608  // Use 200 as the resultLength instead since we are copying to the scratch buffer
1609  // anyway.
1610  // Practically, this only happens with curves such as NIST-P521 that are not word
1611  // multiples.
1612  resultLength = 200;
1613  pkaResult = PKABigNumModGetResult(scratchBuffer, resultLength, resultAddress);
1614 
1615  if (pkaResult != PKA_STATUS_SUCCESS) {
1616  return PKA_STATUS_FAILURE;
1617  }
1618 
1619  // tmp ?= tmp2
1620  PKABigNumCmpStart(scratchBuffer,
1621  scratchBuffer2,
1622  length);
1623 
1625 
1626  pkaResult = PKABigNumCmpGetResult();
1627 
1628  if (pkaResult != PKA_STATUS_EQUAL) {
1630  }
1631  else {
1632  return PKA_STATUS_SUCCESS;
1633  }
1634 }
#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:985
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:1306
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:1225
uint32_t PKABigNumCmpStart(const uint8_t *bigNum1, const uint8_t *bigNum2, uint32_t length)
Starts the comparison of two big numbers.
Definition: pka.c:1066
#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:1215
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:950
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:1179
#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:884
uint32_t PKABigNumCmpGetResult(void)
Gets the result of the comparison operation of two big numbers.
Definition: pka.c:1095

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().

885 {
886  if (HWREG(PKA_BASE + PKA_O_FUNCTION) & PKA_FUNCTION_RUN_M) {
888  }
889  else {
891  }
892 }
#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().

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

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.