CryptoCC26XX.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2018, 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  */
367 #ifndef ti_drivers_crypto_CryptoCC26XX__include
368 #define ti_drivers_crypto_CryptoCC26XX__include
369 
370 #ifdef __cplusplus
371 extern "C" {
372 #endif
373 
374 #include <stdint.h>
375 #include <stdbool.h>
376 
377 #include <ti/drivers/Power.h>
378 
379 #include <ti/devices/DeviceFamily.h>
380 #include DeviceFamily_constructPath(driverlib/crypto.h)
381 
382 #if DeviceFamily_PARENT == DeviceFamily_PARENT_CC13X2_CC26X2
383  #warning "This driver is deprecated for the CC26x2 and CC13x2 families.\
384  It is superceded by AESECB and AESCCM."
385 #endif
386 
397 /* Add CryptoCC26XX_STATUS_* macros here */
398 
411 /* Add CryptoCC26XX_CMD_* macros here */
412 
415 #define CRYPTOCC26XX_TIMEOUT 20
417 #define CRYPTOCC26XX_STATUS_SUCCESS 0
418 #define CRYPTOCC26XX_STATUS_ERROR -1
419 #define CRYPTOCC26XX_STATUS_UNDEFINEDCMD -2
421 #define CRYPTOCC26XX_OP_AES_CCM_ENCRYPT 0
422 #define CRYPTOCC26XX_OP_AES_CCM_ENCRYPT_AAD_ONLY 1
423 #define CRYPTOCC26XX_OP_AES_CCM_DECRYPT 2
424 #define CRYPTOCC26XX_OP_AES_CCM_DECRYPT_AAD_ONLY 3
425 #define CRYPTOCC26XX_OP_AES_ECB_ENCRYPT 4
426 #define CRYPTOCC26XX_OP_AES_ECB_DECRYPT 5
427 #define CRYPTOCC26XX_OP_AES_CBC_ENCRYPT 6
428 #define CRYPTOCC26XX_OP_AES_CBC_DECRYPT 7
430 /* Deprecated operation mode names */
431 #define CRYPTOCC26XX_OP_AES_CCM CRYPTOCC26XX_OP_AES_CCM_ENCRYPT
432 #define CRYPTOCC26XX_OP_AES_CCM_NOCRYPT CRYPTOCC26XX_OP_AES_CCM_ENCRYPT_AAD_ONLY
433 #define CRYPTOCC26XX_OP_AES_CCMINV CRYPTOCC26XX_OP_AES_CCM_DECRYPT
434 #define CRYPTOCC26XX_OP_AES_CCMINV_NOCRYPT CRYPTOCC26XX_OP_AES_CCM_DECRYPT_AAD_ONLY
435 #define CRYPTOCC26XX_OP_AES_ECB CRYPTOCC26XX_OP_AES_ECB_ENCRYPT
436 #define CRYPTOCC26XX_OP_AES_ECB_NOCRYPT CRYPTOCC26XX_OP_AES_ECB_DECRYPT
437 
438 
439 #include <ti/drivers/dpl/HwiP.h>
440 #include <ti/drivers/dpl/SemaphoreP.h>
441 
446 
453 typedef enum CryptoCC26XX_Mode {
459 
466 
481 typedef uint8_t CryptoCC26XX_Operation;
482 
501 
505 typedef struct CryptoCC26XX_Params {
506  uint32_t timeout;
508 
514 typedef uint8_t CryptoCC26XX_KeyStore;
515 
525 typedef struct CryptoCC26XX_Transaction {
526  CryptoCC26XX_Operation opType;
527  CryptoCC26XX_Mode mode;
528  uint8_t data[];
530 
582  CryptoCC26XX_Operation opType;
583  CryptoCC26XX_Mode mode;
584  uint8_t keyIndex;
585  uint8_t authLength;
587  char *nonce;
604  char *msgIn;
610  char *header;
611  void *msgOut;
617  uint8_t fieldLength;
628  uint16_t msgInLength;
630  uint16_t headerLength;
632 
640  CryptoCC26XX_Operation opType;
641  CryptoCC26XX_Mode mode;
642  uint8_t keyIndex;
643  void *nonce;
644  void *msgIn;
645  void *msgOut;
646  uint16_t msgInLength;
648 
656  CryptoCC26XX_Operation opType;
657  CryptoCC26XX_Mode mode;
658  uint8_t keyIndex;
659  void *msgIn;
660  void *msgOut;
662 
692 typedef struct CryptoCC26XX_HWAttrs {
694  uint32_t baseAddr;
698  int intNum;
711  uint8_t intPriority;
713 
719 typedef struct CryptoCC26XX_Object {
720  /* CryptoCC26XX control variables */
721  int openCnt;
722  uint32_t timeout;
723  CryptoCC26XX_KeyStore keyStore;
726  /* Crypto transaction pointers for CryptoCC26XX_MODE_CALLBACK */
732 
733  /* CryptoCC26XX SYS/BIOS objects */
734  HwiP_Struct hwi;
735  SemaphoreP_Struct transSem;
736  SemaphoreP_Struct waitSem;
738 
740 typedef struct CryptoCC26XX_Config {
742  void *object;
743 
745  void const *hwAttrs;
747 
762 int CryptoCC26XX_close(CryptoCC26XX_Handle handle);
763 
773 void CryptoCC26XX_init(void);
774 
799 CryptoCC26XX_Handle CryptoCC26XX_open(unsigned int index, bool exclusiveAccess, CryptoCC26XX_Params *params);
800 
812 
823 void CryptoCC26XX_Transac_init(CryptoCC26XX_Transaction *trans, CryptoCC26XX_Operation opType);
824 
853 int CryptoCC26XX_allocateKey(CryptoCC26XX_Handle handle, CryptoCC26XX_KeyLocation keyLocation, const uint32_t *keySrc);
854 
855 
879 int CryptoCC26XX_loadKey(CryptoCC26XX_Handle handle, int keyIndex, const uint32_t *keySrc);
880 
898 int CryptoCC26XX_releaseKey(CryptoCC26XX_Handle handle, int *keyIndex);
899 
920 int CryptoCC26XX_transact(CryptoCC26XX_Handle handle, CryptoCC26XX_Transaction *transaction);
921 
941 int CryptoCC26XX_transactPolling(CryptoCC26XX_Handle handle, CryptoCC26XX_Transaction *transaction);
942 
966 int CryptoCC26XX_transactCallback(CryptoCC26XX_Handle handle, CryptoCC26XX_Transaction *transaction);
967 
968 #ifdef __cplusplus
969 }
970 #endif
971 
972 #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:525
CryptoCC26XX Global Configuration.
Definition: CryptoCC26XX.h:740
CryptoCC26XX_Transaction * currentTransact
Definition: CryptoCC26XX.h:724
void CryptoCC26XX_Params_init(CryptoCC26XX_Params *params)
Function to initialize the CryptoCC26XX_Params struct to its defaults.
CryptoCC26XX AES-CCM Transaction.
Definition: CryptoCC26XX.h:581
struct CryptoCC26XX_Object CryptoCC26XX_Object
CryptoCC26XX Object.
CryptoCC26XX_Operation opType
Definition: CryptoCC26XX.h:656
int CryptoCC26XX_close(CryptoCC26XX_Handle handle)
Function to closes a given CryptoCC26XX peripheral specified by the CryptoCC26XX handle.
void * msgOut
Definition: CryptoCC26XX.h:611
struct CryptoCC26XX_AESCCM_Transaction CryptoCC26XX_AESCCM_Transaction
CryptoCC26XX AES-CCM Transaction.
CryptoCC26XX_Transaction * tailPtr
Definition: CryptoCC26XX.h:728
CryptoCC26XX Parameters.
Definition: CryptoCC26XX.h:505
uint8_t keyIndex
Definition: CryptoCC26XX.h:658
void * msgIn
Definition: CryptoCC26XX.h:644
CryptoCC26XX_Operation opType
Definition: CryptoCC26XX.h:582
Definition: CryptoCC26XX.h:491
Power Manager interface.
SemaphoreP_Struct waitSem
Definition: CryptoCC26XX.h:736
HwiP_Struct hwi
Definition: CryptoCC26XX.h:734
SemaphoreP_Struct transSem
Definition: CryptoCC26XX.h:735
uint8_t CryptoCC26XX_Operation
CryptoCC26XX Operation Type.
Definition: CryptoCC26XX.h:481
uint8_t fieldLength
Definition: CryptoCC26XX.h:617
Power notify object structure.
Definition: Power.h:121
Definition: CryptoCC26XX.h:494
CryptoCC26XX_Operation opType
Definition: CryptoCC26XX.h:526
Definition: CryptoCC26XX.h:458
CryptoCC26XX_Transaction * headPtr
Definition: CryptoCC26XX.h:727
CryptoCC26XX_Operation opType
Definition: CryptoCC26XX.h:640
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:660
uint8_t keyIndex
Definition: CryptoCC26XX.h:584
char * nonce
Definition: CryptoCC26XX.h:587
void * msgOut
Definition: CryptoCC26XX.h:645
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:497
char * header
Definition: CryptoCC26XX.h:610
CryptoCC26XX Hardware Attributes.
Definition: CryptoCC26XX.h:692
Power_NotifyObj cryptoNotiObj
Definition: CryptoCC26XX.h:731
int openCnt
Definition: CryptoCC26XX.h:721
Definition: CryptoCC26XX.h:496
void const * hwAttrs
Definition: CryptoCC26XX.h:745
uint16_t headerLength
Definition: CryptoCC26XX.h:630
Definition: CryptoCC26XX.h:464
uint16_t msgInLength
Definition: CryptoCC26XX.h:628
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:445
void * msgIn
Definition: CryptoCC26XX.h:659
uint32_t timeout
Definition: CryptoCC26XX.h:722
Definition: CryptoCC26XX.h:498
CryptoCC26XX_Mode
CryptoCC26XX Mode Settings.
Definition: CryptoCC26XX.h:453
CryptoCC26XX AES-ECB Transaction.
Definition: CryptoCC26XX.h:655
char * msgIn
Definition: CryptoCC26XX.h:604
void CryptoCC26XX_init(void)
Function to initialize CryptoCC26XX driver. Users of this module must call init(). Multiple users/libraries may call init(), though subsequent calls may be benign.
uint8_t intPriority
Crypto Peripheral&#39;s interrupt priority.
Definition: CryptoCC26XX.h:711
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:641
CryptoCC26XX_KeyStore keyStore
Definition: CryptoCC26XX.h:723
uint8_t keyIndex
Definition: CryptoCC26XX.h:642
uint16_t msgInLength
Definition: CryptoCC26XX.h:646
int powerMngrId
Definition: CryptoCC26XX.h:696
void * object
Definition: CryptoCC26XX.h:742
Definition: CryptoCC26XX.h:499
Definition: CryptoCC26XX.h:493
uint8_t CryptoCC26XX_KeyStore
CryptoCC26XX Key.
Definition: CryptoCC26XX.h:514
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:657
void * nonce
Definition: CryptoCC26XX.h:643
CryptoCC26XX_KeyLocation
CryptoCC26XX Key Store Location.
Definition: CryptoCC26XX.h:489
int intNum
Definition: CryptoCC26XX.h:698
struct CryptoCC26XX_HWAttrs CryptoCC26XX_HWAttrs
CryptoCC26XX Hardware Attributes.
CryptoCC26XX_Mode mode
Definition: CryptoCC26XX.h:527
Definition: CryptoCC26XX.h:495
struct CryptoCC26XX_Transaction CryptoCC26XX_Transaction
CryptoCC26XX Transaction.
uint32_t timeout
Definition: CryptoCC26XX.h:506
CryptoCC26XX Object.
Definition: CryptoCC26XX.h:719
CryptoCC26XX_Mode mode
Definition: CryptoCC26XX.h:583
uint32_t baseAddr
Definition: CryptoCC26XX.h:694
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:492
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:585
CryptoCC26XX AES-CBC Transaction.
Definition: CryptoCC26XX.h:639
Definition: CryptoCC26XX.h:490
Copyright 2018, Texas Instruments Incorporated