TI BLE-Stack for Bluetooth 4.2 API Documentation  3.01.00.07
Data Structures | Macros | Typedefs | Functions
ECCROMCC26XX.h File Reference

Detailed Description

ECC ROM driver implementation for a CC26XX device.

============================================================================

Driver Include

The ECC ROM header file should be included in an application as follows:

#include <ti/drivers/ecc/ECCROMCC26XX.h>

Overview

The ECCROMCC26XX driver provides reentrant access to the ROM based ECC module. Access is given first come, first serve and subsequent calls block until all preceding callers have returned or the caller times out in which case execution returns to the caller but the operation is not performed.

Note: this implementation differs in byte ordering from the NIST Standard. It is not expected that keys input from a different implementation will match the output here.

Dependencies

This driver is dependent on TRNGCC26XX driver for random number generation. TRNGCC26XX driver should always be included in the project.

General Behavior

For code examples, see Use Cases below.

Initialzing the driver

// Initialize ECC ROM driver
// Generate Public Keys
status = ECCROMCC26XX_genKeys(privKey, pubKeyX, pubKeyY, &params);
if (!status) {
System_printf("ECCROMCC26XX did not complete successfully");
}

Initializing client parameters

// Declaration of this client's ECCROMCC26XX parameters.
// Initialize this client's ECCROMCC26XX parameters.
// Set the Malloc and Free functions for internal buffer allocation.
params.malloc = (uint8_t *(*)(uint16_t))myMallocFunction;
params.free = (void (*)(uint8_t *))myFreeFunction;
// If an indefinite timeout is undesirable, alter the timeout here.
// the value specified here will be a multiple of Clock.tickPeriod is
// specified as.
params.timeout = 1000; // wait a maximum of 1000 system time units
// If using non NIST P-256 curves, supply them here. Otherwise, skip this.
params.curve.keyLen = myCurveLength; // in bytes.
params.curve.workzoneLen = ECCROMCC26XX_WORKZONE_LEN_IN_BYTES(myCurveLength/4, myWindowSize);
params.curve.windowSize = myWindowSize;
params.curve.param_p = myCurveParamP;
params.curve.param_r = myCurveParamR;
params.curve.param_a = myCurveParamA;
params.curve.param_b = myCurveParamB;
params.curve.param_gx = myCurveParamGx;
params.curve.param_gy = myCurveParamGy;

Use Cases

### Performing a key and shared secret generation operation #

// Declaration of this client's ECCROMCC26XX parameters.
// Declaration of local public keys
uint8_t localPrivateKey[32] = {0};
uint8_t localPublicKeyX[32] = {0};
uint8_t localPublicKeyY[32] = {0};
uint8_t sharedSecretKeyX[32] = {0};
uint8_t sharedSecretKeyY[32] = {0};
// Declaration of a remote client's public keys.
// Assume they have already been generated.
extern remotePublicKeyX[32];
extern remotePublicKeyY[32];
// Fill localPrivateKey with 256 bits from a random number generator.
myRandomNumberGenerator(localPrivateKey, 32);
// Initialize ECC ROM driver
// Initialize this client's ECCROMCC26XX parameters.
// Generate public keys
ECCROMCC26XX_genKeys(localPrivateKey, localPublicKeyX,
localPublicKeyY, &params);
// Generate shared secret.
// Note: given your local Public Keys, the remote device can generate the
// same shared secret using its local private key.
ECCROMCC26XX_genDHKey(localPrivateKey, remotePublicKeyX,
remotePublicKeyY, sharedSecretKeyX,
sharedSecretKeyY, &params);
// Generate signature for hashed message
// Given the local private key and hash, the remote device can generate 64
// byte signature split into two 32 byte buffers
uint8_t hash[32] = {0};
uint8_t sign1[32] = {0};
uint8_t sign1[32] = {0};
// Fill with SHA256 hashed message
mySha2HashGenerator(hash);
ECCROMCC26XX_signHash(localPrivateKey,hash,32,sign1,sign2,&params)
// Verify signature for hashed message
// Given the local public keys, hash, and generated signature the remote
// device can verify the signature generated using the local private keys
ECCROMCC26XX_verifyHash(localPublicKeyX,localPublicKeyY,sign1,sign2,hash,
32,&params);

Supported transaction modes

Error handling

If an error occur during key generation, an error status will be returned and stored in the status field of the ECCROMCC26XX_Params instance passed as an argument.

Supported Functions

API function Description
ECCROMCC26XX_init() Initializes module's synchronization resources
ECCROMCC26XX_Params_init() Initialize parameters for Key Generation
ECCROMCC26XX_genKeys() Generate Public Key X and Y Coordinates
ECCROMCC26XX_genDHKey() Generate Diffie-Hellman Shared Secret
ECCROMCC26XX_signHash() Generates
ECCROMCC26XX_verifyHash() Verifies a previously generated signature

============================================================================

Go to the source code of this file.

Data Structures

struct  ECCROMCC26XX_CurveParams
 ECCROMCC26XX Curve Parameters. More...
 
struct  ECCROMCC26XX_Params
 ECCROMCC26XX Parameters. More...
 

Macros

#define ECCROMCC26XX_NIST_P256_KEY_LEN_IN_BYTES   32
 
#define ECCROMCC26XX_NIST_P256_WORKZONE_LEN_IN_BYTES   684
 
#define ECCROMCC26XX_NIST_P256_WORKZONE_SIGN_VERIFY_LEN_IN_BYTES   1100
 
#define ECCROMCC26XX_STATUS_A_COEF_LENGTH_ZERO   0xC5
 
#define ECCROMCC26XX_STATUS_A_COEF_TOO_LONG   0x5C
 
#define ECCROMCC26XX_STATUS_BAD_WINDOW_SIZE   0x66
 
#define ECCROMCC26XX_STATUS_DIGEST_LENGTH_ZERO   0x72
 
#define ECCROMCC26XX_STATUS_DIGEST_TOO_LONG   0x27
 
#define ECCROMCC26XX_STATUS_ECCROMCC26XX_STATUS_KEY_LENGTH_ZERO   0x52
 
#define ECCROMCC26XX_STATUS_ECCROMCC26XX_STATUS_KEY_TOO_LONG   0x25
 
#define ECCROMCC26XX_STATUS_ECDH_COMMON_KEY_OK   ECCROMCC26XX_STATUS_SCALAR_MUL_OK
 
#define ECCROMCC26XX_STATUS_ECDH_KEYGEN_OK   ECCROMCC26XX_STATUS_SCALAR_MUL_OK
 
#define ECCROMCC26XX_STATUS_ECDSA_INVALID_SIGNATURE   0x5A
 
#define ECCROMCC26XX_STATUS_ECDSA_SIGN_OK   0x32
 
#define ECCROMCC26XX_STATUS_ECDSA_VALID_SIGNATURE   0xA5
 
#define ECCROMCC26XX_STATUS_ILLEGAL_PARAM   -2
 
#define ECCROMCC26XX_STATUS_MALLOC_FAIL   -1
 
#define ECCROMCC26XX_STATUS_MODULUS_EVEN   0xDC
 
#define ECCROMCC26XX_STATUS_MODULUS_LARGER_THAN_255_WORDS   0xD2
 
#define ECCROMCC26XX_STATUS_MODULUS_LENGTH_ZERO   0x08
 
#define ECCROMCC26XX_STATUS_MODULUS_MSW_IS_ZERO   0x30
 
#define ECCROMCC26XX_STATUS_ORDER_EVEN   0x82
 
#define ECCROMCC26XX_STATUS_ORDER_LARGER_THAN_255_WORDS   0x28
 
#define ECCROMCC26XX_STATUS_ORDER_LENGTH_ZERO   0x6C
 
#define ECCROMCC26XX_STATUS_ORDER_MSW_IS_ZERO   0x23
 
#define ECCROMCC26XX_STATUS_ORDER_TOO_LONG   0xC6
 
#define ECCROMCC26XX_STATUS_SCALAR_LENGTH_ZERO   0x53
 
#define ECCROMCC26XX_STATUS_SCALAR_MUL_OK   0x99
 
#define ECCROMCC26XX_STATUS_SCALAR_TOO_LONG   0x35
 
#define ECCROMCC26XX_STATUS_SIG_P1_LENGTH_ZERO   0x12
 
#define ECCROMCC26XX_STATUS_SIG_P1_TOO_LONG   0x11
 
#define ECCROMCC26XX_STATUS_SIG_P2_LENGTH_ZERO   0x21
 
#define ECCROMCC26XX_STATUS_SIG_P2_TOO_LONG   0x22
 
#define ECCROMCC26XX_STATUS_SUCCESS   0
 
#define ECCROMCC26XX_STATUS_TIMEOUT   -3
 
#define ECCROMCC26XX_STATUS_X_COORD_LENGTH_ZERO   0xC3
 
#define ECCROMCC26XX_STATUS_X_COORD_TOO_LONG   0x3C
 
#define ECCROMCC26XX_STATUS_Y_COORD_LENGTH_ZERO   0x56
 
#define ECCROMCC26XX_STATUS_Y_COORD_TOO_LONG   0x65
 
#define ECCROMCC26XX_WORKZONE_LEN_IN_BYTES(len, win)   (4 * ((13 * (len)) + 13 + (3 * (len) * (1 << ((win) - 2)))))
 Compute ECC workzone length in bytes for a generic key length and window size. More...
 

Typedefs

typedef struct ECCROMCC26XX_CurveParams ECCROMCC26XX_CurveParams
 ECCROMCC26XX Curve Parameters. More...
 
typedef void(* ECCROMCC26XX_FreeCB) (uint8_t *pBuf)
 ECCROMCC26XX Free Callback. More...
 
typedef uint8_t *(* ECCROMCC26XX_MallocCB) (uint16_t len)
 ECCROMCC26XX Malloc Callback. More...
 
typedef struct ECCROMCC26XX_Params ECCROMCC26XX_Params
 ECCROMCC26XX Parameters. More...
 

Functions

int8_t ECCROMCC26XX_genDHKey (uint8_t *privateKey, uint8_t *publicKeyX, uint8_t *publicKeyY, uint8_t *dHKeyX, uint8_t *dHKeyY, ECCROMCC26XX_Params *params)
 Generate Diffie-Hellman Shared Secret Key X and Y Coordinates. More...
 
int8_t ECCROMCC26XX_genKeys (uint8_t *privateKey, uint8_t *publicKeyX, uint8_t *publicKeyY, ECCROMCC26XX_Params *params)
 Generate Public Key X and Y Coordinates. More...
 
void ECCROMCC26XX_init (void)
 Initializes module's synchronization resources. Only needs to be called once, but safe to call multiple times. More...
 
void ECCROMCC26XX_Params_init (ECCROMCC26XX_Params *params)
 Function to initialize the ECCROMCC26XX_Params struct to its defaults. params should not be modified until after this function is called. Default parameters use the NIST P-256 curve, timeout is set to wait indefinitely, malloc and free are NULL and status is set to ECCROMCC26XX_STATUS_SUCCESS. A client may call this function with the same params instance any number of times. More...
 
int8_t ECCROMCC26XX_signHash (uint8_t *privateKey, const uint8_t *hash, uint32_t hashLen, uint8_t *sign1, uint8_t *sign2, ECCROMCC26XX_Params *params)
 Compute the signature of a previously hashed message. More...
 
int8_t ECCROMCC26XX_verifyHash (uint8_t *publicKeyX, uint8_t *publicKeyY, uint8_t *sign1, uint8_t *sign2, uint8_t *hash, uint32_t hashLen, ECCROMCC26XX_Params *params)
 Verify the signature of a previously hashed message. More...
 
Copyright 2017, Texas Instruments Incorporated