ECDSA.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017-2018, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
332 #ifndef ti_drivers_ECDSA__include
333 #define ti_drivers_ECDSA__include
334 
335 #ifdef __cplusplus
336 extern "C" {
337 #endif
338 
339 #include <stdbool.h>
340 #include <stddef.h>
341 #include <stdint.h>
342 
345 
363 #define ECDSA_CMD_RESERVED (32)
364 
377 #define ECDSA_STATUS_RESERVED (-32)
378 
392 #define ECDSA_STATUS_SUCCESS (0)
393 
400 #define ECDSA_STATUS_ERROR (-1)
401 
409 #define ECDSA_STATUS_UNDEFINEDCMD (-2)
410 
419 #define ECDSA_STATUS_RESOURCE_UNAVAILABLE (-3)
420 
427 #define ECDSA_STATUS_INVALID_PMSN (-4)
428 
435 #define ECDSA_STATUS_R_LARGER_THAN_ORDER (-5)
436 
443 #define ECDSA_STATUS_S_LARGER_THAN_ORDER (-6)
444 
451 #define ECDSA_STATUS_PUBLIC_KEY_NOT_ON_CURVE (-7)
452 
460 #define ECDSA_STATUS_PUBLIC_KEY_LARGER_THAN_PRIME (-8)
461 
467 #define ECDSA_STATUS_POINT_AT_INFINITY (-9)
468 
469 
480 /* Add ECDSA_CMD_<commands> here */
481 
489 typedef struct ECDSA_Config_ *ECDSA_Handle;
490 
512 typedef enum ECDSA_ReturnBehavior_ {
528 
540 typedef struct ECDSA_Config_ {
542  void *object;
543 
545  void const *hwAttrs;
546 } ECDSA_Config;
547 
551 typedef struct ECDSA_OperationSign_ {
556  const CryptoKey *pmsn;
562  const uint8_t *hash;
565  uint8_t *r;
570  uint8_t *s;
576 
580 typedef struct ECDSA_OperationVerify_ {
585  const uint8_t *hash;
588  const uint8_t *r;
592  const uint8_t *s;
597 
601 typedef union ECDSA_Operation_ {
605 
609 typedef enum ECDSA_OperationType_ {
613 
632 typedef void (*ECDSA_CallbackFxn) (ECDSA_Handle handle,
633  int_fast16_t returnStatus,
634  ECDSA_Operation operation,
635  ECDSA_OperationType operationType);
636 
645 typedef struct ECDSA_Params_ {
648  uint32_t timeout;
651  void *custom;
654 } ECDSA_Params;
655 
664 void ECDSA_init(void);
665 
675 void ECDSA_close(ECDSA_Handle handle);
676 
714 int_fast16_t ECDSA_control(ECDSA_Handle handle, uint32_t cmd, void *args);
715 
733 ECDSA_Handle ECDSA_open(uint_least8_t index, ECDSA_Params *params);
734 
747 void ECDSA_Params_init(ECDSA_Params *params);
748 
758 
768 
784 int_fast16_t ECDSA_sign(ECDSA_Handle handle, ECDSA_OperationSign *operation);
785 
799 int_fast16_t ECDSA_verify(ECDSA_Handle handle, ECDSA_OperationVerify *operation);
800 
801 #ifdef __cplusplus
802 }
803 #endif
804 
805 #endif /* ti_drivers_ECDSA__include */
void * object
Definition: ECDSA.h:542
Struct containing the parameters required for signing a message.
Definition: ECDSA.h:551
enum ECDSA_ReturnBehavior_ ECDSA_ReturnBehavior
The way in which ECDSA function calls return after performing an encryption + authentication or decry...
const uint8_t * s
Definition: ECDSA.h:592
The CryptoKey type is an opaque representation of a cryptographic key.
Union containing pointers to all supported operation structs.
Definition: ECDSA.h:601
struct ECDSA_OperationVerify_ ECDSA_OperationVerify
Struct containing the parameters required for verifying a message.
void const * hwAttrs
Definition: ECDSA.h:545
void ECDSA_OperationSign_init(ECDSA_OperationSign *operation)
Function to initialize an ECDSA_OperationSign struct to its defaults.
ECDSA_ReturnBehavior returnBehavior
Definition: ECDSA.h:646
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_CAL...
Definition: ECDSA.h:632
ECDSA_OperationVerify * verify
Definition: ECDSA.h:603
int_fast16_t ECDSA_control(ECDSA_Handle handle, uint32_t cmd, void *args)
Function performs implementation specific features on a given ECDSA_Handle.
CryptoKey datastructure.
Definition: CryptoKey.h:210
const uint8_t * r
Definition: ECDSA.h:588
ECDSA_Handle ECDSA_open(uint_least8_t index, ECDSA_Params *params)
This function opens a given ECDSA peripheral.
void ECDSA_close(ECDSA_Handle handle)
Function to close an ECDSA peripheral specified by the ECDSA handle.
A structure containing the parameters of an elliptic curve in short Weierstrass form.
Definition: ECCParams.h:111
const ECCParams_CurveParams * curve
Definition: ECDSA.h:552
void ECDSA_init(void)
This function initializes the ECDSA module.
ECDSA Parameters.
Definition: ECDSA.h:645
ECDSA_CallbackFxn callbackFxn
Definition: ECDSA.h:647
ECDSA_ReturnBehavior_
The way in which ECDSA function calls return after performing an encryption + authentication or decry...
Definition: ECDSA.h:512
const uint8_t * hash
Definition: ECDSA.h:585
struct ECDSA_Params_ ECDSA_Params
ECDSA Parameters.
const CryptoKey * myPrivateKey
Definition: ECDSA.h:553
Definition: ECDSA.h:513
ECDSA Global configuration.
Definition: ECDSA.h:540
void ECDSA_Params_init(ECDSA_Params *params)
Function to initialize the ECDSA_Params struct to its defaults.
Definition: ECDSA.h:611
ECDSA_OperationType_
Enum for the operation types supported by the driver.
Definition: ECDSA.h:609
uint8_t * s
Definition: ECDSA.h:570
struct ECDSA_OperationSign_ ECDSA_OperationSign
Struct containing the parameters required for signing a message.
int_fast16_t ECDSA_sign(ECDSA_Handle handle, ECDSA_OperationSign *operation)
Signs a hashed message.
int_fast16_t ECDSA_verify(ECDSA_Handle handle, ECDSA_OperationVerify *operation)
Verifies a received signature matches a hash and public key.
uint8_t * r
Definition: ECDSA.h:565
void * custom
Definition: ECDSA.h:651
Definition: ECDSA.h:523
const CryptoKey * theirPublicKey
Definition: ECDSA.h:582
uint32_t timeout
Definition: ECDSA.h:648
struct ECDSA_Config_ ECDSA_Config
ECDSA Global configuration.
union ECDSA_Operation_ ECDSA_Operation
Union containing pointers to all supported operation structs.
struct ECDSA_Config_ * ECDSA_Handle
A handle that is returned from an ECDSA_open() call.
Definition: ECDSA.h:489
Struct containing the parameters required for verifying a message.
Definition: ECDSA.h:580
Definition: ECDSA.h:610
enum ECDSA_OperationType_ ECDSA_OperationType
Enum for the operation types supported by the driver.
void ECDSA_OperationVerify_init(ECDSA_OperationVerify *operation)
Function to initialize an ECDSA_OperationSign struct to its defaults.
Definition: ECDSA.h:519
const CryptoKey * pmsn
Definition: ECDSA.h:556
const ECCParams_CurveParams * curve
Definition: ECDSA.h:581
ECDSA_OperationSign * sign
Definition: ECDSA.h:602
const uint8_t * hash
Definition: ECDSA.h:562
Copyright 2018, Texas Instruments Incorporated