AESCTRLPF3.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021-2024, 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  */
56 #ifndef ti_drivers_aesctr_AESCTRLPF3__include
57 #define ti_drivers_aesctr_AESCTRLPF3__include
58 
59 #include <stdbool.h>
60 #include <stdint.h>
61 
62 #include <ti/drivers/AESCTR.h>
65 
66 #include <ti/devices/DeviceFamily.h>
67 #include DeviceFamily_constructPath(driverlib/aes.h)
68 
69 #ifdef __cplusplus
70 extern "C" {
71 #endif
72 
73 /*
74  * Default AES CTR auto config:
75  * ECB SRC as BUF
76  * Trigger points for auto ECB as RDTX3 and WRBUF3S
77  * (the first encryption starts by writing BUF3, the successive ones by reading TXT3)
78  * Counter size as 128-bits
79  * Counter endianness as Big Endian
80  * BUSHALT enabled
81  */
82 #if (DeviceFamily_PARENT == DeviceFamily_PARENT_CC27XX)
83  #define AES_AUTOCFG_CTRENDN_BIGENDIAN AES_AUTOCFG_CTRENDIAN_BIGENDIAN
84 #endif
85 
86 #if DeviceFamily_PARENT == DeviceFamily_PARENT_CC23X0
87  #define AESCTRLPF3_DEFAULT_AUTOCFG \
88  ((uint32_t)AES_AUTOCFG_AESSRC_BUF | (uint32_t)AES_AUTOCFG_TRGAES_WRBUF3S | \
89  (uint32_t)AES_AUTOCFG_TRGAES_RDTXT3 | (uint32_t)AES_AUTOCFG_CTRSIZE_CTR128 | \
90  (uint32_t)AES_AUTOCFG_CTRENDN_BIGENDIAN | (uint32_t)AES_AUTOCFG_BUSHALT_EN)
91 #elif DeviceFamily_PARENT == DeviceFamily_PARENT_CC27XX
92  #define AESCTRLPF3_DEFAULT_AUTOCFG \
93  ((uint32_t)AES_AUTOCFG_ECBSRC_BUF | (uint32_t)AES_AUTOCFG_TRGECB_WRBUF3S | \
94  (uint32_t)AES_AUTOCFG_TRGECB_RDTXT3 | (uint32_t)AES_AUTOCFG_CTRSIZE_CTR128 | \
95  (uint32_t)AES_AUTOCFG_CTRENDN_BIGENDIAN | (uint32_t)AES_AUTOCFG_BUSHALT_EN)
96 #else
97  #error "Unsupported DeviceFamily_Parent for AESCTRLPF3!"
98 #endif
99 
100 /*
101  * AES CTR auto config for handling processing of the last
102  * block of input to avoid starting encryption of the next counter block and
103  * incrementing the counter value when the output is read from TXT3.
104  *
105  * ECB SRC as BUF
106  * Trigger for auto ECB as WRBUF3S
107  * (the first encryption starts by writing BUF3)
108  * Counter size as 128-bits
109  * Counter endianness as Big Endian
110  */
111 #if DeviceFamily_PARENT == DeviceFamily_PARENT_CC23X0
112  #define AESCTRLPF3_LAST_BLOCK_AUTOCFG \
113  ((uint32_t)AES_AUTOCFG_AESSRC_BUF | (uint32_t)AES_AUTOCFG_TRGAES_WRBUF3S | \
114  (uint32_t)AES_AUTOCFG_CTRSIZE_CTR128 | (uint32_t)AES_AUTOCFG_CTRENDN_BIGENDIAN | \
115  (uint32_t)AES_AUTOCFG_BUSHALT_EN)
116 #elif DeviceFamily_PARENT == DeviceFamily_PARENT_CC27XX
117  #define AESCTRLPF3_LAST_BLOCK_AUTOCFG \
118  ((uint32_t)AES_AUTOCFG_ECBSRC_BUF | (uint32_t)AES_AUTOCFG_TRGECB_WRBUF3S | \
119  (uint32_t)AES_AUTOCFG_CTRSIZE_CTR128 | (uint32_t)AES_AUTOCFG_CTRENDN_BIGENDIAN | \
120  (uint32_t)AES_AUTOCFG_BUSHALT_EN)
121 #else
122  #error "Unsupported DeviceFamily_Parent for AESCTRLPF3!"
123 #endif
124 
132 
138 typedef struct
139 {
140  /* Common member first to allow struct to be cast to the common type */
142  volatile uint32_t counter[AES_BLOCK_SIZE_WORDS];
143  const uint8_t *input;
144  uint8_t *output;
145  size_t inputLength;
151 #if (DeviceFamily_PARENT == DeviceFamily_PARENT_CC27XX)
152 
157  int_fast16_t hsmStatus;
158  /* To indicate whether a segmented operation is in progress
159  */
161 #endif
163 
176 void AESCTRLPF3_processData(const uint8_t *input, uint8_t *output, size_t inputLength, bool isOneStepOrFinalOperation);
177 
189 size_t AESCTRLPF3_configDataDMA(AESCommonLPF3_Object *object,
190  const uint8_t *input,
191  uint8_t *output,
192  size_t inputLength);
193 
201 __STATIC_INLINE void AESCTRLPF3_readCounter(uint32_t counterOut[AES_BLOCK_SIZE_WORDS])
202 {
203  /* Read the latest counter value from the AES engine */
204  AESReadBUF32(&counterOut[0]);
205 }
206 
212 __STATIC_INLINE void AESCTRLPF3_writeCounter(uint32_t counterIn[AES_BLOCK_SIZE_WORDS])
213 {
214  AESWriteBUF32(&counterIn[0]);
215 }
216 
233 __STATIC_INLINE bool AESCTR_acquireLock(AESCTR_Handle handle, uint32_t timeout)
234 {
235  return CryptoResourceLPF3_acquireLock(timeout);
236 }
247 __STATIC_INLINE void AESCTR_releaseLock(AESCTR_Handle handle)
248 {
250 }
261 __STATIC_INLINE void AESCTR_enableThreadSafety(AESCTR_Handle handle)
262 {
263  AESCTRLPF3_Object *object = handle->object;
264  object->threadSafe = true;
265 }
279 __STATIC_INLINE void AESCTR_disableThreadSafety(AESCTR_Handle handle)
280 {
281  AESCTRLPF3_Object *object = handle->object;
282  object->threadSafe = false;
283 }
286 #ifdef __cplusplus
287 }
288 #endif
289 
290 #endif /* ti_drivers_aesctr_AESCTRLPF3__include */
size_t inputLength
Definition: AESCTRLPF3.h:145
AESCommonLPF3_HWAttrs AESCTRLPF3_HWAttrs
AESCTRLPF3 Hardware Attributes.
Definition: AESCTRLPF3.h:131
bool CryptoResourceLPF3_acquireLock(uint32_t timeout)
void(* AESCTR_CallbackFxn)(AESCTR_Handle handle, int_fast16_t returnValue, AESCTR_OperationUnion *operation, AESCTR_OperationType operationType)
The definition of a callback function used by the AESCTR driver when used in AESCTR_RETURN_BEHAVIOR_C...
Definition: AESCTR.h:736
AES Global configuration.
Definition: AESCommon.h:154
uint8_t * output
Definition: AESCTRLPF3.h:144
AESCTR_OperationType
Enum for the operation types supported by the driver.
Definition: AESCTR.h:693
AESCTRLPF3 Object.
Definition: AESCTRLPF3.h:138
AESCTR_OperationUnion * operation
Definition: AESCTRLPF3.h:147
AESCTR_OperationType operationType
Definition: AESCTRLPF3.h:149
AESCommonLPF3 Hardware Attributes.
Definition: AESCommonLPF3.h:80
void CryptoResourceLPF3_releaseLock(void)
AESCommon driver implementation for the Low Power F3 family.
Shared resources to arbitrate access to the AES engine.
void * object
Definition: AESCommon.h:157
size_t inputLengthRemaining
Definition: AESCTRLPF3.h:146
AESCTR_CallbackFxn callbackFxn
Definition: AESCTRLPF3.h:148
Union containing a reference to a one-step and segmented operation structure.
Definition: AESCTR.h:655
int_fast16_t hsmStatus
The staus of the HSM Boot up process if HSMLPF3_STATUS_SUCCESS, the HSM booted properly. if HSMLPF3_STATUS_ERROR, the HSM did not boot properly.
Definition: AESCTRLPF3.h:157
bool segmentedOperationInProgress
Definition: AESCTRLPF3.h:160
AESCTR driver header.
bool threadSafe
Definition: AESCTRLPF3.h:150
const uint8_t * input
Definition: AESCTRLPF3.h:143
AESCommonLPF3 Object.
Definition: AESCommonLPF3.h:102
AESCommonLPF3_Object common
Definition: AESCTRLPF3.h:141
© Copyright 1995-2024, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale