CC26xx Driver Library
rom_ecc.c File Reference
#include "rom_ecc.h"
#include <stdbool.h>
#include <string.h>

Functions

void ECC_initialize (ECC_State *state, uint32_t *workzone)
 Initialize elliptic curve parameters to default values and specify workzone. More...
 
void ECC_init (ECC_State *state, uint32_t *workzone, uint8_t windowSize, const uint32_t *prime, const uint32_t *order, const uint32_t *a, const uint32_t *b, const uint32_t *generatorX, const uint32_t *generatorY)
 Initialize elliptic curve parameters to specified values and specify workzone. More...
 
uint8_t ECC_generateKey (ECC_State *state, uint32_t *randEntropy, uint32_t *privateKey, uint32_t *publicKey_x, uint32_t *publicKey_y)
 Generate a public key. More...
 
uint8_t ECC_ECDSA_sign (ECC_State *state, uint32_t *privateKey, uint32_t *hash, uint32_t *pmsn, uint32_t *r, uint32_t *s)
 Sign message digest. More...
 
uint8_t ECC_ECDSA_verify (ECC_State *state, uint32_t *publicKey_x, uint32_t *publicKey_y, uint32_t *hash, uint32_t *r, uint32_t *s)
 Verify signature. More...
 
uint8_t ECC_ECDH_computeSharedSecret (ECC_State *state, uint32_t *privateKey, uint32_t *publicKey_x, uint32_t *publicKey_y, uint32_t *sharedSecret_x, uint32_t *sharedSecret_y)
 Compute the shared secret. More...
 
uint8_t ECC_validatePublicKey (ECC_State *state, uint32_t *publicKey_x, uint32_t *publicKey_y)
 Validate a public key against the currently set elliptic curve. More...
 
uint8_t ECC_validatePrivateKey (ECC_State *state, uint32_t *privateKey)
 Validate a private key against the currently set elliptic curve. More...
 

Variables

const ECC_NISTP256_Param ECC_NISTP256_generatorX
 X coordinate of the generator point of the ECC_NISTP256 curve. More...
 
const ECC_NISTP256_Param ECC_NISTP256_generatorY
 Y coordinate of the generator point of the ECC_NISTP256 curve. More...
 
const ECC_NISTP256_Param ECC_NISTP256_prime
 prime of the ECC_NISTP256 curve. More...
 
const ECC_NISTP256_Param ECC_NISTP256_a
 a constant of the ECC_NISTP256 curve when expressed in short Weierstrass form (y^3 = x^2 + a*x + b). More...
 
const ECC_NISTP256_Param ECC_NISTP256_b
 b constant of the ECC_NISTP256 curve when expressed in short Weierstrass form (y^3 = x^2 + a*x + b). More...
 
const ECC_NISTP256_Param ECC_NISTP256_order
 order of the ECC_NISTP256 curve. More...
 
const ECC_NISTP256_Param ECC_NISTP256_k_mont
 k in Montgomery domain of the ECC_NISTP256 curve. More...
 
const ECC_NISTP256_Param ECC_NISTP256_a_mont
 a in Montgomery domain of the ECC_NISTP256 curve. More...
 
const ECC_NISTP256_Param ECC_NISTP256_b_mont
 b in Montgomery domain of the ECC_NISTP256 curve. More...
 

Function Documentation

§ ECC_ECDH_computeSharedSecret()

uint8_t ECC_ECDH_computeSharedSecret ( ECC_State state,
uint32_t *  privateKey,
uint32_t *  publicKey_x,
uint32_t *  publicKey_y,
uint32_t *  sharedSecret_x,
uint32_t *  sharedSecret_y 
)

Compute the shared secret.

Parameters
[in,out]stateStruct to keep track of the state of the operation
[in]privateKeyPointer to private key
[in]publicKey_xPointer to public key X-coordinate
[in]publicKey_yPointer to public key Y-coordinate
[out]sharedSecret_xPointer to shared secret X-coordinate
[out]sharedSecret_yPointer to shared secret Y-coordinate
Returns
Status
209 {
210  return HapiECDHCommonKey(state,
211  privateKey,
212  publicKey_x,
213  publicKey_y,
214  sharedSecret_x,
215  sharedSecret_y);
216 }
#define HapiECDHCommonKey(a, b, c, d, e, f)
Definition: rom.h:276

§ ECC_ECDSA_sign()

uint8_t ECC_ECDSA_sign ( ECC_State state,
uint32_t *  privateKey,
uint32_t *  hash,
uint32_t *  pmsn,
uint32_t *  r,
uint32_t *  s 
)

Sign message digest.

Parameters
[in,out]stateStruct to keep track of the state of the operation
[in]privateKeyPointer to the secret key
[in]hashPointer to the message
[in]pmsnPointer to random string
[out]rPointer to r component of signature
[out]sPointer to s component of signature
Returns
Status
183 {
184  return HapiECDSASign(state, privateKey, hash, pmsn, r, s);
185 }
#define HapiECDSASign(a, b, c, d, e, f)
Definition: rom.h:274

§ ECC_ECDSA_verify()

uint8_t ECC_ECDSA_verify ( ECC_State state,
uint32_t *  publicKey_x,
uint32_t *  publicKey_y,
uint32_t *  hash,
uint32_t *  r,
uint32_t *  s 
)

Verify signature.

Parameters
[in,out]stateStruct to keep track of the state of the operation
[in]publicKey_xPointer to public key X-coordinate
[in]publicKey_yPointer to public key Y-coordinate
[in]hashPointer to hash of message digest
[in]rPointer to r component of signature
[in]sPointer to s component of signature
Returns
Status
196 {
197  return HapiECDSAVerify(state, publicKey_x, publicKey_y, hash, r, s);
198 }
#define HapiECDSAVerify(a, b, c, d, e, f)
Definition: rom.h:275

§ ECC_generateKey()

uint8_t ECC_generateKey ( ECC_State state,
uint32_t *  randEntropy,
uint32_t *  privateKey,
uint32_t *  publicKey_x,
uint32_t *  publicKey_y 
)

Generate a public key.

This is used for both ECDH and ECDSA.

Parameters
[in,out]stateStruct to keep track of the state of the operation
[in]randEntropyPointer to random string
[out]privateKeyPointer to the private key. May be the same location as randEntropy.
[out]publicKey_xPointer to public key X-coordinate
[out]publicKey_yPointer to public key Y-coordinate
Returns
Status
165 {
166  return HapiECCKeyGen(state,
167  randEntropy,
168  privateKey,
169  publicKey_x,
170  publicKey_y);
171 
172 }
#define HapiECCKeyGen(a, b, c, d, e)
Definition: rom.h:273

§ ECC_init()

void ECC_init ( ECC_State state,
uint32_t *  workzone,
uint8_t  windowSize,
const uint32_t *  prime,
const uint32_t *  order,
const uint32_t *  a,
const uint32_t *  b,
const uint32_t *  generatorX,
const uint32_t *  generatorY 
)

Initialize elliptic curve parameters to specified values and specify workzone.

This function may be used to explicitly specify the curve parameters used by the ECC in ROM implementation.

All curve parameters must be prepended with a length word specifying the length of the parameter in 32-bit words excluding the length word itself. For NIST-P256, the length word is 8.

Parameters
stateStruct to keep track of the state of the operation.
workzonePointer to memory allocated for computations, input. See description at beginning of ECC section for memory requirements.
windowSizeWindow size of workzone. Default value is 3.
primeCurve prime
orderCurve order
aCurve a value
bCurve b value
generatorXX coordinate of generator point
generatorYY coordinate of generator point
141 {
142  state->data_Gx = generatorX;
143  state->data_Gy = generatorY;
144  state->data_p = prime;
145  state->data_r = order;
146  state->data_a = a;
147  state->data_b = b;
148  // TODO: change signature to accommodate in future
152  state->win = windowSize;
153  state->workzone = workzone;
154 }
const uint32_t * data_r
Definition: rom.h:61
const uint32_t * data_p
Definition: rom.h:60
const ECC_NISTP256_Param ECC_NISTP256_a_mont
a in Montgomery domain of the ECC_NISTP256 curve.
Definition: rom_ecc.c:97
const ECC_NISTP256_Param ECC_NISTP256_k_mont
k in Montgomery domain of the ECC_NISTP256 curve.
Definition: rom_ecc.c:91
const uint32_t * data_k_mont
Definition: rom.h:66
uint32_t * workzone
Definition: rom.h:69
uint32_t word[ECC_NISTP256_PARAM_LENGTH_WITH_OFFSET_BYTES/sizeof(uint32_t)]
Definition: rom_ecc.h:122
const uint32_t * data_b_mont
Definition: rom.h:68
const uint32_t * data_Gx
Definition: rom.h:64
const uint32_t * data_a
Definition: rom.h:62
const uint32_t * data_a_mont
Definition: rom.h:67
const ECC_NISTP256_Param ECC_NISTP256_b_mont
b in Montgomery domain of the ECC_NISTP256 curve.
Definition: rom_ecc.c:103
const uint32_t * data_b
Definition: rom.h:63
uint8_t win
Definition: rom.h:58
const uint32_t * data_Gy
Definition: rom.h:65

§ ECC_initialize()

void ECC_initialize ( ECC_State state,
uint32_t *  workzone 
)

Initialize elliptic curve parameters to default values and specify workzone.

This function initializes the elliptic curve parameters to default values. The default elliptic curve used is NIST-P256.

The workzone defaults to an expected window size of 3.

This function can be called again to point the ECC workzone at a different memory buffer.

Parameters
stateStruct to keep track of the state of the operation.
workzonePointer to memory allocated for computations, input. See description at beginning of ECC section for memory requirements.
Returns
None
115 {
118  state->data_p = ECC_NISTP256_prime.word;
119  state->data_r = ECC_NISTP256_order.word;
120  state->data_a = ECC_NISTP256_a.word;
121  state->data_b = ECC_NISTP256_b.word;
125  state->win = 3;
126  state->workzone = workzone;
127 }
const uint32_t * data_r
Definition: rom.h:61
const ECC_NISTP256_Param ECC_NISTP256_b
b constant of the ECC_NISTP256 curve when expressed in short Weierstrass form (y^3 = x^2 + a*x + b)...
Definition: rom_ecc.c:79
const uint32_t * data_p
Definition: rom.h:60
const ECC_NISTP256_Param ECC_NISTP256_a_mont
a in Montgomery domain of the ECC_NISTP256 curve.
Definition: rom_ecc.c:97
const ECC_NISTP256_Param ECC_NISTP256_k_mont
k in Montgomery domain of the ECC_NISTP256 curve.
Definition: rom_ecc.c:91
const uint32_t * data_k_mont
Definition: rom.h:66
uint32_t * workzone
Definition: rom.h:69
const ECC_NISTP256_Param ECC_NISTP256_a
a constant of the ECC_NISTP256 curve when expressed in short Weierstrass form (y^3 = x^2 + a*x + b)...
Definition: rom_ecc.c:73
uint32_t word[ECC_NISTP256_PARAM_LENGTH_WITH_OFFSET_BYTES/sizeof(uint32_t)]
Definition: rom_ecc.h:122
const ECC_NISTP256_Param ECC_NISTP256_generatorY
Y coordinate of the generator point of the ECC_NISTP256 curve.
Definition: rom_ecc.c:61
const ECC_NISTP256_Param ECC_NISTP256_generatorX
X coordinate of the generator point of the ECC_NISTP256 curve.
Definition: rom_ecc.c:55
const ECC_NISTP256_Param ECC_NISTP256_order
order of the ECC_NISTP256 curve.
Definition: rom_ecc.c:85
const uint32_t * data_b_mont
Definition: rom.h:68
const uint32_t * data_Gx
Definition: rom.h:64
const ECC_NISTP256_Param ECC_NISTP256_prime
prime of the ECC_NISTP256 curve.
Definition: rom_ecc.c:67
const uint32_t * data_a
Definition: rom.h:62
const uint32_t * data_a_mont
Definition: rom.h:67
const ECC_NISTP256_Param ECC_NISTP256_b_mont
b in Montgomery domain of the ECC_NISTP256 curve.
Definition: rom_ecc.c:103
const uint32_t * data_b
Definition: rom.h:63
uint8_t win
Definition: rom.h:58
const uint32_t * data_Gy
Definition: rom.h:65

§ ECC_validatePrivateKey()

uint8_t ECC_validatePrivateKey ( ECC_State state,
uint32_t *  privateKey 
)

Validate a private key against the currently set elliptic curve.

Validates that private key is within [1, n-1] where n is the order of the elliptic curve.

Parameters
[in,out]stateStruct to keep track of the state of the operation
privateKeyPointer to public key X-coordinate, input.
Returns
Status
234 {
235  return HapiECCValidatePrivateKeyWeierstrass(state, privateKey);
236 }
#define HapiECCValidatePrivateKeyWeierstrass(a, b)
Definition: rom.h:278

§ ECC_validatePublicKey()

uint8_t ECC_validatePublicKey ( ECC_State state,
uint32_t *  publicKey_x,
uint32_t *  publicKey_y 
)

Validate a public key against the currently set elliptic curve.

Parameters
[in,out]stateStruct to keep track of the state of the operation
publicKey_xPointer to public key X-coordinate, input.
publicKey_yPointer to public key Y-coordinate, input.
Returns
Status
224 {
226  publicKey_x,
227  publicKey_y);
228 }
#define HapiECCValidatePublicKeyWeierstrass(a, b, c)
Definition: rom.h:277

Variable Documentation

§ ECC_NISTP256_a

const ECC_NISTP256_Param ECC_NISTP256_a
Initial value:
= {.byte = {0x08, 0x00, 0x00, 0x00,
0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff}}

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

§ ECC_NISTP256_a_mont

const ECC_NISTP256_Param ECC_NISTP256_a_mont
Initial value:
= {.byte = {
0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00, 0xfc, 0xff, 0xff, 0xff }}

a in Montgomery domain of the ECC_NISTP256 curve.

§ ECC_NISTP256_b

const ECC_NISTP256_Param ECC_NISTP256_b
Initial value:
= {.byte = {0x08, 0x00, 0x00, 0x00,
0x4b, 0x60, 0xd2, 0x27, 0x3e, 0x3c, 0xce, 0x3b,
0xf6, 0xb0, 0x53, 0xcc, 0xb0, 0x06, 0x1d, 0x65,
0xbc, 0x86, 0x98, 0x76, 0x55, 0xbd, 0xeb, 0xb3,
0xe7, 0x93, 0x3a, 0xaa, 0xd8, 0x35, 0xc6, 0x5a}}

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

§ ECC_NISTP256_b_mont

const ECC_NISTP256_Param ECC_NISTP256_b_mont
Initial value:
= {.byte = {
0xdf, 0xbd, 0xc4, 0x29, 0x62, 0xdf, 0x9c, 0xd8,
0x90, 0x30, 0x84, 0x78, 0xcd, 0x05, 0xf0, 0xac,
0xd6, 0x2e, 0x21, 0xf7, 0xab, 0x20, 0xa2, 0xe5,
0x34, 0x48, 0x87, 0x04, 0x1d, 0x06, 0x30, 0xdc }}

b in Montgomery domain of the ECC_NISTP256 curve.

§ ECC_NISTP256_generatorX

const ECC_NISTP256_Param ECC_NISTP256_generatorX
Initial value:
= {.byte = {0x08, 0x00, 0x00, 0x00,
0x96, 0xc2, 0x98, 0xd8, 0x45, 0x39, 0xa1, 0xf4,
0xa0, 0x33, 0xeb, 0x2d, 0x81, 0x7d, 0x03, 0x77,
0xf2, 0x40, 0xa4, 0x63, 0xe5, 0xe6, 0xbc, 0xf8,
0x47, 0x42, 0x2c, 0xe1, 0xf2, 0xd1, 0x17, 0x6b}}

X coordinate of the generator point of the ECC_NISTP256 curve.

§ ECC_NISTP256_generatorY

const ECC_NISTP256_Param ECC_NISTP256_generatorY
Initial value:
= {.byte = {0x08, 0x00, 0x00, 0x00,
0xf5, 0x51, 0xbf, 0x37, 0x68, 0x40, 0xb6, 0xcb,
0xce, 0x5e, 0x31, 0x6b, 0x57, 0x33, 0xce, 0x2b,
0x16, 0x9e, 0x0f, 0x7c, 0x4a, 0xeb, 0xe7, 0x8e,
0x9b, 0x7f, 0x1a, 0xfe, 0xe2, 0x42, 0xe3, 0x4f}}

Y coordinate of the generator point of the ECC_NISTP256 curve.

§ ECC_NISTP256_k_mont

const ECC_NISTP256_Param ECC_NISTP256_k_mont
Initial value:
= {.byte = {
0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xff, 0xff, 0xff, 0xff, 0xfb, 0xff, 0xff, 0xff,
0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xfd, 0xff, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00 }}

k in Montgomery domain of the ECC_NISTP256 curve.

§ ECC_NISTP256_order

const ECC_NISTP256_Param ECC_NISTP256_order
Initial value:
= {.byte = {0x08, 0x00, 0x00, 0x00,
0x51, 0x25, 0x63, 0xfc, 0xc2, 0xca, 0xb9, 0xf3,
0x84, 0x9e, 0x17, 0xa7, 0xad, 0xfa, 0xe6, 0xbc,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff}}

order of the ECC_NISTP256 curve.

§ ECC_NISTP256_prime

const ECC_NISTP256_Param ECC_NISTP256_prime
Initial value:
= {.byte = {0x08, 0x00, 0x00, 0x00,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff}}

prime of the ECC_NISTP256 curve.