TI-RTOS Drivers  tidrivers_cc13xx_cc26xx_2_16_00_08
CryptoCC26XX.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2016, 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  */
256 #ifndef ti_drivers_crypto_CryptoCC26XX__include
257 #define ti_drivers_crypto_CryptoCC26XX__include
258 
259 #ifdef __cplusplus
260 extern "C" {
261 #endif
262 
263 #include <stdint.h>
264 #include <stdbool.h>
265 #include <ti/drivers/Power.h>
266 #include <driverlib/crypto.h>
267 
278 /* Add CryptoCC26XX_STATUS_* macros here */
279 
292 /* Add CryptoCC26XX_CMD_* macros here */
293 
296 #define CRYPTOCC26XX_TIMEOUT 20
298 #define CRYPTOCC26XX_STATUS_SUCCESS 0
299 #define CRYPTOCC26XX_STATUS_ERROR -1
300 #define CRYPTOCC26XX_STATUS_UNDEFINEDCMD -2
302 #define CRYPTOCC26XX_OP_AES_CCM 0
303 #define CRYPTOCC26XX_OP_AES_CCM_NOCRYPT 1
304 #define CRYPTOCC26XX_OP_AES_CCMINV 2
305 #define CRYPTOCC26XX_OP_AES_CCMINV_NOCRYPT 3
306 #define CRYPTOCC26XX_OP_AES_ECB 4
307 #define CRYPTOCC26XX_OP_AES_ECB_NOCRYPT 5
310 #define OP_TYPE(x) ((x)&0xFE)
311 
312 #define DO_CRYPT(x) ((x)&0x01?false:true)
313 
314 /*
315  * The following allows this header file to be included in an application file
316  * which also includes ti/sysbios/hal/Hwi.h.
317  */
318 #define ti_sysbios_family_arm_m3_Hwi__nolocalnames
319 #include <ti/sysbios/family/arm/m3/Hwi.h>
320 #include <ti/sysbios/knl/Semaphore.h>
321 
326 
333 typedef enum CryptoCC26XX_Mode {
339 
346 
357 typedef uint8_t CryptoCC26XX_Operation;
358 
377 
381 typedef struct CryptoCC26XX_Params {
382  uint32_t timeout;
384 
390 typedef uint8_t CryptoCC26XX_KeyStore;
391 
401 typedef struct CryptoCC26XX_Transaction {
402  CryptoCC26XX_Operation opType;
404  uint8_t data[];
406 
414  CryptoCC26XX_Operation opType;
416  uint8_t keyIndex;
417  uint8_t authLength;
419  char *nonce;
420  char *msgIn;
421  char *header;
422  void *msgOut;
423  uint8_t fieldLength;
424  uint16_t msgInLength;
425  uint16_t headerLength;
427 
435  CryptoCC26XX_Operation opType;
437  uint8_t keyIndex;
438  void *msgIn;
439  void *msgOut;
441 
473 typedef struct CryptoCC26XX_HWAttrs {
475  uint32_t baseAddr;
479  int intNum;
492  uint8_t intPriority;
494 
500 typedef struct CryptoCC26XX_Object {
501  /* CryptoCC26XX control variables */
502  int openCnt;
503  uint32_t timeout;
504  CryptoCC26XX_KeyStore keyStore;
507  /* Crypto transaction pointers for CryptoCC26XX_MODE_CALLBACK */
513 
514  /* CryptoCC26XX SYS/BIOS objects */
515  ti_sysbios_family_arm_m3_Hwi_Struct hwi;
516  Semaphore_Struct transSem;
517  Semaphore_Struct waitSem;
519 
521 typedef struct CryptoCC26XX_Config {
523  void *object;
524 
526  void const *hwAttrs;
528 
543 int CryptoCC26XX_close(CryptoCC26XX_Handle handle);
544 
552 void CryptoCC26XX_init(void);
553 
577 CryptoCC26XX_Handle CryptoCC26XX_open(unsigned int index, bool exclusiveAccess, CryptoCC26XX_Params *params);
578 
590 
601 void CryptoCC26XX_Transac_init(CryptoCC26XX_Transaction *trans, CryptoCC26XX_Operation opType);
602 
628 int CryptoCC26XX_allocateKey(CryptoCC26XX_Handle handle, CryptoCC26XX_KeyLocation keyLocation, const uint32_t *keySrc);
629 
647 int CryptoCC26XX_releaseKey(CryptoCC26XX_Handle handle, int *keyIndex);
648 
669 int CryptoCC26XX_transact(CryptoCC26XX_Handle handle, CryptoCC26XX_Transaction *transaction);
670 
690 int CryptoCC26XX_transactPolling(CryptoCC26XX_Handle handle, CryptoCC26XX_Transaction *transaction);
691 
715 int CryptoCC26XX_transactCallback(CryptoCC26XX_Handle handle, CryptoCC26XX_Transaction *transaction);
716 
717 
718 /* Do not interfere with the app if they include the family Hwi module */
719 #undef ti_sysbios_family_arm_m3_Hwi__nolocalnames
720 
721 #ifdef __cplusplus
722 }
723 #endif
724 
725 #endif /* ti_drivers_crypto_CryptoCC26XX__include */
int CryptoCC26XX_allocateKey(CryptoCC26XX_Handle handle, CryptoCC26XX_KeyLocation keyLocation, const uint32_t *keySrc)
Function that allocates key, writes key into key store RAM and returns a handle to CryptoCC26XX Key...
CryptoCC26XX Transaction.
Definition: CryptoCC26XX.h:401
Semaphore_Struct waitSem
Definition: CryptoCC26XX.h:517
CryptoCC26XX Global Configuration.
Definition: CryptoCC26XX.h:521
CryptoCC26XX_Transaction * currentTransact
Definition: CryptoCC26XX.h:505
void CryptoCC26XX_Params_init(CryptoCC26XX_Params *params)
Function to initialize the CryptoCC26XX_Params struct to its defaults.
CryptoCC26XX AES-CCM Transaction.
Definition: CryptoCC26XX.h:413
struct CryptoCC26XX_Object CryptoCC26XX_Object
CryptoCC26XX Object.
CryptoCC26XX_Operation opType
Definition: CryptoCC26XX.h:435
int CryptoCC26XX_close(CryptoCC26XX_Handle handle)
Function to closes a given CryptoCC26XX peripheral specified by the CryptoCC26XX handle.
void * msgOut
Definition: CryptoCC26XX.h:422
struct CryptoCC26XX_AESCCM_Transaction CryptoCC26XX_AESCCM_Transaction
CryptoCC26XX AES-CCM Transaction.
CryptoCC26XX_Transaction * tailPtr
Definition: CryptoCC26XX.h:509
CryptoCC26XX Parameters.
Definition: CryptoCC26XX.h:381
uint8_t keyIndex
Definition: CryptoCC26XX.h:437
CryptoCC26XX_Operation opType
Definition: CryptoCC26XX.h:414
Definition: CryptoCC26XX.h:367
Power manager interface.
uint8_t CryptoCC26XX_Operation
CryptoCC26XX Operation Type.
Definition: CryptoCC26XX.h:357
uint8_t fieldLength
Definition: CryptoCC26XX.h:423
Definition: CryptoCC26XX.h:370
CryptoCC26XX_Operation opType
Definition: CryptoCC26XX.h:402
uint8_t data[]
Definition: CryptoCC26XX.h:404
Definition: CryptoCC26XX.h:338
CryptoCC26XX_Transaction * headPtr
Definition: CryptoCC26XX.h:508
void * msgOut
Definition: CryptoCC26XX.h:439
uint8_t keyIndex
Definition: CryptoCC26XX.h:416
char * nonce
Definition: CryptoCC26XX.h:419
struct CryptoCC26XX_Config CryptoCC26XX_Config
CryptoCC26XX Global Configuration.
void CryptoCC26XX_Transac_init(CryptoCC26XX_Transaction *trans, CryptoCC26XX_Operation opType)
Function to initialize the CryptoCC26XX_Transaction struct to its defaults.
int CryptoCC26XX_releaseKey(CryptoCC26XX_Handle handle, int *keyIndex)
Function that releases the specified CryptoCC26XX Key.
Definition: CryptoCC26XX.h:373
char * header
Definition: CryptoCC26XX.h:421
CryptoCC26XX Hardware Attributes.
Definition: CryptoCC26XX.h:473
Power_NotifyObj cryptoNotiObj
Definition: CryptoCC26XX.h:512
int openCnt
Definition: CryptoCC26XX.h:502
ti_sysbios_family_arm_m3_Hwi_Struct hwi
Definition: CryptoCC26XX.h:515
Definition: CryptoCC26XX.h:372
void const * hwAttrs
Definition: CryptoCC26XX.h:526
uint16_t headerLength
Definition: CryptoCC26XX.h:425
Definition: CryptoCC26XX.h:344
uint16_t msgInLength
Definition: CryptoCC26XX.h:424
struct CryptoCC26XX_Params CryptoCC26XX_Params
CryptoCC26XX Parameters.
struct CryptoCC26XX_Config * CryptoCC26XX_Handle
A handle that is returned from a CryptoCC26XX_open() call.
Definition: CryptoCC26XX.h:325
void * msgIn
Definition: CryptoCC26XX.h:438
Power notify object structure.
Definition: Power.h:112
uint32_t timeout
Definition: CryptoCC26XX.h:503
Definition: CryptoCC26XX.h:374
CryptoCC26XX_Mode
CryptoCC26XX Mode Settings.
Definition: CryptoCC26XX.h:333
CryptoCC26XX AES-ECB Transaction.
Definition: CryptoCC26XX.h:434
char * msgIn
Definition: CryptoCC26XX.h:420
void CryptoCC26XX_init(void)
Function to initializes bios modules needed by CryptoCC26XX module.
uint8_t intPriority
Crypto Peripheral's interrupt priority.
Definition: CryptoCC26XX.h:492
int CryptoCC26XX_transact(CryptoCC26XX_Handle handle, CryptoCC26XX_Transaction *transaction)
Function to do a Crypto operation (encryption or decryption) in blocking mode.
CryptoCC26XX_KeyStore keyStore
Definition: CryptoCC26XX.h:504
int powerMngrId
Definition: CryptoCC26XX.h:477
void * object
Definition: CryptoCC26XX.h:523
Semaphore_Struct transSem
Definition: CryptoCC26XX.h:516
Definition: CryptoCC26XX.h:375
Definition: CryptoCC26XX.h:369
uint8_t CryptoCC26XX_KeyStore
CryptoCC26XX Key.
Definition: CryptoCC26XX.h:390
CryptoCC26XX_Handle CryptoCC26XX_open(unsigned int index, bool exclusiveAccess, CryptoCC26XX_Params *params)
Function to initialize a given CryptoCC26XX peripheral specified by the particular index value...
CryptoCC26XX_Mode mode
Definition: CryptoCC26XX.h:436
CryptoCC26XX_KeyLocation
CryptoCC26XX Key Store Location.
Definition: CryptoCC26XX.h:365
int intNum
Definition: CryptoCC26XX.h:479
struct CryptoCC26XX_HWAttrs CryptoCC26XX_HWAttrs
CryptoCC26XX Hardware Attributes.
CryptoCC26XX_Mode mode
Definition: CryptoCC26XX.h:403
Definition: CryptoCC26XX.h:371
struct CryptoCC26XX_Transaction CryptoCC26XX_Transaction
CryptoCC26XX Transaction.
uint32_t timeout
Definition: CryptoCC26XX.h:382
CryptoCC26XX Object.
Definition: CryptoCC26XX.h:500
CryptoCC26XX_Mode mode
Definition: CryptoCC26XX.h:415
uint32_t baseAddr
Definition: CryptoCC26XX.h:475
struct CryptoCC26XX_AESECB_Transaction CryptoCC26XX_AESECB_Transaction
CryptoCC26XX AES-ECB Transaction.
Definition: CryptoCC26XX.h:368
int CryptoCC26XX_transactPolling(CryptoCC26XX_Handle handle, CryptoCC26XX_Transaction *transaction)
Function to do a Crypto transaction operation (encryption or decryption) in polling mode...
int CryptoCC26XX_transactCallback(CryptoCC26XX_Handle handle, CryptoCC26XX_Transaction *transaction)
Function to do a Crypto transaction operation (encryption or decryption) in callback mode...
uint8_t authLength
Definition: CryptoCC26XX.h:417
Definition: CryptoCC26XX.h:366
Copyright 2016, Texas Instruments Incorporated