AESCTRLPF3.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021-2023, 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  */
55 #ifndef ti_drivers_aesctr_AESCTRLPF3__include
56 #define ti_drivers_aesctr_AESCTRLPF3__include
57 
58 #include <stdbool.h>
59 #include <stdint.h>
60 
61 #include <ti/drivers/AESCTR.h>
64 
65 #include <ti/devices/DeviceFamily.h>
66 #include DeviceFamily_constructPath(driverlib/aes.h)
67 
68 #ifdef __cplusplus
69 extern "C" {
70 #endif
71 
72 /*
73  * Default AES CTR auto config:
74  * ECB SRC as BUF
75  * Trigger points for auto ECB as RDTX3 and WRBUF3S
76  * (the first encryption starts by writing BUF3, the successive ones by reading TXT3)
77  * Counter size as 128-bits
78  * Counter endianness as Big Endian
79  * BUSHALT enabled
80  */
81 #if (DeviceFamily_PARENT == DeviceFamily_PARENT_CC27XX)
82  #define AES_AUTOCFG_CTRENDN_BIGENDIAN AES_AUTOCFG_CTRENDIAN_BIGENDIAN
83 #endif
84 
85 #if DeviceFamily_PARENT == DeviceFamily_PARENT_CC23X0
86  #define AESCTRLPF3_DEFAULT_AUTOCFG \
87  ((uint32_t)AES_AUTOCFG_AESSRC_BUF | (uint32_t)AES_AUTOCFG_TRGAES_WRBUF3S | \
88  (uint32_t)AES_AUTOCFG_TRGAES_RDTXT3 | (uint32_t)AES_AUTOCFG_CTRSIZE_CTR128 | \
89  (uint32_t)AES_AUTOCFG_CTRENDN_BIGENDIAN | (uint32_t)AES_AUTOCFG_BUSHALT_EN)
90 #elif DeviceFamily_PARENT == DeviceFamily_PARENT_CC27XX
91  #define AESCTRLPF3_DEFAULT_AUTOCFG \
92  ((uint32_t)AES_AUTOCFG_ECBSRC_BUF | (uint32_t)AES_AUTOCFG_TRGECB_WRBUF3S | \
93  (uint32_t)AES_AUTOCFG_TRGECB_RDTXT3 | (uint32_t)AES_AUTOCFG_CTRSIZE_CTR128 | \
94  (uint32_t)AES_AUTOCFG_CTRENDN_BIGENDIAN | (uint32_t)AES_AUTOCFG_BUSHALT_EN)
95 #else
96  #error "Unsupported DeviceFamily_Parent for AESCTRLPF3!"
97 #endif
98 
99 /*
100  * AES CTR auto config for handling processing of the last
101  * block of input to avoid starting encryption of the next counter block and
102  * incrementing the counter value when the output is read from TXT3.
103  *
104  * ECB SRC as BUF
105  * Trigger for auto ECB as WRBUF3S
106  * (the first encryption starts by writing BUF3)
107  * Counter size as 128-bits
108  * Counter endianness as Big Endian
109  */
110 #if DeviceFamily_PARENT == DeviceFamily_PARENT_CC23X0
111  #define AESCTRLPF3_LAST_BLOCK_AUTOCFG \
112  ((uint32_t)AES_AUTOCFG_AESSRC_BUF | (uint32_t)AES_AUTOCFG_TRGAES_WRBUF3S | \
113  (uint32_t)AES_AUTOCFG_CTRSIZE_CTR128 | (uint32_t)AES_AUTOCFG_CTRENDN_BIGENDIAN | \
114  (uint32_t)AES_AUTOCFG_BUSHALT_EN)
115 #elif DeviceFamily_PARENT == DeviceFamily_PARENT_CC27XX
116  #define AESCTRLPF3_LAST_BLOCK_AUTOCFG \
117  ((uint32_t)AES_AUTOCFG_ECBSRC_BUF | (uint32_t)AES_AUTOCFG_TRGECB_WRBUF3S | \
118  (uint32_t)AES_AUTOCFG_CTRSIZE_CTR128 | (uint32_t)AES_AUTOCFG_CTRENDN_BIGENDIAN | \
119  (uint32_t)AES_AUTOCFG_BUSHALT_EN)
120 #else
121  #error "Unsupported DeviceFamily_Parent for AESCTRLPF3!"
122 #endif
123 
131 
137 typedef struct
138 {
139  /* Common member first to allow struct to be cast to the common type */
141  volatile uint32_t counter[AES_BLOCK_SIZE_WORDS];
142  const uint8_t *input;
143  uint8_t *output;
144  size_t inputLength;
151 
164 void AESCTRLPF3_processData(const uint8_t *input, uint8_t *output, size_t inputLength, bool isOneStepOrFinalOperation);
165 
177 size_t AESCTRLPF3_configDataDMA(AESCommonLPF3_Object *object,
178  const uint8_t *input,
179  uint8_t *output,
180  size_t inputLength);
181 
189 __STATIC_INLINE void AESCTRLPF3_readCounter(uint32_t counterOut[AES_BLOCK_SIZE_WORDS])
190 {
191  /* Read the latest counter value from the AES engine */
192  AESReadBUF32(&counterOut[0]);
193 }
194 
200 __STATIC_INLINE void AESCTRLPF3_writeCounter(uint32_t counterIn[AES_BLOCK_SIZE_WORDS])
201 {
202  AESWriteBUF32(&counterIn[0]);
203 }
204 
221 __STATIC_INLINE bool AESCTR_acquireLock(AESCTR_Handle handle, uint32_t timeout)
222 {
223  return CryptoResourceLPF3_acquireLock(timeout);
224 }
235 __STATIC_INLINE void AESCTR_releaseLock(AESCTR_Handle handle)
236 {
238 }
249 __STATIC_INLINE void AESCTR_enableThreadSafety(AESCTR_Handle handle)
250 {
251  AESCTRLPF3_Object *object = handle->object;
252  object->threadSafe = true;
253 }
267 __STATIC_INLINE void AESCTR_disableThreadSafety(AESCTR_Handle handle)
268 {
269  AESCTRLPF3_Object *object = handle->object;
270  object->threadSafe = false;
271 }
274 #ifdef __cplusplus
275 }
276 #endif
277 
278 #endif /* ti_drivers_aesctr_AESCTRLPF3__include */
size_t inputLength
Definition: AESCTRLPF3.h:144
AESCommonLPF3_HWAttrs AESCTRLPF3_HWAttrs
AESCTRLPF3 Hardware Attributes.
Definition: AESCTRLPF3.h:130
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:666
AES Global configuration.
Definition: AESCommon.h:154
uint8_t * output
Definition: AESCTRLPF3.h:143
AESCTR_OperationType
Enum for the operation types supported by the driver.
Definition: AESCTR.h:623
AESCTRLPF3 Object.
Definition: AESCTRLPF3.h:137
AESCTR_OperationUnion * operation
Definition: AESCTRLPF3.h:146
AESCTR_OperationType operationType
Definition: AESCTRLPF3.h:148
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:145
AESCTR_CallbackFxn callbackFxn
Definition: AESCTRLPF3.h:147
Union containing a reference to a one-step and segmented operation structure.
Definition: AESCTR.h:585
AESCTR driver header.
bool threadSafe
Definition: AESCTRLPF3.h:149
const uint8_t * input
Definition: AESCTRLPF3.h:142
AESCommonLPF3 Object.
Definition: AESCommonLPF3.h:102
AESCommonLPF3_Object common
Definition: AESCTRLPF3.h:140
© Copyright 1995-2023, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale