TI-RTOS for SimpleLink Wireless MCUs  2.14.03.28
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  */
247 #ifndef ti_drivers_crypto_CryptoCC26XX__include
248 #define ti_drivers_crypto_CryptoCC26XX__include
249 
250 #ifdef __cplusplus
251 extern "C" {
252 #endif
253 
254 #include <stdint.h>
255 #include <stdbool.h>
256 #include <ti/sysbios/family/arm/cc26xx/Power.h>
257 #include <driverlib/crypto.h>
258 
259 #define CRYPTOCC26XX_TIMEOUT 20
261 #define CRYPTOCC26XX_STATUS_SUCCESS 0
262 #define CRYPTOCC26XX_STATUS_ERROR -1
263 #define CRYPTOCC26XX_STATUS_UNDEFINEDCMD -2
265 #define CRYPTOCC26XX_OP_AES_CCM 0
266 #define CRYPTOCC26XX_OP_AES_CCM_NOCRYPT 1
267 #define CRYPTOCC26XX_OP_AES_CCMINV 2
268 #define CRYPTOCC26XX_OP_AES_CCMINV_NOCRYPT 3
269 #define CRYPTOCC26XX_OP_AES_ECB 4
270 #define CRYPTOCC26XX_OP_AES_ECB_NOCRYPT 5
273 #define OP_TYPE(x) ((x)&0xFE)
274 
275 #define DO_CRYPT(x) ((x)&0x01?false:true)
276 
277 /*
278  * The following allows this header file to be included in an application file
279  * which also includes ti/sysbios/hal/Hwi.h.
280  */
281 #define ti_sysbios_family_arm_m3_Hwi__nolocalnames
282 #include <ti/sysbios/family/arm/m3/Hwi.h>
283 #include <ti/sysbios/knl/Semaphore.h>
284 
289 
296 typedef enum CryptoCC26XX_Mode {
302 
309 
320 typedef uint8_t CryptoCC26XX_Operation;
321 
340 
344 typedef struct CryptoCC26XX_Params {
345  uint32_t timeout;
347 
353 typedef uint8_t CryptoCC26XX_KeyStore;
354 
364 typedef struct CryptoCC26XX_Transaction {
365  CryptoCC26XX_Operation opType;
367  uint8_t data[];
369 
377  CryptoCC26XX_Operation opType;
379  uint8_t keyIndex;
380  uint8_t authLength;
382  char *nonce;
383  char *msgIn;
384  char *header;
385  void *msgOut;
386  uint8_t fieldLength;
387  uint16_t msgInLength;
388  uint16_t headerLength;
390 
398  CryptoCC26XX_Operation opType;
400  uint8_t keyIndex;
401  void *msgIn;
402  void *msgOut;
404 
436 typedef struct CryptoCC26XX_HWAttrs {
438  uint32_t baseAddr;
442  int intNum;
455  uint8_t intPriority;
457 
463 typedef struct CryptoCC26XX_Object {
464  /* CryptoCC26XX control variables */
465  int openCnt;
466  uint32_t timeout;
467  CryptoCC26XX_KeyStore keyStore;
470  /* Crypto transaction pointers for CryptoCC26XX_MODE_CALLBACK */
476 
477  /* CryptoCC26XX SYS/BIOS objects */
478  ti_sysbios_family_arm_m3_Hwi_Struct hwi;
479  Semaphore_Struct transSem;
480  Semaphore_Struct waitSem;
482 
484 typedef struct CryptoCC26XX_Config {
486  void *object;
487 
489  void const *hwAttrs;
491 
506 int CryptoCC26XX_close(CryptoCC26XX_Handle handle);
507 
515 void CryptoCC26XX_init(void);
516 
540 CryptoCC26XX_Handle CryptoCC26XX_open(unsigned int index, bool exclusiveAccess, CryptoCC26XX_Params *params);
541 
553 
564 void CryptoCC26XX_Transac_init(CryptoCC26XX_Transaction *trans, CryptoCC26XX_Operation opType);
565 
591 int CryptoCC26XX_allocateKey(CryptoCC26XX_Handle handle, CryptoCC26XX_KeyLocation keyLocation, const uint32_t *keySrc);
592 
610 int CryptoCC26XX_releaseKey(CryptoCC26XX_Handle handle, int *keyIndex);
611 
632 int CryptoCC26XX_transact(CryptoCC26XX_Handle handle, CryptoCC26XX_Transaction *transaction);
633 
653 int CryptoCC26XX_transactPolling(CryptoCC26XX_Handle handle, CryptoCC26XX_Transaction *transaction);
654 
678 int CryptoCC26XX_transactCallback(CryptoCC26XX_Handle handle, CryptoCC26XX_Transaction *transaction);
679 
680 
681 /* Do not interfere with the app if they include the family Hwi module */
682 #undef ti_sysbios_family_arm_m3_Hwi__nolocalnames
683 
684 #ifdef __cplusplus
685 }
686 #endif
687 
688 #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:364
Semaphore_Struct waitSem
Definition: CryptoCC26XX.h:480
CryptoCC26XX Global Configuration.
Definition: CryptoCC26XX.h:484
CryptoCC26XX_Transaction * currentTransact
Definition: CryptoCC26XX.h:468
void CryptoCC26XX_Params_init(CryptoCC26XX_Params *params)
Function to initialize the CryptoCC26XX_Params struct to its defaults.
CryptoCC26XX AES-CCM Transaction.
Definition: CryptoCC26XX.h:376
struct CryptoCC26XX_Object CryptoCC26XX_Object
CryptoCC26XX Object.
CryptoCC26XX_Operation opType
Definition: CryptoCC26XX.h:398
int CryptoCC26XX_close(CryptoCC26XX_Handle handle)
Function to closes a given CryptoCC26XX peripheral specified by the CryptoCC26XX handle.
void * msgOut
Definition: CryptoCC26XX.h:385
struct CryptoCC26XX_AESCCM_Transaction CryptoCC26XX_AESCCM_Transaction
CryptoCC26XX AES-CCM Transaction.
CryptoCC26XX_Transaction * tailPtr
Definition: CryptoCC26XX.h:472
CryptoCC26XX Parameters.
Definition: CryptoCC26XX.h:344
uint8_t keyIndex
Definition: CryptoCC26XX.h:400
CryptoCC26XX_Operation opType
Definition: CryptoCC26XX.h:377
Definition: CryptoCC26XX.h:330
uint8_t CryptoCC26XX_Operation
CryptoCC26XX Operation Type.
Definition: CryptoCC26XX.h:320
uint8_t fieldLength
Definition: CryptoCC26XX.h:386
Definition: CryptoCC26XX.h:333
CryptoCC26XX_Operation opType
Definition: CryptoCC26XX.h:365
uint8_t data[]
Definition: CryptoCC26XX.h:367
Definition: CryptoCC26XX.h:301
CryptoCC26XX_Transaction * headPtr
Definition: CryptoCC26XX.h:471
void * msgOut
Definition: CryptoCC26XX.h:402
uint8_t keyIndex
Definition: CryptoCC26XX.h:379
char * nonce
Definition: CryptoCC26XX.h:382
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:336
char * header
Definition: CryptoCC26XX.h:384
CryptoCC26XX Hardware Attributes.
Definition: CryptoCC26XX.h:436
Power_NotifyObj cryptoNotiObj
Definition: CryptoCC26XX.h:475
int openCnt
Definition: CryptoCC26XX.h:465
ti_sysbios_family_arm_m3_Hwi_Struct hwi
Definition: CryptoCC26XX.h:478
Definition: CryptoCC26XX.h:335
void const * hwAttrs
Definition: CryptoCC26XX.h:489
uint16_t headerLength
Definition: CryptoCC26XX.h:388
Definition: CryptoCC26XX.h:307
uint16_t msgInLength
Definition: CryptoCC26XX.h:387
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:288
void * msgIn
Definition: CryptoCC26XX.h:401
Power notify object structure.
Definition: Power.h:112
uint32_t timeout
Definition: CryptoCC26XX.h:466
Definition: CryptoCC26XX.h:337
CryptoCC26XX_Mode
CryptoCC26XX Mode Settings.
Definition: CryptoCC26XX.h:296
CryptoCC26XX AES-ECB Transaction.
Definition: CryptoCC26XX.h:397
char * msgIn
Definition: CryptoCC26XX.h:383
void CryptoCC26XX_init(void)
Function to initializes bios modules needed by CryptoCC26XX module.
uint8_t intPriority
Crypto Peripheral's interrupt priority.
Definition: CryptoCC26XX.h:455
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:467
int powerMngrId
Definition: CryptoCC26XX.h:440
void * object
Definition: CryptoCC26XX.h:486
Semaphore_Struct transSem
Definition: CryptoCC26XX.h:479
Definition: CryptoCC26XX.h:338
Definition: CryptoCC26XX.h:332
uint8_t CryptoCC26XX_KeyStore
CryptoCC26XX Key.
Definition: CryptoCC26XX.h:353
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:399
CryptoCC26XX_KeyLocation
CryptoCC26XX Key Store Location.
Definition: CryptoCC26XX.h:328
int intNum
Definition: CryptoCC26XX.h:442
struct CryptoCC26XX_HWAttrs CryptoCC26XX_HWAttrs
CryptoCC26XX Hardware Attributes.
CryptoCC26XX_Mode mode
Definition: CryptoCC26XX.h:366
Definition: CryptoCC26XX.h:334
struct CryptoCC26XX_Transaction CryptoCC26XX_Transaction
CryptoCC26XX Transaction.
uint32_t timeout
Definition: CryptoCC26XX.h:345
CryptoCC26XX Object.
Definition: CryptoCC26XX.h:463
CryptoCC26XX_Mode mode
Definition: CryptoCC26XX.h:378
uint32_t baseAddr
Definition: CryptoCC26XX.h:438
struct CryptoCC26XX_AESECB_Transaction CryptoCC26XX_AESECB_Transaction
CryptoCC26XX AES-ECB Transaction.
Definition: CryptoCC26XX.h:331
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:380
Definition: CryptoCC26XX.h:329
Copyright 2015, Texas Instruments Incorporated