AESCommonXXF3.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021-2025, 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  */
59 #ifndef ti_drivers_aescommon_AESCommonXXF3__include
60 #define ti_drivers_aescommon_AESCommonXXF3__include
61 
62 #include <stdbool.h>
63 #include <stdint.h>
64 
65 #include <ti/drivers/AESCommon.h>
67 
68 #include <ti/drivers/dpl/HwiP.h>
69 
70 #include <ti/devices/DeviceFamily.h>
71 #include DeviceFamily_constructPath(inc/hw_types.h)
72 
73 #ifdef __cplusplus
74 extern "C" {
75 #endif
76 
77 /*
78  * Unaligned input/output pointer arguments are not supported by default
79  * because the performance will be up to 5x slower. Enabling unaligned I/O
80  * is strongly discouraged.
81  */
82 #ifndef AESCommonXXF3_UNALIGNED_IO_SUPPORT_ENABLE
83  #define AESCommonXXF3_UNALIGNED_IO_SUPPORT_ENABLE 0
84 #endif
85 
86 /* DMA Channel Numbers */
87 #define DMA_CH4 4U
88 #define DMA_CH5 5U
89 
90 /* DMA Channel 4 is reserved for AES Channel A (input) */
91 #define AESCommonXXF3_DMA_CHA_BITMASK ((uint32_t)1U << DMA_CH4)
92 /* DMA Channel 5 is reserved for AES Channel B (output) */
93 #define AESCommonXXF3_DMA_CHB_BITMASK ((uint32_t)1U << DMA_CH5)
94 
95 /* Max key length supported by HSM - needed for KeyStore material retrieval */
96 #define AESCommonXXF3_256_KEY_LENGTH_BYTES (256U / 8U)
97 
98 #if (DeviceFamily_PARENT == DeviceFamily_PARENT_CC35XX)
99  /* For CC27XX and CC23XX devices, below AES defines come from driverlib headers.
100  * For CC35XX devices, driverlib does NOT contain these defines.
101  * So, below defines are added.
102  */
103  #define AES_BLOCK_SIZE 16U
104  #define AES_BLOCK_SIZE_WORDS (AES_BLOCK_SIZE / 4U)
105  #define AES_BLOCK_SIZE_MULTIPLE_MASK 0xFFFFFFF0U
106  #define AES_BLOCK_SIZE_MULTIPLE_LENGTH(len) ((len)&AES_BLOCK_SIZE_MULTIPLE_MASK)
107  #define AES_NON_BLOCK_SIZE_MULTIPLE_MASK 0x0000000FU
108  #define AES_NON_BLOCK_SIZE_MULTIPLE_LENGTH(len) ((len)&AES_NON_BLOCK_SIZE_MULTIPLE_MASK)
109 
110  #define AES_IV_LENGTH_BYTES AES_BLOCK_SIZE
111  #define AES_TAG_LENGTH_BYTES AES_BLOCK_SIZE
112 
113  #define AES_128_KEY_LENGTH_BYTES (128U / 8U)
114 
115  #define IS_WORD_ALIGNED(ptr) (((uintptr_t)(ptr) << 30) == 0U)
116 #endif
117 
121 typedef struct
122 {
135  uint8_t intPriority;
137 
143 typedef struct
144 {
147  volatile int_fast16_t returnStatus;
149  bool isOpen;
150  volatile bool cryptoResourceLocked;
151  volatile bool operationInProgress;
152  volatile bool powerConstraintSet;
154 
163 void AESCommonXXF3_init(void);
164 
178 int_fast16_t AESCommonXXF3_construct(AESCommonXXF3_Object *object, AES_ReturnBehavior returnBehavior, uint32_t timeout);
188 void AESCommonXXF3_loadKey(const CryptoKey *key);
191 #if (ENABLE_KEY_STORAGE == 1)
192  /* Due to circular include dependencies, these types are defined here instead of retrieved via an include */
193  #ifndef KeyStore_PSA_Algorithm
194 typedef uint32_t KeyStore_PSA_Algorithm;
195  #endif
196  #ifndef KeyStore_PSA_KeyUsage
197 typedef uint32_t KeyStore_PSA_KeyUsage;
198  #endif
199 
213 int_fast16_t AESCommonXXF3_loadKeyFromKeyStore(const CryptoKey *key,
214  uint32_t *keyAssetID,
215  KeyStore_PSA_Algorithm targetAlg,
216  KeyStore_PSA_KeyUsage targetUsage);
218 #endif /* ENABLE_KEY_STORAGE */
219 
228 void AESCommonXXF3_setupOperation(CryptoKey *key, uint32_t autoCfgVal);
239 void AESCommonXXF3_close(AESCommonXXF3_Object *object);
252 int_fast16_t AESCommonXXF3_setOperationInProgress(AESCommonXXF3_Object *object);
263 __STATIC_INLINE void AESCommonXXF3_clearOperationInProgress(AESCommonXXF3_Object *object)
264 {
265  object->operationInProgress = false;
266 }
280 void AESCommonXXF3_cleanup(AESCommonXXF3_Object *object);
291 int_fast16_t AESCommonXXF3_setupSegmentedOperation(AESCommonXXF3_Object *object, const CryptoKey *key);
306 bool AESCommonXXF3_isDMALengthValid(const void *input, const void *output, size_t length);
324 void AESCommonXXF3_configInputDMA(const void *input, size_t inputLength);
343 void AESCommonXXF3_configOutputDMA(void *output, size_t outputLength);
354 void AESCommonXXF3_cancelDMA(bool cancelChannelB);
369 void AESCommonXXF3_cancelOperation(AESCommonXXF3_Object *object, bool cancelDMAChannelB);
381 void AESCommonXXF3_setupHwi(HwiP_Fxn hwiFxn, uintptr_t hwiFxnArg, uint8_t intPriority);
391 void AESCommonXXF3_cleanupHwi(AESCommonXXF3_Object *object);
402 void AESCommonXXF3_setupDMA(AESCommonXXF3_Object *object, uint32_t dmaConfig);
405 #ifdef __cplusplus
406 }
407 #endif
408 
409 #endif /* ti_drivers_aescommon_AESCommonXXF3__include */
AES_ReturnBehavior returnBehavior
Definition: AESCommonXXF3.h:148
psa_key_usage_t KeyStore_PSA_KeyUsage
Encoding of permitted usage on a key.
Definition: CryptoKeyKeyStore_PSA.h:133
uint8_t intPriority
Crypto Peripheral&#39;s interrupt priority.
Definition: AESCommonXXF3.h:135
The CryptoKey type is an opaque representation of a cryptographic key.
AES_ReturnBehavior
The return behavior of AES functions.
Definition: AESCommon.h:184
volatile bool cryptoResourceLocked
Definition: AESCommonXXF3.h:150
CryptoKey datastructure.
Definition: CryptoKey.h:211
volatile int_fast16_t returnStatus
Definition: AESCommonXXF3.h:147
volatile bool powerConstraintSet
Definition: AESCommonXXF3.h:152
volatile bool operationInProgress
Definition: AESCommonXXF3.h:151
psa_algorithm_t KeyStore_PSA_Algorithm
Encoding of a cryptographic algorithm.
Definition: CryptoKeyKeyStore_PSA.h:575
uint32_t semaphoreTimeout
Definition: AESCommonXXF3.h:145
bool isOpen
Definition: AESCommonXXF3.h:149
AESCommonXXF3 Object.
Definition: AESCommonXXF3.h:143
CryptoKey key
Definition: AESCommonXXF3.h:146
AES common module header for all devices.
AESCommonXXF3 Hardware Attributes.
Definition: AESCommonXXF3.h:121
© Copyright 1995-2026, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale