TI-RTOS Drivers  tidrivers_full_2_20_01_10
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  */
351 #ifndef ti_drivers_crypto_CryptoCC26XX__include
352 #define ti_drivers_crypto_CryptoCC26XX__include
353 
354 #ifdef __cplusplus
355 extern "C" {
356 #endif
357 
358 #include <stdint.h>
359 #include <stdbool.h>
360 #include <ti/drivers/Power.h>
361 #include <driverlib/crypto.h>
362 
373 /* Add CryptoCC26XX_STATUS_* macros here */
374 
387 /* Add CryptoCC26XX_CMD_* macros here */
388 
391 #define CRYPTOCC26XX_TIMEOUT 20
393 #define CRYPTOCC26XX_STATUS_SUCCESS 0
394 #define CRYPTOCC26XX_STATUS_ERROR -1
395 #define CRYPTOCC26XX_STATUS_UNDEFINEDCMD -2
397 #define CRYPTOCC26XX_OP_AES_CCM_ENCRYPT 0
398 #define CRYPTOCC26XX_OP_AES_CCM_ENCRYPT_AAD_ONLY 1
399 #define CRYPTOCC26XX_OP_AES_CCM_DECRYPT 2
400 #define CRYPTOCC26XX_OP_AES_CCM_DECRYPT_AAD_ONLY 3
401 #define CRYPTOCC26XX_OP_AES_ECB_ENCRYPT 4
402 #define CRYPTOCC26XX_OP_AES_ECB_DECRYPT 5
403 #define CRYPTOCC26XX_OP_AES_CBC_ENCRYPT 6
404 #define CRYPTOCC26XX_OP_AES_CBC_DECRYPT 7
406 /* Deprecated operation mode names */
407 #define CRYPTOCC26XX_OP_AES_CCM CRYPTOCC26XX_OP_AES_CCM_ENCRYPT
408 #define CRYPTOCC26XX_OP_AES_CCM_NOCRYPT CRYPTOCC26XX_OP_AES_CCM_ENCRYPT_AAD_ONLY
409 #define CRYPTOCC26XX_OP_AES_CCMINV CRYPTOCC26XX_OP_AES_CCM_DECRYPT
410 #define CRYPTOCC26XX_OP_AES_CCMINV_NOCRYPT CRYPTOCC26XX_OP_AES_CCM_DECRYPT_AAD_ONLY
411 #define CRYPTOCC26XX_OP_AES_ECB CRYPTOCC26XX_OP_AES_ECB_ENCRYPT
412 #define CRYPTOCC26XX_OP_AES_ECB_NOCRYPT CRYPTOCC26XX_OP_AES_ECB_DECRYPT
413 
414 
415 /*
416  * The following allows this header file to be included in an application file
417  * which also includes ti/sysbios/hal/Hwi.h.
418  */
419 #define ti_sysbios_family_arm_m3_Hwi__nolocalnames
420 #include <ti/sysbios/family/arm/m3/Hwi.h>
421 #include <ti/sysbios/knl/Semaphore.h>
422 
427 
434 typedef enum CryptoCC26XX_Mode {
440 
447 
462 typedef uint8_t CryptoCC26XX_Operation;
463 
482 
486 typedef struct CryptoCC26XX_Params {
487  uint32_t timeout;
489 
495 typedef uint8_t CryptoCC26XX_KeyStore;
496 
506 typedef struct CryptoCC26XX_Transaction {
507  CryptoCC26XX_Operation opType;
509  uint8_t data[];
511 
563  CryptoCC26XX_Operation opType;
565  uint8_t keyIndex;
566  uint8_t authLength;
568  char *nonce;
569  char *msgIn;
575  char *header;
576  void *msgOut;
577  uint8_t fieldLength;
583  uint16_t msgInLength;
585  uint16_t headerLength;
587 
595  CryptoCC26XX_Operation opType;
597  uint8_t keyIndex;
598  void *nonce;
599  void *msgIn;
600  void *msgOut;
601  uint16_t msgInLength;
603 
611  CryptoCC26XX_Operation opType;
613  uint8_t keyIndex;
614  void *msgIn;
615  void *msgOut;
617 
649 typedef struct CryptoCC26XX_HWAttrs {
651  uint32_t baseAddr;
655  int intNum;
668  uint8_t intPriority;
670 
676 typedef struct CryptoCC26XX_Object {
677  /* CryptoCC26XX control variables */
678  int openCnt;
679  uint32_t timeout;
680  CryptoCC26XX_KeyStore keyStore;
683  /* Crypto transaction pointers for CryptoCC26XX_MODE_CALLBACK */
689 
690  /* CryptoCC26XX SYS/BIOS objects */
691  ti_sysbios_family_arm_m3_Hwi_Struct hwi;
692  Semaphore_Struct transSem;
693  Semaphore_Struct waitSem;
695 
697 typedef struct CryptoCC26XX_Config {
699  void *object;
700 
702  void const *hwAttrs;
704 
719 int CryptoCC26XX_close(CryptoCC26XX_Handle handle);
720 
728 void CryptoCC26XX_init(void);
729 
753 CryptoCC26XX_Handle CryptoCC26XX_open(unsigned int index, bool exclusiveAccess, CryptoCC26XX_Params *params);
754 
766 
777 void CryptoCC26XX_Transac_init(CryptoCC26XX_Transaction *trans, CryptoCC26XX_Operation opType);
778 
807 int CryptoCC26XX_allocateKey(CryptoCC26XX_Handle handle, CryptoCC26XX_KeyLocation keyLocation, const uint32_t *keySrc);
808 
809 
831 int CryptoCC26XX_loadKey(CryptoCC26XX_Handle handle, int keyIndex, const uint32_t *keySrc);
832 
850 int CryptoCC26XX_releaseKey(CryptoCC26XX_Handle handle, int *keyIndex);
851 
872 int CryptoCC26XX_transact(CryptoCC26XX_Handle handle, CryptoCC26XX_Transaction *transaction);
873 
893 int CryptoCC26XX_transactPolling(CryptoCC26XX_Handle handle, CryptoCC26XX_Transaction *transaction);
894 
918 int CryptoCC26XX_transactCallback(CryptoCC26XX_Handle handle, CryptoCC26XX_Transaction *transaction);
919 
920 
921 /* Do not interfere with the app if they include the family Hwi module */
922 #undef ti_sysbios_family_arm_m3_Hwi__nolocalnames
923 
924 #ifdef __cplusplus
925 }
926 #endif
927 
928 #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:506
Semaphore_Struct waitSem
Definition: CryptoCC26XX.h:693
CryptoCC26XX Global Configuration.
Definition: CryptoCC26XX.h:697
CryptoCC26XX_Transaction * currentTransact
Definition: CryptoCC26XX.h:681
void CryptoCC26XX_Params_init(CryptoCC26XX_Params *params)
Function to initialize the CryptoCC26XX_Params struct to its defaults.
CryptoCC26XX AES-CCM Transaction.
Definition: CryptoCC26XX.h:562
struct CryptoCC26XX_Object CryptoCC26XX_Object
CryptoCC26XX Object.
CryptoCC26XX_Operation opType
Definition: CryptoCC26XX.h:611
int CryptoCC26XX_close(CryptoCC26XX_Handle handle)
Function to closes a given CryptoCC26XX peripheral specified by the CryptoCC26XX handle.
void * msgOut
Definition: CryptoCC26XX.h:576
struct CryptoCC26XX_AESCCM_Transaction CryptoCC26XX_AESCCM_Transaction
CryptoCC26XX AES-CCM Transaction.
CryptoCC26XX_Transaction * tailPtr
Definition: CryptoCC26XX.h:685
CryptoCC26XX Parameters.
Definition: CryptoCC26XX.h:486
uint8_t keyIndex
Definition: CryptoCC26XX.h:613
void * msgIn
Definition: CryptoCC26XX.h:599
CryptoCC26XX_Operation opType
Definition: CryptoCC26XX.h:563
Definition: CryptoCC26XX.h:472
Power manager interface.
uint8_t CryptoCC26XX_Operation
CryptoCC26XX Operation Type.
Definition: CryptoCC26XX.h:462
uint8_t fieldLength
Definition: CryptoCC26XX.h:577
Definition: CryptoCC26XX.h:475
CryptoCC26XX_Operation opType
Definition: CryptoCC26XX.h:507
uint8_t data[]
Definition: CryptoCC26XX.h:509
Definition: CryptoCC26XX.h:439
CryptoCC26XX_Transaction * headPtr
Definition: CryptoCC26XX.h:684
CryptoCC26XX_Operation opType
Definition: CryptoCC26XX.h:595
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:615
uint8_t keyIndex
Definition: CryptoCC26XX.h:565
char * nonce
Definition: CryptoCC26XX.h:568
void * msgOut
Definition: CryptoCC26XX.h:600
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:478
char * header
Definition: CryptoCC26XX.h:575
CryptoCC26XX Hardware Attributes.
Definition: CryptoCC26XX.h:649
Power_NotifyObj cryptoNotiObj
Definition: CryptoCC26XX.h:688
int openCnt
Definition: CryptoCC26XX.h:678
ti_sysbios_family_arm_m3_Hwi_Struct hwi
Definition: CryptoCC26XX.h:691
Definition: CryptoCC26XX.h:477
void const * hwAttrs
Definition: CryptoCC26XX.h:702
uint16_t headerLength
Definition: CryptoCC26XX.h:585
Definition: CryptoCC26XX.h:445
uint16_t msgInLength
Definition: CryptoCC26XX.h:583
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:426
void * msgIn
Definition: CryptoCC26XX.h:614
Power notify object structure.
Definition: Power.h:112
uint32_t timeout
Definition: CryptoCC26XX.h:679
Definition: CryptoCC26XX.h:479
CryptoCC26XX_Mode
CryptoCC26XX Mode Settings.
Definition: CryptoCC26XX.h:434
CryptoCC26XX AES-ECB Transaction.
Definition: CryptoCC26XX.h:610
char * msgIn
Definition: CryptoCC26XX.h:569
void CryptoCC26XX_init(void)
Function to initializes bios modules needed by CryptoCC26XX module.
uint8_t intPriority
Crypto Peripheral's interrupt priority.
Definition: CryptoCC26XX.h:668
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:596
CryptoCC26XX_KeyStore keyStore
Definition: CryptoCC26XX.h:680
uint8_t keyIndex
Definition: CryptoCC26XX.h:597
uint16_t msgInLength
Definition: CryptoCC26XX.h:601
int powerMngrId
Definition: CryptoCC26XX.h:653
void * object
Definition: CryptoCC26XX.h:699
Semaphore_Struct transSem
Definition: CryptoCC26XX.h:692
Definition: CryptoCC26XX.h:480
Definition: CryptoCC26XX.h:474
uint8_t CryptoCC26XX_KeyStore
CryptoCC26XX Key.
Definition: CryptoCC26XX.h:495
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:612
void * nonce
Definition: CryptoCC26XX.h:598
CryptoCC26XX_KeyLocation
CryptoCC26XX Key Store Location.
Definition: CryptoCC26XX.h:470
int intNum
Definition: CryptoCC26XX.h:655
struct CryptoCC26XX_HWAttrs CryptoCC26XX_HWAttrs
CryptoCC26XX Hardware Attributes.
CryptoCC26XX_Mode mode
Definition: CryptoCC26XX.h:508
Definition: CryptoCC26XX.h:476
struct CryptoCC26XX_Transaction CryptoCC26XX_Transaction
CryptoCC26XX Transaction.
uint32_t timeout
Definition: CryptoCC26XX.h:487
CryptoCC26XX Object.
Definition: CryptoCC26XX.h:676
CryptoCC26XX_Mode mode
Definition: CryptoCC26XX.h:564
uint32_t baseAddr
Definition: CryptoCC26XX.h:651
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:473
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:566
CryptoCC26XX AES-CBC Transaction.
Definition: CryptoCC26XX.h:594
Definition: CryptoCC26XX.h:471
Copyright 2016, Texas Instruments Incorporated