ECDH.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017, 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  */
303 #ifndef ti_drivers_ECDH__include
304 #define ti_drivers_ECDH__include
305 
306 #ifdef __cplusplus
307 extern "C" {
308 #endif
309 
310 #include <stdbool.h>
311 #include <stddef.h>
312 #include <stdint.h>
313 
316 
334 #define ECDH_CMD_RESERVED (32)
335 
348 #define ECDH_STATUS_RESERVED (-32)
349 
363 #define ECDH_STATUS_SUCCESS (0)
364 
371 #define ECDH_STATUS_ERROR (-1)
372 
380 #define ECDH_STATUS_UNDEFINEDCMD (-2)
381 
390 #define ECDH_STATUS_RESOURCE_UNAVAILABLE (-3)
391 
398 #define ECDH_STATUS_RESULT_POINT_AT_INFINITY (-4)
399 
406 #define ECDH_STATUS_RESULT_PRIVATE_KEY_LARGER_THAN_ORDER (-5)
407 
414 #define ECDH_STATUS_RESULT_PUBLIC_KEY_NOT_ON_CURVE (-6)
415 
416 
427 /* Add ECDH_CMD_<commands> here */
428 
436 typedef struct ECDH_Config_ *ECDH_Handle;
437 
447 typedef void (*ECDH_CallbackFxn) (ECDH_Handle handle, int_fast16_t operationStatus);
448 
470 typedef enum ECDH_ReturnBehavior_ {
486 
495 typedef struct ECDH_Params_ {
499  uint32_t timeout;
500  void *custom;
503 } ECDH_Params;
504 
516 typedef struct ECDH_Config_ {
518  void *object;
519 
521  void const *hwAttrs;
522 } ECDH_Config;
523 
544 typedef int_fast16_t (*ECDH_KDFFxn) (void *driverHandle, const uint8_t *seedEntropy, size_t seedEntropyLength, CryptoKey derivedKeys[], uint32_t derivedKeysCount);
545 
551 extern const ECDH_Params ECDH_defaultParams;
552 
561 void ECDH_init(void);
562 
575 void ECDH_Params_init(ECDH_Params *params);
576 
594 ECDH_Handle ECDH_open(uint_least8_t index, ECDH_Params *params);
595 
605 void ECDH_close(ECDH_Handle handle);
606 
644 int_fast16_t ECDH_control(ECDH_Handle handle, uint32_t cmd, void *args);
645 
646 
647 
648 
649 
664 int_fast16_t ECDH_generatePublicKey(ECDH_Handle handle, const ECCParams_CurveParams *eccParams, const CryptoKey *myPrivateKey, CryptoKey *myPublicKey);
665 
679 int_fast16_t ECDH_computeSharedSecret(ECDH_Handle handle, const ECCParams_CurveParams *eccParams, const CryptoKey *myPrivateKey, const CryptoKey *theirPublicKey, CryptoKey *sharedSecret);
680 
699 int_fast16_t ECDH_calculateSharedEntropy(ECDH_Handle handle, const CryptoKey *sharedSecret, const ECDH_KDFFxn kdf, void *kdfPrimitiveDriverHandle, CryptoKey derivedKeys[], uint32_t derivedKeysCount);
700 
701 #ifdef __cplusplus
702 }
703 #endif
704 
705 #endif /* ti_drivers_ECDH__include */
ECDH_ReturnBehavior_
The way in which ECC function calls return after performing an encryption + authentication or decrypt...
Definition: ECDH.h:470
The CryptoKey type is an opaque representation of a cryptographic key.
int_fast16_t ECDH_calculateSharedEntropy(ECDH_Handle handle, const CryptoKey *sharedSecret, const ECDH_KDFFxn kdf, void *kdfPrimitiveDriverHandle, CryptoKey derivedKeys[], uint32_t derivedKeysCount)
Calculates key material.
ECDH_Handle ECDH_open(uint_least8_t index, ECDH_Params *params)
This function opens a given ECC peripheral.
ECC Parameters.
Definition: ECDH.h:495
void * custom
Definition: ECDH.h:500
struct ECDH_Params_ ECDH_Params
ECC Parameters.
ECDH_ReturnBehavior returnBehavior
Definition: ECDH.h:497
int_fast16_t ECDH_control(ECDH_Handle handle, uint32_t cmd, void *args)
Function performs implementation specific features on a given ECDH_Handle.
ECDH_CallbackFxn callbackFxn
Definition: ECDH.h:498
CryptoKey datastructure.
Definition: CryptoKey.h:210
A structure containing the parameters of an elliptic curve in short Weierstrass form.
Definition: ECCParams.h:70
void * object
Definition: ECDH.h:518
Definition: ECDH.h:481
int_fast16_t ECDH_computeSharedSecret(ECDH_Handle handle, const ECCParams_CurveParams *eccParams, const CryptoKey *myPrivateKey, const CryptoKey *theirPublicKey, CryptoKey *sharedSecret)
Computes a shared secret.
Definition: ECDH.h:477
const ECDH_Params ECDH_defaultParams
Default ECDH_Params structure.
Definition: ECDH.h:471
void ECDH_init(void)
This function initializes the ECC module.
void const * hwAttrs
Definition: ECDH.h:521
int_fast16_t ECDH_generatePublicKey(ECDH_Handle handle, const ECCParams_CurveParams *eccParams, const CryptoKey *myPrivateKey, CryptoKey *myPublicKey)
Generates a public key for use in key agreement.
struct ECDH_Config_ ECDH_Config
ECC Global configuration.
int_fast16_t(* ECDH_KDFFxn)(void *driverHandle, const uint8_t *seedEntropy, size_t seedEntropyLength, CryptoKey derivedKeys[], uint32_t derivedKeysCount)
Function that implements a key derivation function (KDF)
Definition: ECDH.h:544
ECC Global configuration.
Definition: ECDH.h:516
void ECDH_close(ECDH_Handle handle)
Function to close a ECC peripheral specified by the ECC handle.
struct ECDH_Config_ * ECDH_Handle
A handle that is returned from an ECDH_open() call.
Definition: ECDH.h:436
bool doNotValidateKeys
Definition: ECDH.h:496
void ECDH_Params_init(ECDH_Params *params)
Function to initialize the ECDH_Params struct to its defaults.
uint32_t timeout
Definition: ECDH.h:499
void(* ECDH_CallbackFxn)(ECDH_Handle handle, int_fast16_t operationStatus)
The definition of a callback function used by the ECC driver when used in ECDH_RETURN_BEHAVIOR_CALLBA...
Definition: ECDH.h:447
enum ECDH_ReturnBehavior_ ECDH_ReturnBehavior
The way in which ECC function calls return after performing an encryption + authentication or decrypt...
Copyright 2017, Texas Instruments Incorporated