TI-RTOS Drivers  tidrivers_full_2_20_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  */
258 #ifndef ti_drivers_crypto_CryptoCC26XX__include
259 #define ti_drivers_crypto_CryptoCC26XX__include
260 
261 #ifdef __cplusplus
262 extern "C" {
263 #endif
264 
265 #include <stdint.h>
266 #include <stdbool.h>
267 #include <ti/drivers/Power.h>
268 #include <driverlib/crypto.h>
269 
280 /* Add CryptoCC26XX_STATUS_* macros here */
281 
294 /* Add CryptoCC26XX_CMD_* macros here */
295 
298 #define CRYPTOCC26XX_TIMEOUT 20
300 #define CRYPTOCC26XX_STATUS_SUCCESS 0
301 #define CRYPTOCC26XX_STATUS_ERROR -1
302 #define CRYPTOCC26XX_STATUS_UNDEFINEDCMD -2
304 #define CRYPTOCC26XX_OP_AES_CCM_ENCRYPT 0
305 #define CRYPTOCC26XX_OP_AES_CCM_ENCRYPT_AAD_ONLY 1
306 #define CRYPTOCC26XX_OP_AES_CCM_DECRYPT 2
307 #define CRYPTOCC26XX_OP_AES_CCM_DECRYPT_AAD_ONLY 3
308 #define CRYPTOCC26XX_OP_AES_ECB_ENCRYPT 4
309 #define CRYPTOCC26XX_OP_AES_ECB_DECRYPT 5
310 #define CRYPTOCC26XX_OP_AES_CBC_ENCRYPT 6
311 #define CRYPTOCC26XX_OP_AES_CBC_DECRYPT 7
313 /* Deprecated operation mode names */
314 #define CRYPTOCC26XX_OP_AES_CCM CRYPTOCC26XX_OP_AES_CCM_ENCRYPT
315 #define CRYPTOCC26XX_OP_AES_CCM_NOCRYPT CRYPTOCC26XX_OP_AES_CCM_ENCRYPT_AAD_ONLY
316 #define CRYPTOCC26XX_OP_AES_CCMINV CRYPTOCC26XX_OP_AES_CCM_DECRYPT
317 #define CRYPTOCC26XX_OP_AES_CCMINV_NOCRYPT CRYPTOCC26XX_OP_AES_CCM_DECRYPT_AAD_ONLY
318 #define CRYPTOCC26XX_OP_AES_ECB CRYPTOCC26XX_OP_AES_ECB_ENCRYPT
319 #define CRYPTOCC26XX_OP_AES_ECB_NOCRYPT CRYPTOCC26XX_OP_AES_ECB_DECRYPT
320 
321 
322 /*
323  * The following allows this header file to be included in an application file
324  * which also includes ti/sysbios/hal/Hwi.h.
325  */
326 #define ti_sysbios_family_arm_m3_Hwi__nolocalnames
327 #include <ti/sysbios/family/arm/m3/Hwi.h>
328 #include <ti/sysbios/knl/Semaphore.h>
329 
334 
341 typedef enum CryptoCC26XX_Mode {
347 
354 
369 typedef uint8_t CryptoCC26XX_Operation;
370 
389 
393 typedef struct CryptoCC26XX_Params {
394  uint32_t timeout;
396 
402 typedef uint8_t CryptoCC26XX_KeyStore;
403 
413 typedef struct CryptoCC26XX_Transaction {
414  CryptoCC26XX_Operation opType;
416  uint8_t data[];
418 
426  CryptoCC26XX_Operation opType;
428  uint8_t keyIndex;
429  uint8_t authLength;
431  char *nonce;
432  char *msgIn;
433  char *header;
434  void *msgOut;
435  uint8_t fieldLength;
436  uint16_t msgInLength;
437  uint16_t headerLength;
439 
447  CryptoCC26XX_Operation opType;
449  uint8_t keyIndex;
450  void *nonce;
451  void *msgIn;
452  void *msgOut;
453  uint16_t msgInLength;
455 
463  CryptoCC26XX_Operation opType;
465  uint8_t keyIndex;
466  void *msgIn;
467  void *msgOut;
469 
501 typedef struct CryptoCC26XX_HWAttrs {
503  uint32_t baseAddr;
507  int intNum;
520  uint8_t intPriority;
522 
528 typedef struct CryptoCC26XX_Object {
529  /* CryptoCC26XX control variables */
530  int openCnt;
531  uint32_t timeout;
532  CryptoCC26XX_KeyStore keyStore;
535  /* Crypto transaction pointers for CryptoCC26XX_MODE_CALLBACK */
541 
542  /* CryptoCC26XX SYS/BIOS objects */
543  ti_sysbios_family_arm_m3_Hwi_Struct hwi;
544  Semaphore_Struct transSem;
545  Semaphore_Struct waitSem;
547 
549 typedef struct CryptoCC26XX_Config {
551  void *object;
552 
554  void const *hwAttrs;
556 
571 int CryptoCC26XX_close(CryptoCC26XX_Handle handle);
572 
580 void CryptoCC26XX_init(void);
581 
605 CryptoCC26XX_Handle CryptoCC26XX_open(unsigned int index, bool exclusiveAccess, CryptoCC26XX_Params *params);
606 
618 
629 void CryptoCC26XX_Transac_init(CryptoCC26XX_Transaction *trans, CryptoCC26XX_Operation opType);
630 
658 int CryptoCC26XX_allocateKey(CryptoCC26XX_Handle handle, CryptoCC26XX_KeyLocation keyLocation, const uint32_t *keySrc);
659 
660 
681 int CryptoCC26XX_loadKey(CryptoCC26XX_Handle handle, int keyIndex, const uint32_t *keySrc);
682 
700 int CryptoCC26XX_releaseKey(CryptoCC26XX_Handle handle, int *keyIndex);
701 
722 int CryptoCC26XX_transact(CryptoCC26XX_Handle handle, CryptoCC26XX_Transaction *transaction);
723 
743 int CryptoCC26XX_transactPolling(CryptoCC26XX_Handle handle, CryptoCC26XX_Transaction *transaction);
744 
768 int CryptoCC26XX_transactCallback(CryptoCC26XX_Handle handle, CryptoCC26XX_Transaction *transaction);
769 
770 
771 /* Do not interfere with the app if they include the family Hwi module */
772 #undef ti_sysbios_family_arm_m3_Hwi__nolocalnames
773 
774 #ifdef __cplusplus
775 }
776 #endif
777 
778 #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:413
Semaphore_Struct waitSem
Definition: CryptoCC26XX.h:545
CryptoCC26XX Global Configuration.
Definition: CryptoCC26XX.h:549
CryptoCC26XX_Transaction * currentTransact
Definition: CryptoCC26XX.h:533
void CryptoCC26XX_Params_init(CryptoCC26XX_Params *params)
Function to initialize the CryptoCC26XX_Params struct to its defaults.
CryptoCC26XX AES-CCM Transaction.
Definition: CryptoCC26XX.h:425
struct CryptoCC26XX_Object CryptoCC26XX_Object
CryptoCC26XX Object.
CryptoCC26XX_Operation opType
Definition: CryptoCC26XX.h:463
int CryptoCC26XX_close(CryptoCC26XX_Handle handle)
Function to closes a given CryptoCC26XX peripheral specified by the CryptoCC26XX handle.
void * msgOut
Definition: CryptoCC26XX.h:434
struct CryptoCC26XX_AESCCM_Transaction CryptoCC26XX_AESCCM_Transaction
CryptoCC26XX AES-CCM Transaction.
CryptoCC26XX_Transaction * tailPtr
Definition: CryptoCC26XX.h:537
CryptoCC26XX Parameters.
Definition: CryptoCC26XX.h:393
uint8_t keyIndex
Definition: CryptoCC26XX.h:465
void * msgIn
Definition: CryptoCC26XX.h:451
CryptoCC26XX_Operation opType
Definition: CryptoCC26XX.h:426
Definition: CryptoCC26XX.h:379
Power manager interface.
uint8_t CryptoCC26XX_Operation
CryptoCC26XX Operation Type.
Definition: CryptoCC26XX.h:369
uint8_t fieldLength
Definition: CryptoCC26XX.h:435
Definition: CryptoCC26XX.h:382
CryptoCC26XX_Operation opType
Definition: CryptoCC26XX.h:414
uint8_t data[]
Definition: CryptoCC26XX.h:416
Definition: CryptoCC26XX.h:346
CryptoCC26XX_Transaction * headPtr
Definition: CryptoCC26XX.h:536
CryptoCC26XX_Operation opType
Definition: CryptoCC26XX.h:447
int CryptoCC26XX_loadKey(CryptoCC26XX_Handle handle, int keyIndex, const uint32_t *keySrc)
Function that writes a given key into a key store.
void * msgOut
Definition: CryptoCC26XX.h:467
uint8_t keyIndex
Definition: CryptoCC26XX.h:428
char * nonce
Definition: CryptoCC26XX.h:431
void * msgOut
Definition: CryptoCC26XX.h:452
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:385
char * header
Definition: CryptoCC26XX.h:433
CryptoCC26XX Hardware Attributes.
Definition: CryptoCC26XX.h:501
Power_NotifyObj cryptoNotiObj
Definition: CryptoCC26XX.h:540
int openCnt
Definition: CryptoCC26XX.h:530
ti_sysbios_family_arm_m3_Hwi_Struct hwi
Definition: CryptoCC26XX.h:543
Definition: CryptoCC26XX.h:384
void const * hwAttrs
Definition: CryptoCC26XX.h:554
uint16_t headerLength
Definition: CryptoCC26XX.h:437
Definition: CryptoCC26XX.h:352
uint16_t msgInLength
Definition: CryptoCC26XX.h:436
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:333
void * msgIn
Definition: CryptoCC26XX.h:466
Power notify object structure.
Definition: Power.h:112
uint32_t timeout
Definition: CryptoCC26XX.h:531
Definition: CryptoCC26XX.h:386
CryptoCC26XX_Mode
CryptoCC26XX Mode Settings.
Definition: CryptoCC26XX.h:341
CryptoCC26XX AES-ECB Transaction.
Definition: CryptoCC26XX.h:462
char * msgIn
Definition: CryptoCC26XX.h:432
void CryptoCC26XX_init(void)
Function to initializes bios modules needed by CryptoCC26XX module.
uint8_t intPriority
Crypto Peripheral's interrupt priority.
Definition: CryptoCC26XX.h:520
int CryptoCC26XX_transact(CryptoCC26XX_Handle handle, CryptoCC26XX_Transaction *transaction)
Function to do a Crypto operation (encryption or decryption) in blocking mode.
CryptoCC26XX_Mode mode
Definition: CryptoCC26XX.h:448
CryptoCC26XX_KeyStore keyStore
Definition: CryptoCC26XX.h:532
uint8_t keyIndex
Definition: CryptoCC26XX.h:449
uint16_t msgInLength
Definition: CryptoCC26XX.h:453
int powerMngrId
Definition: CryptoCC26XX.h:505
void * object
Definition: CryptoCC26XX.h:551
Semaphore_Struct transSem
Definition: CryptoCC26XX.h:544
Definition: CryptoCC26XX.h:387
Definition: CryptoCC26XX.h:381
uint8_t CryptoCC26XX_KeyStore
CryptoCC26XX Key.
Definition: CryptoCC26XX.h:402
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:464
void * nonce
Definition: CryptoCC26XX.h:450
CryptoCC26XX_KeyLocation
CryptoCC26XX Key Store Location.
Definition: CryptoCC26XX.h:377
int intNum
Definition: CryptoCC26XX.h:507
struct CryptoCC26XX_HWAttrs CryptoCC26XX_HWAttrs
CryptoCC26XX Hardware Attributes.
CryptoCC26XX_Mode mode
Definition: CryptoCC26XX.h:415
Definition: CryptoCC26XX.h:383
struct CryptoCC26XX_Transaction CryptoCC26XX_Transaction
CryptoCC26XX Transaction.
uint32_t timeout
Definition: CryptoCC26XX.h:394
CryptoCC26XX Object.
Definition: CryptoCC26XX.h:528
CryptoCC26XX_Mode mode
Definition: CryptoCC26XX.h:427
uint32_t baseAddr
Definition: CryptoCC26XX.h:503
struct CryptoCC26XX_AESECB_Transaction CryptoCC26XX_AESECB_Transaction
CryptoCC26XX AES-ECB Transaction.
struct CryptoCC26XX_AESCBC_Transaction CryptoCC26XX_AESCBC_Transaction
CryptoCC26XX AES-CBC Transaction.
Definition: CryptoCC26XX.h:380
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:429
CryptoCC26XX AES-CBC Transaction.
Definition: CryptoCC26XX.h:446
Definition: CryptoCC26XX.h:378
Copyright 2016, Texas Instruments Incorporated