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 #define AESCTRLPF3_DEFAULT_AUTOCFG \
82  ((uint32_t)AES_AUTOCFG_ECBSRC_BUF | (uint32_t)AES_AUTOCFG_TRGECB_WRBUF3S | (uint32_t)AES_AUTOCFG_TRGECB_RDTXT3 | \
83  (uint32_t)AES_AUTOCFG_CTRSIZE_CTR128 | (uint32_t)AES_AUTOCFG_CTRENDN_BIGENDIAN | \
84  (uint32_t)AES_AUTOCFG_BUSHALT_EN)
85 
86 /*
87  * AES CTR auto config for handling processing of the last
88  * block of input to avoid starting encryption of the next counter block and
89  * incrementing the counter value when the output is read from TXT3.
90  *
91  * ECB SRC as BUF
92  * Trigger for auto ECB as WRBUF3S
93  * (the first encryption starts by writing BUF3)
94  * Counter size as 128-bits
95  * Counter endianness as Big Endian
96  */
97 #define AESCTRLPF3_LAST_BLOCK_AUTOCFG \
98  ((uint32_t)AES_AUTOCFG_ECBSRC_BUF | (uint32_t)AES_AUTOCFG_TRGECB_WRBUF3S | (uint32_t)AES_AUTOCFG_CTRSIZE_CTR128 | \
99  (uint32_t)AES_AUTOCFG_CTRENDN_BIGENDIAN | (uint32_t)AES_AUTOCFG_BUSHALT_EN)
100 
108 
114 typedef struct
115 {
116  /* Common member first to allow struct to be cast to the common type */
118  volatile uint32_t counter[AES_BLOCK_SIZE_WORDS];
119  const uint8_t *input;
120  uint8_t *output;
121  size_t inputLength;
128 
141 void AESCTRLPF3_processData(const uint8_t *input, uint8_t *output, size_t inputLength, bool isOneStepOrFinalOperation);
142 
154 size_t AESCTRLPF3_configDataDMA(AESCommonLPF3_Object *object,
155  const uint8_t *input,
156  uint8_t *output,
157  size_t inputLength);
158 
166 __STATIC_INLINE void AESCTRLPF3_readCounter(uint32_t counterOut[AES_BLOCK_SIZE_WORDS])
167 {
168  /* Read the latest counter value from the AES engine */
169  AESReadBUF32(&counterOut[0]);
170 }
171 
177 __STATIC_INLINE void AESCTRLPF3_writeCounter(uint32_t counterIn[AES_BLOCK_SIZE_WORDS])
178 {
179  AESWriteBUF32(&counterIn[0]);
180 }
181 
198 __STATIC_INLINE bool AESCTR_acquireLock(AESCTR_Handle handle, uint32_t timeout)
199 {
200  return CryptoResourceLPF3_acquireLock(timeout);
201 }
212 __STATIC_INLINE void AESCTR_releaseLock(AESCTR_Handle handle)
213 {
215 }
226 __STATIC_INLINE void AESCTR_enableThreadSafety(AESCTR_Handle handle)
227 {
228  AESCTRLPF3_Object *object = handle->object;
229  object->threadSafe = true;
230 }
244 __STATIC_INLINE void AESCTR_disableThreadSafety(AESCTR_Handle handle)
245 {
246  AESCTRLPF3_Object *object = handle->object;
247  object->threadSafe = false;
248 }
251 #ifdef __cplusplus
252 }
253 #endif
254 
255 #endif /* ti_drivers_aesctr_AESCTRLPF3__include */
size_t inputLength
Definition: AESCTRLPF3.h:121
AESCommonLPF3_HWAttrs AESCTRLPF3_HWAttrs
AESCTRLPF3 Hardware Attributes.
Definition: AESCTRLPF3.h:107
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:120
AESCTR_OperationType
Enum for the operation types supported by the driver.
Definition: AESCTR.h:623
AESCTRLPF3 Object.
Definition: AESCTRLPF3.h:114
AESCTR_OperationUnion * operation
Definition: AESCTRLPF3.h:123
AESCTR_OperationType operationType
Definition: AESCTRLPF3.h:125
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:122
AESCTR_CallbackFxn callbackFxn
Definition: AESCTRLPF3.h:124
Union containing a reference to a one-step and segmented operation structure.
Definition: AESCTR.h:585
AESCTR driver header.
bool threadSafe
Definition: AESCTRLPF3.h:126
const uint8_t * input
Definition: AESCTRLPF3.h:119
AESCommonLPF3 Object.
Definition: AESCommonLPF3.h:102
AESCommonLPF3_Object common
Definition: AESCTRLPF3.h:117
© Copyright 1995-2023, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale