TI-RTOS Drivers  tidrivers_cc13xx_cc26xx_2_21_00_04
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  */
366 #ifndef ti_drivers_crypto_CryptoCC26XX__include
367 #define ti_drivers_crypto_CryptoCC26XX__include
368 
369 #ifdef __cplusplus
370 extern "C" {
371 #endif
372 
373 #include <stdint.h>
374 #include <stdbool.h>
375 #include <ti/drivers/Power.h>
376 #include <driverlib/crypto.h>
377 
388 /* Add CryptoCC26XX_STATUS_* macros here */
389 
402 /* Add CryptoCC26XX_CMD_* macros here */
403 
406 #define CRYPTOCC26XX_TIMEOUT 20
408 #define CRYPTOCC26XX_STATUS_SUCCESS 0
409 #define CRYPTOCC26XX_STATUS_ERROR -1
410 #define CRYPTOCC26XX_STATUS_UNDEFINEDCMD -2
412 #define CRYPTOCC26XX_OP_AES_CCM_ENCRYPT 0
413 #define CRYPTOCC26XX_OP_AES_CCM_ENCRYPT_AAD_ONLY 1
414 #define CRYPTOCC26XX_OP_AES_CCM_DECRYPT 2
415 #define CRYPTOCC26XX_OP_AES_CCM_DECRYPT_AAD_ONLY 3
416 #define CRYPTOCC26XX_OP_AES_ECB_ENCRYPT 4
417 #define CRYPTOCC26XX_OP_AES_ECB_DECRYPT 5
418 #define CRYPTOCC26XX_OP_AES_CBC_ENCRYPT 6
419 #define CRYPTOCC26XX_OP_AES_CBC_DECRYPT 7
421 /* Deprecated operation mode names */
422 #define CRYPTOCC26XX_OP_AES_CCM CRYPTOCC26XX_OP_AES_CCM_ENCRYPT
423 #define CRYPTOCC26XX_OP_AES_CCM_NOCRYPT CRYPTOCC26XX_OP_AES_CCM_ENCRYPT_AAD_ONLY
424 #define CRYPTOCC26XX_OP_AES_CCMINV CRYPTOCC26XX_OP_AES_CCM_DECRYPT
425 #define CRYPTOCC26XX_OP_AES_CCMINV_NOCRYPT CRYPTOCC26XX_OP_AES_CCM_DECRYPT_AAD_ONLY
426 #define CRYPTOCC26XX_OP_AES_ECB CRYPTOCC26XX_OP_AES_ECB_ENCRYPT
427 #define CRYPTOCC26XX_OP_AES_ECB_NOCRYPT CRYPTOCC26XX_OP_AES_ECB_DECRYPT
428 
429 
430 /*
431  * The following allows this header file to be included in an application file
432  * which also includes ti/sysbios/hal/Hwi.h.
433  */
434 #define ti_sysbios_family_arm_m3_Hwi__nolocalnames
435 #include <ti/sysbios/family/arm/m3/Hwi.h>
436 #include <ti/sysbios/knl/Semaphore.h>
437 
442 
449 typedef enum CryptoCC26XX_Mode {
455 
462 
477 typedef uint8_t CryptoCC26XX_Operation;
478 
497 
501 typedef struct CryptoCC26XX_Params {
502  uint32_t timeout;
504 
510 typedef uint8_t CryptoCC26XX_KeyStore;
511 
521 typedef struct CryptoCC26XX_Transaction {
522  CryptoCC26XX_Operation opType;
524  uint8_t data[];
526 
578  CryptoCC26XX_Operation opType;
580  uint8_t keyIndex;
581  uint8_t authLength;
583  char *nonce;
584  char *msgIn;
590  char *header;
591  void *msgOut;
592  uint8_t fieldLength;
598  uint16_t msgInLength;
600  uint16_t headerLength;
602 
610  CryptoCC26XX_Operation opType;
612  uint8_t keyIndex;
613  void *nonce;
614  void *msgIn;
615  void *msgOut;
616  uint16_t msgInLength;
618 
626  CryptoCC26XX_Operation opType;
628  uint8_t keyIndex;
629  void *msgIn;
630  void *msgOut;
632 
664 typedef struct CryptoCC26XX_HWAttrs {
666  uint32_t baseAddr;
670  int intNum;
683  uint8_t intPriority;
685 
691 typedef struct CryptoCC26XX_Object {
692  /* CryptoCC26XX control variables */
693  int openCnt;
694  uint32_t timeout;
695  CryptoCC26XX_KeyStore keyStore;
698  /* Crypto transaction pointers for CryptoCC26XX_MODE_CALLBACK */
704 
705  /* CryptoCC26XX SYS/BIOS objects */
706  ti_sysbios_family_arm_m3_Hwi_Struct hwi;
707  Semaphore_Struct transSem;
708  Semaphore_Struct waitSem;
710 
712 typedef struct CryptoCC26XX_Config {
714  void *object;
715 
717  void const *hwAttrs;
719 
734 int CryptoCC26XX_close(CryptoCC26XX_Handle handle);
735 
743 void CryptoCC26XX_init(void);
744 
768 CryptoCC26XX_Handle CryptoCC26XX_open(unsigned int index, bool exclusiveAccess, CryptoCC26XX_Params *params);
769 
781 
792 void CryptoCC26XX_Transac_init(CryptoCC26XX_Transaction *trans, CryptoCC26XX_Operation opType);
793 
822 int CryptoCC26XX_allocateKey(CryptoCC26XX_Handle handle, CryptoCC26XX_KeyLocation keyLocation, const uint32_t *keySrc);
823 
824 
846 int CryptoCC26XX_loadKey(CryptoCC26XX_Handle handle, int keyIndex, const uint32_t *keySrc);
847 
865 int CryptoCC26XX_releaseKey(CryptoCC26XX_Handle handle, int *keyIndex);
866 
887 int CryptoCC26XX_transact(CryptoCC26XX_Handle handle, CryptoCC26XX_Transaction *transaction);
888 
908 int CryptoCC26XX_transactPolling(CryptoCC26XX_Handle handle, CryptoCC26XX_Transaction *transaction);
909 
933 int CryptoCC26XX_transactCallback(CryptoCC26XX_Handle handle, CryptoCC26XX_Transaction *transaction);
934 
935 
936 /* Do not interfere with the app if they include the family Hwi module */
937 #undef ti_sysbios_family_arm_m3_Hwi__nolocalnames
938 
939 #ifdef __cplusplus
940 }
941 #endif
942 
943 #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:521
Semaphore_Struct waitSem
Definition: CryptoCC26XX.h:708
CryptoCC26XX Global Configuration.
Definition: CryptoCC26XX.h:712
CryptoCC26XX_Transaction * currentTransact
Definition: CryptoCC26XX.h:696
void CryptoCC26XX_Params_init(CryptoCC26XX_Params *params)
Function to initialize the CryptoCC26XX_Params struct to its defaults.
CryptoCC26XX AES-CCM Transaction.
Definition: CryptoCC26XX.h:577
struct CryptoCC26XX_Object CryptoCC26XX_Object
CryptoCC26XX Object.
CryptoCC26XX_Operation opType
Definition: CryptoCC26XX.h:626
int CryptoCC26XX_close(CryptoCC26XX_Handle handle)
Function to closes a given CryptoCC26XX peripheral specified by the CryptoCC26XX handle.
void * msgOut
Definition: CryptoCC26XX.h:591
struct CryptoCC26XX_AESCCM_Transaction CryptoCC26XX_AESCCM_Transaction
CryptoCC26XX AES-CCM Transaction.
CryptoCC26XX_Transaction * tailPtr
Definition: CryptoCC26XX.h:700
CryptoCC26XX Parameters.
Definition: CryptoCC26XX.h:501
uint8_t keyIndex
Definition: CryptoCC26XX.h:628
void * msgIn
Definition: CryptoCC26XX.h:614
CryptoCC26XX_Operation opType
Definition: CryptoCC26XX.h:578
Definition: CryptoCC26XX.h:487
Power manager interface.
uint8_t CryptoCC26XX_Operation
CryptoCC26XX Operation Type.
Definition: CryptoCC26XX.h:477
uint8_t fieldLength
Definition: CryptoCC26XX.h:592
Definition: CryptoCC26XX.h:490
CryptoCC26XX_Operation opType
Definition: CryptoCC26XX.h:522
uint8_t data[]
Definition: CryptoCC26XX.h:524
Definition: CryptoCC26XX.h:454
CryptoCC26XX_Transaction * headPtr
Definition: CryptoCC26XX.h:699
CryptoCC26XX_Operation opType
Definition: CryptoCC26XX.h:610
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:630
uint8_t keyIndex
Definition: CryptoCC26XX.h:580
char * nonce
Definition: CryptoCC26XX.h:583
void * msgOut
Definition: CryptoCC26XX.h:615
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:493
char * header
Definition: CryptoCC26XX.h:590
CryptoCC26XX Hardware Attributes.
Definition: CryptoCC26XX.h:664
Power_NotifyObj cryptoNotiObj
Definition: CryptoCC26XX.h:703
int openCnt
Definition: CryptoCC26XX.h:693
ti_sysbios_family_arm_m3_Hwi_Struct hwi
Definition: CryptoCC26XX.h:706
Definition: CryptoCC26XX.h:492
void const * hwAttrs
Definition: CryptoCC26XX.h:717
uint16_t headerLength
Definition: CryptoCC26XX.h:600
Definition: CryptoCC26XX.h:460
uint16_t msgInLength
Definition: CryptoCC26XX.h:598
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:441
void * msgIn
Definition: CryptoCC26XX.h:629
Power notify object structure.
Definition: Power.h:112
uint32_t timeout
Definition: CryptoCC26XX.h:694
Definition: CryptoCC26XX.h:494
CryptoCC26XX_Mode
CryptoCC26XX Mode Settings.
Definition: CryptoCC26XX.h:449
CryptoCC26XX AES-ECB Transaction.
Definition: CryptoCC26XX.h:625
char * msgIn
Definition: CryptoCC26XX.h:584
void CryptoCC26XX_init(void)
Function to initializes bios modules needed by CryptoCC26XX module.
uint8_t intPriority
Crypto Peripheral's interrupt priority.
Definition: CryptoCC26XX.h:683
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:611
CryptoCC26XX_KeyStore keyStore
Definition: CryptoCC26XX.h:695
uint8_t keyIndex
Definition: CryptoCC26XX.h:612
uint16_t msgInLength
Definition: CryptoCC26XX.h:616
int powerMngrId
Definition: CryptoCC26XX.h:668
void * object
Definition: CryptoCC26XX.h:714
Semaphore_Struct transSem
Definition: CryptoCC26XX.h:707
Definition: CryptoCC26XX.h:495
Definition: CryptoCC26XX.h:489
uint8_t CryptoCC26XX_KeyStore
CryptoCC26XX Key.
Definition: CryptoCC26XX.h:510
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:627
void * nonce
Definition: CryptoCC26XX.h:613
CryptoCC26XX_KeyLocation
CryptoCC26XX Key Store Location.
Definition: CryptoCC26XX.h:485
int intNum
Definition: CryptoCC26XX.h:670
struct CryptoCC26XX_HWAttrs CryptoCC26XX_HWAttrs
CryptoCC26XX Hardware Attributes.
CryptoCC26XX_Mode mode
Definition: CryptoCC26XX.h:523
Definition: CryptoCC26XX.h:491
struct CryptoCC26XX_Transaction CryptoCC26XX_Transaction
CryptoCC26XX Transaction.
uint32_t timeout
Definition: CryptoCC26XX.h:502
CryptoCC26XX Object.
Definition: CryptoCC26XX.h:691
CryptoCC26XX_Mode mode
Definition: CryptoCC26XX.h:579
uint32_t baseAddr
Definition: CryptoCC26XX.h:666
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:488
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:581
CryptoCC26XX AES-CBC Transaction.
Definition: CryptoCC26XX.h:609
Definition: CryptoCC26XX.h:486
Copyright 2016, Texas Instruments Incorporated