Data Structures | Macros | Typedefs | Enumerations | Functions
ECDSA.h File Reference

Detailed Description

TI Driver for Elliptic Curve Digital Signature Algorithm.

Overview

The Elliptic Curve Digital Signature Algorithm (ECDSA) is a message authentication scheme between two parties based on operation on elliptic curves over finite fields.

Signing a message with ECDSA proves to the recipient that the sender of the message is in possession of the private key corresponding to the transmitted public key used during verification. For most practical systems, this ensures message authentication and integrity.

Steps involved

Usage

Before starting an ECDSA operation

Before starting an ECDSA operation, the application must do the following:

Signing a message

To sign a message using an agreed upon hash function and elliptic curve, the application must do the following:

Verifying a message

After receiving the message, public key, r, and s, the application should do the following to verify the signature:

General usage

The API expects elliptic curves as defined in ti/drivers/cryptoutils/ecc/ECCParams.h. Several commonly used curves are provided. Check the device-specific ECDSA documentation for curve type (short Weierstrass, Montgomery, Edwards) support for your device. ECDSA support for a curve type on a device does not imply curve-type support for other ECC schemes.

Public keys and shared secrets are points on an elliptic curve. These points can be expressed in several ways. The most common one is in affine coordinates as an X,Y pair. This API uses points expressed in affine coordinates. The point is stored as a concatenated array of X followed by Y in a location described by its CryptoKey.

This API accepts and returns the keying material of public keys according to the following table:

Curve Type Keying Material Array Array Length
Short Weierstrass [X, Y] 2 * Curve Param Length
Montgomery [X, Y] 2 * Curve Param Length
Edwards [X, Y] 2 * Curve Param Length

ECDSA Driver Configuration

In order to use the ECDSA APIs, the application is required to provide device-specific ECDSA configuration in the Board.c file. The ECDSA driver interface defines a configuration data structure:

typedef struct ECDSA_Config_ {
void *object;
void const *hwAttrs;

The application must declare an array of ECDSA_Config elements, named ECDSA_config[]. Each element of ECDSA_config[] must be populated with pointers to a device specific ECDSA driver implementation's driver object, hardware attributes. Each element in ECDSA_config[] corresponds to an ECDSA instance, and none of the elements should have NULL pointers. There is no correlation between the index and the peripheral designation (such as ECDSA0 or ECDSA1). For example, it is possible to use ECDSA_config[0] for ECDSA1. Multiple drivers and driver instances may all access the same underlying hardware. This is transparent to the application. Mutual exclusion is performed automatically by the drivers as necessary.

Because the ECDSA configuration is highly device dependent, you will need to check the doxygen for the device specific ECDSA implementation. There you will find a description of the ECDSA hardware attributes. Please also refer to the Board.c file of any of your examples to see the ECDSA configuration.

ECDSA Parameters

The ECDSA_Params structure is passed to the ECDSA_open() call. If NULL is passed for the parameters, ECDSA_open() uses default parameters. An ECDSA_Params structure is initialized with default values by passing it to ECDSA_Params_init(). Some of the ECDSA parameters are described below. To see brief descriptions of all the parameters, see ECDSA_Params.

Examples

ECDSA sign with plaintext CryotoKeys

...
// This vector is taken from the NIST ST toolkit examples from ECDSA_Prime.pdf
uint8_t myPrivateKeyingMaterial[32] = {0x96, 0xBF, 0x85, 0x49, 0xC3, 0x79, 0xE4, 0x04,
0xED, 0xA1, 0x08, 0xA5, 0x51, 0xF8, 0x36, 0x23,
0x12, 0xD8, 0xD1, 0xB2, 0xA5, 0xFA, 0x57, 0x06,
0xE2, 0xCC, 0x22, 0x5C, 0xF6, 0xF9, 0x77, 0xC4};
uint8_t messageHashSHA256[32] = {0xC4, 0xA8, 0xC8, 0x99, 0x28, 0xCF, 0x80, 0xB6,
0xE4, 0x42, 0xD5, 0xBD, 0x28, 0x4D, 0xE3, 0xFD,
0x3A, 0x13, 0xD8, 0x65, 0x0C, 0x41, 0x1C, 0x21,
0x48, 0x95, 0x79, 0x2A, 0xA1, 0x41, 0x1A, 0xA4};
uint8_t pmsn[32] = {0xAE, 0x50, 0xEE, 0xFA, 0x27, 0xB4, 0xDB, 0x14,
0x9F, 0xE1, 0xFB, 0x04, 0xF2, 0x4B, 0x50, 0x58,
0x91, 0xE3, 0xAC, 0x4D, 0x2A, 0x5D, 0x43, 0xAA,
0xCA, 0xC8, 0x7F, 0x79, 0x52, 0x7E, 0x1A, 0x7A};
uint8_t r[32] = {0};
uint8_t s[32] = {0};
CryptoKey myPrivateKey;
CryptoKey pmsnKey;
ECDSA_Handle ecdsaHandle;
int_fast16_t operationResult;
// Since we are using default ECDSA_Params, we just pass in NULL for that parameter.
ecdsaHandle = ECDSA_open(0, NULL);
if (!ecdsaHandle) {
// Handle error
}
// Initialize myPrivateKey
CryptoKeyPlaintext_initKey(&myPrivateKey, myPrivateKeyingMaterial, sizeof(myPrivateKeyingMaterial));
CryptoKeyPlaintext_initKey(&pmsnKey, pmsn, sizeof(pmsn));
// Initialize the operation
ECDSA_OperationSign_init(&operationSign);
operationSign.curve = &ECCParams_NISTP256;
operationSign.myPrivateKey = &myPrivateKey;
operationSign.pmsn = &pmsnKey;
operationSign.hash = messageHash;
operationSign.r = r;
operationSign.s = s;
// Generate the signature
operationResult = ECDSA_sign(ecdsaHandle, &operationSign);
if (operationResult != ECDSA_STATUS_SUCCESS) {
// Handle error
}
// Send out signature
// r should be 0x4F, 0x10, 0x46, 0xCA, 0x9A, 0xB6, 0x25, 0x73,
// 0xF5, 0x3E, 0x0B, 0x1F, 0x6F, 0x31, 0x4C, 0xE4,
// 0x81, 0x0F, 0x50, 0xB1, 0xF3, 0xD1, 0x65, 0xFF,
// 0x65, 0x41, 0x7F, 0xD0, 0x76, 0xF5, 0x42, 0x2B
//
// s should be 0xF1, 0xFA, 0x63, 0x6B, 0xDB, 0x9B, 0x32, 0x4B,
// 0x2C, 0x26, 0x9D, 0xE6, 0x6F, 0x88, 0xC1, 0x98,
// 0x81, 0x2A, 0x50, 0x89, 0x3A, 0x99, 0x3A, 0x3E,
// 0xCD, 0x92, 0x63, 0x2D, 0x12, 0xC2, 0x42, 0xDC

ECDSA verify with plaintext CryotoKeys

...
// This vector is taken from the NIST ST toolkit examples from ECDSA_Prime.pdf
uint8_t theirPublicKeyingMaterial[64] = {0x19, 0x7A, 0xBC, 0x89, 0x08, 0xCD, 0x01, 0x82,
0xA3, 0xA2, 0x9E, 0x1E, 0xAD, 0xA0, 0xB3, 0x62,
0x1C, 0xBA, 0x98, 0x47, 0x73, 0x8C, 0xDC, 0xF1,
0xD3, 0xBA, 0x94, 0xFE, 0xFD, 0x8A, 0xE0, 0xB7,
0x09, 0x5E, 0xCC, 0x06, 0xC6, 0xBB, 0x63, 0xB5,
0x61, 0x9E, 0x52, 0x43, 0xAE, 0xC7, 0xAD, 0x63,
0x90, 0x72, 0x28, 0x19, 0xE4, 0x26, 0xB2, 0x4B,
0x7A, 0xBF, 0x9D, 0x95, 0x47, 0xF7, 0x03, 0x36};
uint8_t messageHashSHA256[32] = {0xC4, 0xA8, 0xC8, 0x99, 0x28, 0xCF, 0x80, 0xB6,
0xE4, 0x42, 0xD5, 0xBD, 0x28, 0x4D, 0xE3, 0xFD,
0x3A, 0x13, 0xD8, 0x65, 0x0C, 0x41, 0x1C, 0x21,
0x48, 0x95, 0x79, 0x2A, 0xA1, 0x41, 0x1A, 0xA4};
uint8_t r[32] = {0x4F, 0x10, 0x46, 0xCA, 0x9A, 0xB6, 0x25, 0x73,
0xF5, 0x3E, 0x0B, 0x1F, 0x6F, 0x31, 0x4C, 0xE4,
0x81, 0x0F, 0x50, 0xB1, 0xF3, 0xD1, 0x65, 0xFF,
0x65, 0x41, 0x7F, 0xD0, 0x76, 0xF5, 0x42, 0x2B};
uint8_t s[32] = {0xF1, 0xFA, 0x63, 0x6B, 0xDB, 0x9B, 0x32, 0x4B,
0x2C, 0x26, 0x9D, 0xE6, 0x6F, 0x88, 0xC1, 0x98,
0x81, 0x2A, 0x50, 0x89, 0x3A, 0x99, 0x3A, 0x3E,
0xCD, 0x92, 0x63, 0x2D, 0x12, 0xC2, 0x42, 0xDC};
CryptoKey theirPublicKey;
ECDSA_Handle ecdsaHandle;
int_fast16_t operationResult;
ECDSA_OperationVerify operationVerify;
// Since we are using default ECDSA_Params, we just pass in NULL for that parameter.
ecdsaHandle = ECDSA_open(0, NULL);
if (!ecdsaHandle) {
// Handle error
}
// Initialize theirPublicKey
CryptoKeyPlaintext_initKey(&theirPublicKey, theirPublicKeyingMaterial, sizeof(theirPublicKeyingMaterial));
ECDSA_OperationVerify_init(&operationVerify);
operationVerify.curve = &ECCParams_NISTP256;
operationVerify.theirPublicKey = &theirPublicKey;
operationVerify.hash = messageHash;
operationVerify.r = r;
operationVerify.s = s;
// Generate the keying material for myPublicKey and store it in myPublicKeyingMaterial
operationResult = ECDSA_verify(ecdsaHandle, &operationVerify);
if (operationResult != ECDSA_STATUS_SUCCESS) {
// Handle error
}
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <ti/drivers/cryptoutils/cryptokey/CryptoKey.h>
#include <ti/drivers/cryptoutils/ecc/ECCParams.h>

Go to the source code of this file.

Data Structures

struct  ECDSA_Config_
 ECDSA Global configuration. More...
 
struct  ECDSA_OperationSign_
 Struct containing the parameters required for signing a message. More...
 
struct  ECDSA_OperationVerify_
 Struct containing the parameters required for verifying a message. More...
 
union  ECDSA_Operation_
 Union containing pointers to all supported operation structs. More...
 
struct  ECDSA_Params_
 ECDSA Parameters. More...
 

Macros

#define ECDSA_CMD_RESERVED   (32)
 
#define ECDSA_STATUS_RESERVED   (-32)
 
#define ECDSA_STATUS_SUCCESS   (0)
 Successful status code. More...
 
#define ECDSA_STATUS_ERROR   (-1)
 Generic error status code. More...
 
#define ECDSA_STATUS_UNDEFINEDCMD   (-2)
 An error status code returned by ECDSA_control() for undefined command codes. More...
 
#define ECDSA_STATUS_RESOURCE_UNAVAILABLE   (-3)
 An error status code returned if the hardware or software resource is currently unavailable. More...
 
#define ECDSA_STATUS_INVALID_PMSN   (-4)
 The PMSN passed into the the call is invalid. More...
 
#define ECDSA_STATUS_R_LARGER_THAN_ORDER   (-5)
 The r value passed in is larger than the order of the curve. More...
 
#define ECDSA_STATUS_S_LARGER_THAN_ORDER   (-6)
 The r value passed in is larger than the order of the curve. More...
 
#define ECDSA_STATUS_PUBLIC_KEY_NOT_ON_CURVE   (-7)
 The public key of the other party does not lie upon the curve. More...
 
#define ECDSA_STATUS_PUBLIC_KEY_LARGER_THAN_PRIME   (-8)
 A coordinate of the public key of the other party is too large. More...
 
#define ECDSA_STATUS_POINT_AT_INFINITY   (-9)
 The public key to verify against is the point at infinity. More...
 

Typedefs

typedef struct ECDSA_Config_ECDSA_Handle
 A handle that is returned from an ECDSA_open() call. More...
 
typedef enum ECDSA_ReturnBehavior_ ECDSA_ReturnBehavior
 The way in which ECDSA function calls return after performing an encryption + authentication or decryption + verification operation. More...
 
typedef struct ECDSA_Config_ ECDSA_Config
 ECDSA Global configuration. More...
 
typedef struct ECDSA_OperationSign_ ECDSA_OperationSign
 Struct containing the parameters required for signing a message. More...
 
typedef struct ECDSA_OperationVerify_ ECDSA_OperationVerify
 Struct containing the parameters required for verifying a message. More...
 
typedef union ECDSA_Operation_ ECDSA_Operation
 Union containing pointers to all supported operation structs. More...
 
typedef enum ECDSA_OperationType_ ECDSA_OperationType
 Enum for the operation types supported by the driver. More...
 
typedef void(* ECDSA_CallbackFxn) (ECDSA_Handle handle, int_fast16_t returnStatus, ECDSA_Operation operation, ECDSA_OperationType operationType)
 The definition of a callback function used by the ECDSA driver when used in ECDSA_RETURN_BEHAVIOR_CALLBACK. More...
 
typedef struct ECDSA_Params_ ECDSA_Params
 ECDSA Parameters. More...
 

Enumerations

enum  ECDSA_ReturnBehavior_ { ECDSA_RETURN_BEHAVIOR_CALLBACK = 1, ECDSA_RETURN_BEHAVIOR_BLOCKING = 2, ECDSA_RETURN_BEHAVIOR_POLLING = 4 }
 The way in which ECDSA function calls return after performing an encryption + authentication or decryption + verification operation. More...
 
enum  ECDSA_OperationType_ { ECDSA_OPERATION_TYPE_SIGN = 1, ECDSA_OPERATION_TYPE_VERIFY = 2 }
 Enum for the operation types supported by the driver. More...
 

Functions

void ECDSA_init (void)
 This function initializes the ECDSA module. More...
 
void ECDSA_close (ECDSA_Handle handle)
 Function to close an ECDSA peripheral specified by the ECDSA handle. More...
 
int_fast16_t ECDSA_control (ECDSA_Handle handle, uint32_t cmd, void *args)
 Function performs implementation specific features on a given ECDSA_Handle. More...
 
ECDSA_Handle ECDSA_open (uint_least8_t index, ECDSA_Params *params)
 This function opens a given ECDSA peripheral. More...
 
void ECDSA_Params_init (ECDSA_Params *params)
 Function to initialize the ECDSA_Params struct to its defaults. More...
 
void ECDSA_OperationSign_init (ECDSA_OperationSign *operation)
 Function to initialize an ECDSA_OperationSign struct to its defaults. More...
 
void ECDSA_OperationVerify_init (ECDSA_OperationVerify *operation)
 Function to initialize an ECDSA_OperationSign struct to its defaults. More...
 
int_fast16_t ECDSA_sign (ECDSA_Handle handle, ECDSA_OperationSign *operation)
 Signs a hashed message. More...
 
int_fast16_t ECDSA_verify (ECDSA_Handle handle, ECDSA_OperationVerify *operation)
 Verifies a received signature matches a hash and public key. More...
 

Typedef Documentation

§ ECDSA_Handle

typedef struct ECDSA_Config_* ECDSA_Handle

A handle that is returned from an ECDSA_open() call.

§ ECDSA_ReturnBehavior

The way in which ECDSA function calls return after performing an encryption + authentication or decryption + verification operation.

Not all ECDSA operations exhibit the specified return behavor. Functions that do not require significant computation and cannot offload that computation to a background thread behave like regular functions. Which functions exhibit the specfied return behavior is implementation dependent. Specifically, a software-backed implementation run on the same CPU as the application will emulate the return behavior while not actually offloading the computation to the background thread.

ECDSA functions exhibiting the specified return behavior have restrictions on the context from which they may be called.

Task Hwi Swi
ECDSA_RETURN_BEHAVIOR_CALLBACK X X X
ECDSA_RETURN_BEHAVIOR_BLOCKING X
ECDSA_RETURN_BEHAVIOR_POLLING X X X

§ ECDSA_Config

typedef struct ECDSA_Config_ ECDSA_Config

ECDSA Global configuration.

The ECDSA_Config structure contains a set of pointers used to characterize the ECDSA driver implementation.

This structure needs to be defined before calling ECDSA_init() and it must not be changed thereafter.

See also
ECDSA_init()

§ ECDSA_OperationSign

Struct containing the parameters required for signing a message.

§ ECDSA_OperationVerify

Struct containing the parameters required for verifying a message.

§ ECDSA_Operation

Union containing pointers to all supported operation structs.

§ ECDSA_OperationType

Enum for the operation types supported by the driver.

§ ECDSA_CallbackFxn

typedef void(* ECDSA_CallbackFxn) (ECDSA_Handle handle, int_fast16_t returnStatus, ECDSA_Operation operation, ECDSA_OperationType operationType)

The definition of a callback function used by the ECDSA driver when used in ECDSA_RETURN_BEHAVIOR_CALLBACK.

Parameters
handleHandle of the client that started the ECDSA operation.
returnStatusThe result of the ECDSA operation. May contain an error code if the result is the point at infinity for example.
operationA union of pointers to operation structs. Only one type of pointer is valid per call to the callback function. Which type is currently valid is determined by /c operationType. The union allows easier access to the struct's fields without the need to typecase the result.
operationTypeThis parameter determined which operation the callback refers to and which type to access through /c operation.

§ ECDSA_Params

typedef struct ECDSA_Params_ ECDSA_Params

ECDSA Parameters.

ECDSA Parameters are used to with the ECDSA_open() call. Default values for these parameters are set using ECDSA_Params_init().

See also
ECDSA_Params_init()

Enumeration Type Documentation

§ ECDSA_ReturnBehavior_

The way in which ECDSA function calls return after performing an encryption + authentication or decryption + verification operation.

Not all ECDSA operations exhibit the specified return behavor. Functions that do not require significant computation and cannot offload that computation to a background thread behave like regular functions. Which functions exhibit the specfied return behavior is implementation dependent. Specifically, a software-backed implementation run on the same CPU as the application will emulate the return behavior while not actually offloading the computation to the background thread.

ECDSA functions exhibiting the specified return behavior have restrictions on the context from which they may be called.

Task Hwi Swi
ECDSA_RETURN_BEHAVIOR_CALLBACK X X X
ECDSA_RETURN_BEHAVIOR_BLOCKING X
ECDSA_RETURN_BEHAVIOR_POLLING X X X
Enumerator
ECDSA_RETURN_BEHAVIOR_CALLBACK 

The function call will return immediately while the ECDSA operation goes on in the background. The registered callback function is called after the operation completes. The context the callback function is called (task, HWI, SWI) is implementation-dependent.

ECDSA_RETURN_BEHAVIOR_BLOCKING 

The function call will block while ECDSA operation goes on in the background. ECDSA operation results are available after the function returns.

ECDSA_RETURN_BEHAVIOR_POLLING 

The function call will continuously poll a flag while ECDSA operation goes on in the background. ECDSA operation results are available after the function returns.

§ ECDSA_OperationType_

Enum for the operation types supported by the driver.

Enumerator
ECDSA_OPERATION_TYPE_SIGN 
ECDSA_OPERATION_TYPE_VERIFY 

Function Documentation

§ ECDSA_init()

void ECDSA_init ( void  )

This function initializes the ECDSA module.

Precondition
The ECDSA_config structure must exist and be persistent before this function can be called. This function must also be called before any other ECDSA driver APIs. This function call does not modify any peripheral registers.

§ ECDSA_close()

void ECDSA_close ( ECDSA_Handle  handle)

Function to close an ECDSA peripheral specified by the ECDSA handle.

Precondition
ECDSA_open() has to be called first.
Parameters
handleAn ECDSA handle returned from ECDSA_open()
See also
ECDSA_open()

§ ECDSA_control()

int_fast16_t ECDSA_control ( ECDSA_Handle  handle,
uint32_t  cmd,
void *  args 
)

Function performs implementation specific features on a given ECDSA_Handle.

Commands for ECDSA_control can originate from ECDSA.h or from implementation specific ECDSA*.h (ECDSACC26X2.h, ECDSASP432.h, etc.. ) files. While commands from ECDSA.h are API portable across driver implementations, not all implementations may support all these commands. Conversely, commands from driver implementation specific ECDSA*.h files add unique driver capabilities but are not API portable across all ECDSA driver implementations.

Commands supported by ECDSA.h follow an ECDSA_CMD_<cmd> naming convention.
Commands supported by ECDSA*.h follow an ECDSA*_CMD_<cmd> naming convention.
Each control command defines arg differently. The types of arg are documented with each command.

See ECDSA_control command codes for command codes.

See ECDSA_control return status codes for status codes.

Precondition
ECDSA_open() has to be called first.
Parameters
handleAn ECDSA handle returned from ECDSA_open()
cmdECDSA.h or ECDSA*.h commands.
argsAn optional R/W (read/write) command argument accompanied with cmd
Returns
Implementation specific return codes. Negative values indicate unsuccessful operations.
See also
ECDSA_open()

§ ECDSA_open()

ECDSA_Handle ECDSA_open ( uint_least8_t  index,
ECDSA_Params params 
)

This function opens a given ECDSA peripheral.

Precondition
ECDSA controller has been initialized using ECDSA_init()
Parameters
indexLogical peripheral number for the ECDSA indexed into the ECDSA_config table
paramsPointer to an parameter block, if NULL it will use default values.
Returns
An ECDSA_Handle on success or a NULL on an error or if it has been opened already.
See also
ECDSA_init()
ECDSA_close()

§ ECDSA_Params_init()

void ECDSA_Params_init ( ECDSA_Params params)

Function to initialize the ECDSA_Params struct to its defaults.

Parameters
paramsAn pointer to ECDSA_Params structure for initialization

Defaults values are: returnBehavior = ECDSA_RETURN_BEHAVIOR_BLOCKING callbackFxn = NULL timeout = SemaphoreP_WAIT_FOREVER custom = NULL

§ ECDSA_OperationSign_init()

void ECDSA_OperationSign_init ( ECDSA_OperationSign operation)

Function to initialize an ECDSA_OperationSign struct to its defaults.

Parameters
operationA pointer to ECDSA_OperationSign structure for initialization

Defaults values are all zeros.

§ ECDSA_OperationVerify_init()

void ECDSA_OperationVerify_init ( ECDSA_OperationVerify operation)

Function to initialize an ECDSA_OperationSign struct to its defaults.

Parameters
operationAn pointer to ECDSA_OperationSign structure for initialization

Defaults values are all zeros.

§ ECDSA_sign()

int_fast16_t ECDSA_sign ( ECDSA_Handle  handle,
ECDSA_OperationSign operation 
)

Signs a hashed message.

ECDSA_sign() generates a signature (r, s) of a hash of a message.

Precondition
ECDSA_OperationSign_init() must be called on operation first. The driver must have been opened by calling ECDSA_open() first.
Parameters
[in]handleAn ECDSA handle returned from ECDSA_open()
[in]operationA struct containing the pointers to the buffers necessary to perform the operation
See also
ECDSA_verify()

§ ECDSA_verify()

int_fast16_t ECDSA_verify ( ECDSA_Handle  handle,
ECDSA_OperationVerify operation 
)

Verifies a received signature matches a hash and public key.

Precondition
ECDSA_OperationVerify_init() must be called on operation first. The driver must have been opened by calling ECDSA_open() first.
Parameters
[in]handleAn ECDSA handle returned from ECDSA_open()
[in]operationA struct containing the pointers to the buffers necessary to perform the operation
See also
ECDSA_sign()
Copyright 2018, Texas Instruments Incorporated