TI-RTOS for SimpleLink Wireless MCUs  2.14.02.22
CryptoCC26XX.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015, 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  */
243 #ifndef ti_drivers_crypto_CryptoCC26XX__include
244 #define ti_drivers_crypto_CryptoCC26XX__include
245 
246 #ifdef __cplusplus
247 extern "C" {
248 #endif
249 
250 #include <stdint.h>
251 #include <stdbool.h>
252 #include <ti/sysbios/family/arm/cc26xx/Power.h>
253 #include <driverlib/crypto.h>
254 
255 #define CRYPTOCC26XX_TIMEOUT 20
257 #define CRYPTOCC26XX_STATUS_SUCCESS 0
258 #define CRYPTOCC26XX_STATUS_ERROR -1
259 #define CRYPTOCC26XX_STATUS_UNDEFINEDCMD -2
261 #define CRYPTOCC26XX_OP_AES_CCM 0
262 #define CRYPTOCC26XX_OP_AES_CCM_NOCRYPT 1
263 #define CRYPTOCC26XX_OP_AES_CCMINV 2
264 #define CRYPTOCC26XX_OP_AES_CCMINV_NOCRYPT 3
265 #define CRYPTOCC26XX_OP_AES_ECB 4
266 #define CRYPTOCC26XX_OP_AES_ECB_NOCRYPT 5
269 #define OP_TYPE(x) ((x)&0xFE)
270 
271 #define DO_CRYPT(x) ((x)&0x01?false:true)
272 
273 /*
274  * The following allows this header file to be included in an application file
275  * which also includes ti/sysbios/hal/Hwi.h.
276  */
277 #define ti_sysbios_family_arm_m3_Hwi__nolocalnames
278 #include <ti/sysbios/family/arm/m3/Hwi.h>
279 #include <ti/sysbios/knl/Semaphore.h>
280 
285 
292 typedef enum CryptoCC26XX_Mode {
298 
305 
316 typedef uint8_t CryptoCC26XX_Operation;
317 
336 
340 typedef struct CryptoCC26XX_Params {
341  uint32_t timeout;
343 
349 typedef uint8_t CryptoCC26XX_KeyStore;
350 
360 typedef struct CryptoCC26XX_Transaction {
361  CryptoCC26XX_Operation opType;
363  uint8_t data[];
365 
373  CryptoCC26XX_Operation opType;
375  uint8_t keyIndex;
376  uint8_t authLength;
378  char *nonce;
379  char *msgIn;
380  char *header;
381  void *msgOut;
382  uint8_t fieldLength;
383  uint16_t msgInLength;
384  uint16_t headerLength;
386 
394  CryptoCC26XX_Operation opType;
396  uint8_t keyIndex;
397  void *msgIn;
398  void *msgOut;
400 
421 typedef struct CryptoCC26XX_HWAttrs {
423  uint32_t baseAddr;
427  int intNum;
434  uint8_t intPriority;
436 
442 typedef struct CryptoCC26XX_Object {
443  /* CryptoCC26XX control variables */
444  int openCnt;
445  uint32_t timeout;
446  CryptoCC26XX_KeyStore keyStore;
449  /* Crypto transaction pointers for CryptoCC26XX_MODE_CALLBACK */
455 
456  /* CryptoCC26XX SYS/BIOS objects */
457  ti_sysbios_family_arm_m3_Hwi_Struct hwi;
458  Semaphore_Struct transSem;
459  Semaphore_Struct waitSem;
461 
463 typedef struct CryptoCC26XX_Config {
465  void *object;
466 
468  void const *hwAttrs;
470 
485 int CryptoCC26XX_close(CryptoCC26XX_Handle handle);
486 
494 void CryptoCC26XX_init(void);
495 
519 CryptoCC26XX_Handle CryptoCC26XX_open(unsigned int index, bool exclusiveAccess, CryptoCC26XX_Params *params);
520 
532 
543 void CryptoCC26XX_Transac_init(CryptoCC26XX_Transaction *trans, CryptoCC26XX_Operation opType);
544 
570 int CryptoCC26XX_allocateKey(CryptoCC26XX_Handle handle, CryptoCC26XX_KeyLocation keyLocation, const uint32_t *keySrc);
571 
589 int CryptoCC26XX_releaseKey(CryptoCC26XX_Handle handle, int *keyIndex);
590 
611 int CryptoCC26XX_transact(CryptoCC26XX_Handle handle, CryptoCC26XX_Transaction *transaction);
612 
632 int CryptoCC26XX_transactPolling(CryptoCC26XX_Handle handle, CryptoCC26XX_Transaction *transaction);
633 
657 int CryptoCC26XX_transactCallback(CryptoCC26XX_Handle handle, CryptoCC26XX_Transaction *transaction);
658 
659 
660 /* Do not interfere with the app if they include the family Hwi module */
661 #undef ti_sysbios_family_arm_m3_Hwi__nolocalnames
662 
663 #ifdef __cplusplus
664 }
665 #endif
666 
667 #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:360
Semaphore_Struct waitSem
Definition: CryptoCC26XX.h:459
CryptoCC26XX Global Configuration.
Definition: CryptoCC26XX.h:463
CryptoCC26XX_Transaction * currentTransact
Definition: CryptoCC26XX.h:447
void CryptoCC26XX_Params_init(CryptoCC26XX_Params *params)
Function to initialize the CryptoCC26XX_Params struct to its defaults.
CryptoCC26XX AES-CCM Transaction.
Definition: CryptoCC26XX.h:372
struct CryptoCC26XX_Object CryptoCC26XX_Object
CryptoCC26XX Object.
CryptoCC26XX_Operation opType
Definition: CryptoCC26XX.h:394
int CryptoCC26XX_close(CryptoCC26XX_Handle handle)
Function to closes a given CryptoCC26XX peripheral specified by the CryptoCC26XX handle.
void * msgOut
Definition: CryptoCC26XX.h:381
struct CryptoCC26XX_AESCCM_Transaction CryptoCC26XX_AESCCM_Transaction
CryptoCC26XX AES-CCM Transaction.
CryptoCC26XX_Transaction * tailPtr
Definition: CryptoCC26XX.h:451
CryptoCC26XX Parameters.
Definition: CryptoCC26XX.h:340
uint8_t keyIndex
Definition: CryptoCC26XX.h:396
CryptoCC26XX_Operation opType
Definition: CryptoCC26XX.h:373
Definition: CryptoCC26XX.h:326
uint8_t CryptoCC26XX_Operation
CryptoCC26XX Operation Type.
Definition: CryptoCC26XX.h:316
uint8_t fieldLength
Definition: CryptoCC26XX.h:382
Definition: CryptoCC26XX.h:329
CryptoCC26XX_Operation opType
Definition: CryptoCC26XX.h:361
uint8_t data[]
Definition: CryptoCC26XX.h:363
Definition: CryptoCC26XX.h:297
CryptoCC26XX_Transaction * headPtr
Definition: CryptoCC26XX.h:450
void * msgOut
Definition: CryptoCC26XX.h:398
uint8_t keyIndex
Definition: CryptoCC26XX.h:375
char * nonce
Definition: CryptoCC26XX.h:378
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:332
char * header
Definition: CryptoCC26XX.h:380
CryptoCC26XX Hardware Attributes.
Definition: CryptoCC26XX.h:421
Power_NotifyObj cryptoNotiObj
Definition: CryptoCC26XX.h:454
int openCnt
Definition: CryptoCC26XX.h:444
ti_sysbios_family_arm_m3_Hwi_Struct hwi
Definition: CryptoCC26XX.h:457
Definition: CryptoCC26XX.h:331
void const * hwAttrs
Definition: CryptoCC26XX.h:468
uint16_t headerLength
Definition: CryptoCC26XX.h:384
Definition: CryptoCC26XX.h:303
uint16_t msgInLength
Definition: CryptoCC26XX.h:383
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:284
void * msgIn
Definition: CryptoCC26XX.h:397
Power notify object structure.
Definition: Power.h:112
uint32_t timeout
Definition: CryptoCC26XX.h:445
Definition: CryptoCC26XX.h:333
CryptoCC26XX_Mode
CryptoCC26XX Mode Settings.
Definition: CryptoCC26XX.h:292
CryptoCC26XX AES-ECB Transaction.
Definition: CryptoCC26XX.h:393
char * msgIn
Definition: CryptoCC26XX.h:379
void CryptoCC26XX_init(void)
Function to initializes bios modules needed by CryptoCC26XX module.
uint8_t intPriority
Crypto Peripheral's interrupt priority.
Definition: CryptoCC26XX.h:434
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:446
int powerMngrId
Definition: CryptoCC26XX.h:425
void * object
Definition: CryptoCC26XX.h:465
Semaphore_Struct transSem
Definition: CryptoCC26XX.h:458
Definition: CryptoCC26XX.h:334
Definition: CryptoCC26XX.h:328
uint8_t CryptoCC26XX_KeyStore
CryptoCC26XX Key.
Definition: CryptoCC26XX.h:349
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:395
CryptoCC26XX_KeyLocation
CryptoCC26XX Key Store Location.
Definition: CryptoCC26XX.h:324
int intNum
Definition: CryptoCC26XX.h:427
struct CryptoCC26XX_HWAttrs CryptoCC26XX_HWAttrs
CryptoCC26XX Hardware Attributes.
CryptoCC26XX_Mode mode
Definition: CryptoCC26XX.h:362
Definition: CryptoCC26XX.h:330
struct CryptoCC26XX_Transaction CryptoCC26XX_Transaction
CryptoCC26XX Transaction.
uint32_t timeout
Definition: CryptoCC26XX.h:341
CryptoCC26XX Object.
Definition: CryptoCC26XX.h:442
CryptoCC26XX_Mode mode
Definition: CryptoCC26XX.h:374
uint32_t baseAddr
Definition: CryptoCC26XX.h:423
struct CryptoCC26XX_AESECB_Transaction CryptoCC26XX_AESECB_Transaction
CryptoCC26XX AES-ECB Transaction.
Definition: CryptoCC26XX.h:327
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:376
Definition: CryptoCC26XX.h:325
Copyright 2015, Texas Instruments Incorporated