ti_psa_crypto_aead.h
Go to the documentation of this file.
1 /*
2  * Copyright The Mbed TLS Contributors
3  * Copyright 2025, Texas Instruments Incorporated
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License"); you may
7  * not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * Modified by Texas Instruments to support SimpleLink device crypto hardware
19  * drivers.
20  */
21 
22 #ifndef TI_PSA_CRYPTO_AEAD_H
23 #define TI_PSA_CRYPTO_AEAD_H
24 
25 #include <stddef.h>
26 #include <stdint.h>
27 
28 #if ((TFM_ENABLED == 1) && !defined(TFM_BUILD))
29  #include <third_party/tfm/interface/include/psa/crypto.h>
30 #else
31  #include <third_party/mbedtls/include/psa/crypto.h>
32 #endif
34 #include <ti/devices/DeviceFamily.h>
35 #if ((DeviceFamily_PARENT == DeviceFamily_PARENT_CC27XX) || (DeviceFamily_PARENT == DeviceFamily_PARENT_CC35XX))
38 #elif ((DeviceFamily_PARENT == DeviceFamily_PARENT_CC13X2_CC26X2) || \
39  (DeviceFamily_PARENT == DeviceFamily_PARENT_CC13X4_CC26X3_CC26X4))
40  #include <ti/drivers/aesccm/AESCCMCC26XX.h>
41  #include <ti/drivers/aesgcm/AESGCMCC26XX.h>
42 #endif
43 
45 {
46  union
47  {
48  struct
49  {
51 #if ((DeviceFamily_PARENT == DeviceFamily_PARENT_CC27XX) || (DeviceFamily_PARENT == DeviceFamily_PARENT_CC35XX))
53 #elif ((DeviceFamily_PARENT == DeviceFamily_PARENT_CC13X2_CC26X2) || \
54  (DeviceFamily_PARENT == DeviceFamily_PARENT_CC13X4_CC26X3_CC26X4))
55  AESCCMCC26XX_Object aesccmObject;
56 #endif
57  } aesccm;
58  struct
59  {
61 #if ((DeviceFamily_PARENT == DeviceFamily_PARENT_CC27XX) || (DeviceFamily_PARENT == DeviceFamily_PARENT_CC35XX))
63 #elif ((DeviceFamily_PARENT == DeviceFamily_PARENT_CC13X2_CC26X2) || \
64  (DeviceFamily_PARENT == DeviceFamily_PARENT_CC13X4_CC26X3_CC26X4))
65  AESGCMCC26XX_Object aesgcmObject;
66 #endif
67  } aesgcm;
68  } driver;
69  /* Used to mark the operation struct as ready.*/
70  unsigned int id;
71  psa_algorithm_t alg;
72  unsigned int iv_set:1;
73  unsigned int in_error_state:1;
74  size_t adLength;
78  size_t tagSize;
79 
80  /* Buffer for data that has not been processed yet. Word-aligned for max
81  * performance and in case any drivers require aligned input buffer.
82  * Double-buffer is used when PSA crypto is built into the TFM to prevent
83  * corruption before the data can be consumed since the underlying crypto
84  * drivers are used in callback mode. */
85 #ifdef TFM_BUILD
86  uint8_t unprocessedData[PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE * 2] __attribute__((aligned(4)));
87 #else
88  uint8_t unprocessedData[PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE] __attribute__((aligned(4)));
89 #endif /* TFM_BUILD */
90 
91  /* Pointer to the current unprocessed data */
93 
95 
98  bool length_set;
99 };
100 
102 
103 #define TI_PSA_AEAD_OPERATION_INIT \
104  (ti_psa_aead_operation_t) \
105  { \
106  0 \
107  }
109 {
111  return (v);
112 }
113 
114 /******************************************************************************/
115 /* Multi-Step AEAD */
116 /******************************************************************************/
117 psa_status_t ti_psa_aead_abort(psa_aead_operation_t *psa_operation);
118 
119 psa_status_t ti_psa_aead_encrypt_setup(psa_aead_operation_t *psa_operation,
120  mbedtls_svc_key_id_t key,
121  psa_algorithm_t alg);
122 
123 psa_status_t ti_psa_aead_decrypt_setup(psa_aead_operation_t *psa_operation,
124  mbedtls_svc_key_id_t key,
125  psa_algorithm_t alg);
126 
127 psa_status_t ti_psa_aead_finish(psa_aead_operation_t *psa_operation,
128  uint8_t *ciphertext,
129  size_t ciphertext_size,
130  size_t *ciphertext_length,
131  uint8_t *tag,
132  size_t tag_size,
133  size_t *tag_length);
134 
135 psa_status_t ti_psa_aead_update(psa_aead_operation_t *psa_operation,
136  const uint8_t *input,
137  size_t input_length,
138  uint8_t *output,
139  size_t output_size,
140  size_t *output_length);
141 
142 psa_status_t ti_psa_aead_update_ad(psa_aead_operation_t *psa_operation, const uint8_t *input, size_t input_length);
143 
144 /******************************************************************************/
145 /* One-Step AEAD */
146 /******************************************************************************/
147 psa_status_t ti_psa_aead_encrypt(mbedtls_svc_key_id_t key,
148  psa_algorithm_t alg,
149  const uint8_t *nonce,
150  size_t nonce_length,
151  const uint8_t *additional_data,
152  size_t additional_data_length,
153  const uint8_t *plaintext,
154  size_t plaintext_length,
155  uint8_t *ciphertext,
156  size_t ciphertext_size,
157  size_t *ciphertext_length);
158 
159 psa_status_t ti_psa_aead_decrypt(mbedtls_svc_key_id_t key,
160  psa_algorithm_t alg,
161  const uint8_t *nonce,
162  size_t nonce_length,
163  const uint8_t *additional_data,
164  size_t additional_data_length,
165  const uint8_t *ciphertext,
166  size_t ciphertext_length,
167  uint8_t *plaintext,
168  size_t plaintext_size,
169  size_t *plaintext_length);
170 
171 psa_status_t ti_psa_aead_generate_nonce(psa_aead_operation_t *psa_operation,
172  uint8_t *nonce,
173  size_t nonce_size,
174  size_t *nonce_length);
175 
176 psa_status_t ti_psa_aead_set_lengths(psa_aead_operation_t *psa_operation, size_t ad_length, size_t plaintext_length);
177 
178 psa_status_t ti_psa_aead_set_nonce(psa_aead_operation_t *psa_operation, const uint8_t *nonce, size_t nonce_length);
179 
180 psa_status_t ti_psa_aead_verify(psa_aead_operation_t *psa_operation,
181  uint8_t *plaintext,
182  size_t plaintext_size,
183  size_t *plaintext_length,
184  const uint8_t *tag,
185  size_t tag_length);
186 
187 #endif /* TI_PSA_CRYPTO_AEAD_H */
AESCCM driver implementation for the Low Power F3 family.
size_t adLength
Definition: ti_psa_crypto_aead.h:74
bool length_set
Definition: ti_psa_crypto_aead.h:98
The CryptoKey type is an opaque representation of a cryptographic key.
unsigned int id
Definition: ti_psa_crypto_aead.h:70
psa_status_t ti_psa_aead_generate_nonce(psa_aead_operation_t *psa_operation, uint8_t *nonce, size_t nonce_size, size_t *nonce_length)
psa_algorithm_t alg
Definition: ti_psa_crypto_aead.h:71
size_t unprocessed_len
Definition: ti_psa_crypto_aead.h:94
AESCCMXXF3 Object.
Definition: AESCCMXXF3.h:105
uint8_t * curr_unprocessed_data
Definition: ti_psa_crypto_aead.h:92
psa_status_t ti_psa_aead_set_nonce(psa_aead_operation_t *psa_operation, const uint8_t *nonce, size_t nonce_length)
size_t tagSize
Definition: ti_psa_crypto_aead.h:78
AES Global configuration.
Definition: AESCommon.h:154
CryptoKey datastructure.
Definition: CryptoKey.h:211
uint8_t unprocessedData[PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE]
Definition: ti_psa_crypto_aead.h:88
psa_status_t ti_psa_aead_encrypt(mbedtls_svc_key_id_t key, psa_algorithm_t alg, const uint8_t *nonce, size_t nonce_length, const uint8_t *additional_data, size_t additional_data_length, const uint8_t *plaintext, size_t plaintext_length, uint8_t *ciphertext, size_t ciphertext_size, size_t *ciphertext_length)
psa_status_t ti_psa_aead_update_ad(psa_aead_operation_t *psa_operation, const uint8_t *input, size_t input_length)
psa_status_t ti_psa_aead_decrypt_setup(psa_aead_operation_t *psa_operation, mbedtls_svc_key_id_t key, psa_algorithm_t alg)
AESCCMXXF3_Object aesccmObject
Definition: ti_psa_crypto_aead.h:52
union ti_psa_aead_operation_s::@1 driver
size_t runningADLength
Definition: ti_psa_crypto_aead.h:76
psa_status_t ti_psa_aead_abort(psa_aead_operation_t *psa_operation)
AESGCMXXF3HSM Object.
Definition: AESGCMXXF3HSM.h:97
psa_status_t ti_psa_aead_update(psa_aead_operation_t *psa_operation, const uint8_t *input, size_t input_length, uint8_t *output, size_t output_size, size_t *output_length)
struct ti_psa_aead_operation_s::@1::@2 aesccm
psa_status_t ti_psa_aead_set_lengths(psa_aead_operation_t *psa_operation, size_t ad_length, size_t plaintext_length)
struct ti_psa_aead_operation_s::@1::@3 aesgcm
psa_status_t ti_psa_aead_finish(psa_aead_operation_t *psa_operation, uint8_t *ciphertext, size_t ciphertext_size, size_t *ciphertext_length, uint8_t *tag, size_t tag_size, size_t *tag_length)
Definition: ti_psa_crypto_aead.h:44
static struct ti_psa_aead_operation_s ti_psa_aead_operation_init(void)
Definition: ti_psa_crypto_aead.h:108
AESCCM_Config aesccmConfig
Definition: ti_psa_crypto_aead.h:50
CryptoKey cryptoKey
Definition: ti_psa_crypto_aead.h:96
size_t plaintextLength
Definition: ti_psa_crypto_aead.h:75
psa_status_t ti_psa_aead_verify(psa_aead_operation_t *psa_operation, uint8_t *plaintext, size_t plaintext_size, size_t *plaintext_length, const uint8_t *tag, size_t tag_length)
AESGCM_Config aesgcmConfig
Definition: ti_psa_crypto_aead.h:60
psa_status_t ti_psa_aead_encrypt_setup(psa_aead_operation_t *psa_operation, mbedtls_svc_key_id_t key, psa_algorithm_t alg)
#define TI_PSA_AEAD_OPERATION_INIT
Definition: ti_psa_crypto_aead.h:103
unsigned int in_error_state
Definition: ti_psa_crypto_aead.h:73
AESGCMXXF3HSM_Object aesgcmObject
Definition: ti_psa_crypto_aead.h:62
unsigned int iv_set
Definition: ti_psa_crypto_aead.h:72
psa_status_t ti_psa_aead_decrypt(mbedtls_svc_key_id_t key, psa_algorithm_t alg, const uint8_t *nonce, size_t nonce_length, const uint8_t *additional_data, size_t additional_data_length, const uint8_t *ciphertext, size_t ciphertext_length, uint8_t *plaintext, size_t plaintext_size, size_t *plaintext_length)
bool done_updating_ad
Definition: ti_psa_crypto_aead.h:97
AESGCM driver implementation for the Low Power F3 family.
size_t runningPlaintextLength
Definition: ti_psa_crypto_aead.h:77
© Copyright 1995-2026, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale