ti_psa_crypto_cipher.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_CIPHER_H
23 #define TI_PSA_CRYPTO_CIPHER_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))
39 #elif ((DeviceFamily_PARENT == DeviceFamily_PARENT_CC13X2_CC26X2) || \
40  (DeviceFamily_PARENT == DeviceFamily_PARENT_CC13X4_CC26X3_CC26X4))
41  #include <ti/drivers/aesecb/AESECBCC26XX.h>
42  #include <ti/drivers/aescbc/AESCBCCC26XX.h>
43  #include <ti/drivers/aesctr/AESCTRCC26XX.h>
44 #endif
46 {
47  union
48  {
49  struct
50  {
52 #if ((DeviceFamily_PARENT == DeviceFamily_PARENT_CC27XX) || (DeviceFamily_PARENT == DeviceFamily_PARENT_CC35XX))
54 #elif ((DeviceFamily_PARENT == DeviceFamily_PARENT_CC13X2_CC26X2) || \
55  (DeviceFamily_PARENT == DeviceFamily_PARENT_CC13X4_CC26X3_CC26X4))
56  AESECBCC26XX_Object aesecbObject;
57 #endif
58  } aesecb;
59  struct
60  {
62 #if ((DeviceFamily_PARENT == DeviceFamily_PARENT_CC27XX) || (DeviceFamily_PARENT == DeviceFamily_PARENT_CC35XX))
64 #elif ((DeviceFamily_PARENT == DeviceFamily_PARENT_CC13X2_CC26X2) || \
65  (DeviceFamily_PARENT == DeviceFamily_PARENT_CC13X4_CC26X3_CC26X4))
66  AESCBCCC26XX_Object aescbcObject;
67 #endif
68  } aescbc;
69  struct
70  {
72 #if ((DeviceFamily_PARENT == DeviceFamily_PARENT_CC27XX) || (DeviceFamily_PARENT == DeviceFamily_PARENT_CC35XX))
74 #elif ((DeviceFamily_PARENT == DeviceFamily_PARENT_CC13X2_CC26X2) || \
75  (DeviceFamily_PARENT == DeviceFamily_PARENT_CC13X4_CC26X3_CC26X4))
76  AESCTRCC26XX_Object aesctrObject;
77 #endif
78  } aesctr;
79  /* Add other driver structs here as needed */
80  } driver;
81  /* Used to mark the operation struct as ready.*/
82  unsigned int id;
83  unsigned int iv_required:1;
84  unsigned int iv_set:1;
85  unsigned int is_encrypt:1;
86  unsigned int in_error_state:1;
88  psa_algorithm_t alg;
89 
92 
93  /* Buffer for data that has not been processed yet. Word-aligned for max
94  * performance and in case any drivers require aligned input buffer.
95  * Double-buffer is used when PSA crypto is built into the TFM to prevent
96  * corruption before the data can be consumed since the underlying crypto
97  * drivers are used in callback mode. */
98 #ifdef TFM_BUILD
99  uint8_t unprocessed_data[PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE * 2] __attribute__((aligned(4)));
100 #else
101  uint8_t unprocessed_data[PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE] __attribute__((aligned(4)));
102 #endif /* TFM_BUILD */
103 
104  /* Pointer to the current unprocessed data */
106 
108 };
109 
111 
112 #define TI_PSA_CIPHER_OPERATION_INIT \
113  (ti_psa_cipher_operation_t) \
114  { \
115  0 \
116  }
118 {
120  return (v);
121 }
122 
123 /******************************************************************************/
124 /* Random generation */
125 /******************************************************************************/
126 psa_status_t ti_psa_generate_random(uint8_t *output, size_t output_size);
127 
128 /******************************************************************************/
129 /* Symmetric cryptography */
130 /******************************************************************************/
131 psa_status_t ti_psa_cipher_encrypt_setup(psa_cipher_operation_t *psa_operation,
132  mbedtls_svc_key_id_t key,
133  psa_algorithm_t alg);
134 
135 psa_status_t ti_psa_cipher_decrypt_setup(psa_cipher_operation_t *psa_operation,
136  mbedtls_svc_key_id_t key,
137  psa_algorithm_t alg);
138 
139 psa_status_t ti_psa_cipher_generate_iv(psa_cipher_operation_t *psa_operation,
140  uint8_t *iv,
141  size_t iv_size,
142  size_t *iv_length);
143 
144 psa_status_t ti_psa_cipher_set_iv(psa_cipher_operation_t *psa_operation, const uint8_t *iv, size_t iv_length);
145 
146 psa_status_t ti_psa_cipher_encrypt(mbedtls_svc_key_id_t key,
147  psa_algorithm_t alg,
148  const uint8_t *input,
149  size_t input_length,
150  uint8_t *output,
151  size_t output_size,
152  size_t *output_length);
153 
154 psa_status_t ti_psa_cipher_decrypt(mbedtls_svc_key_id_t key,
155  psa_algorithm_t alg,
156  const uint8_t *input,
157  size_t input_length,
158  uint8_t *output,
159  size_t output_size,
160  size_t *output_length);
161 
162 psa_status_t ti_psa_cipher_update(psa_cipher_operation_t *psa_operation,
163  const uint8_t *input,
164  size_t input_length,
165  uint8_t *output,
166  size_t output_size,
167  size_t *output_length);
168 
169 psa_status_t ti_psa_cipher_finish(psa_cipher_operation_t *psa_operation,
170  uint8_t *output,
171  size_t output_size,
172  size_t *output_length);
173 
174 psa_status_t ti_psa_cipher_abort(psa_cipher_operation_t *psa_operation);
175 
176 #endif /* TI_PSA_CRYPTO_CIPHER_H */
AESCBCXXF3_Object aescbcObject
Definition: ti_psa_crypto_cipher.h:63
The CryptoKey type is an opaque representation of a cryptographic key.
AESCBCXXF3 Object.
Definition: AESCBCXXF3.h:90
psa_status_t ti_psa_cipher_encrypt_setup(psa_cipher_operation_t *psa_operation, mbedtls_svc_key_id_t key, psa_algorithm_t alg)
psa_status_t ti_psa_cipher_encrypt(mbedtls_svc_key_id_t key, psa_algorithm_t alg, const uint8_t *input, size_t input_length, uint8_t *output, size_t output_size, size_t *output_length)
AESECB_Config aesecbConfig
Definition: ti_psa_crypto_cipher.h:51
unsigned int iv_required
Definition: ti_psa_crypto_cipher.h:83
struct ti_psa_cipher_operation_s::@4::@7 aesctr
AES Global configuration.
Definition: AESCommon.h:154
unsigned int in_error_state
Definition: ti_psa_crypto_cipher.h:86
CryptoKey datastructure.
Definition: CryptoKey.h:211
AESCTRXXF3_Object aesctrObject
Definition: ti_psa_crypto_cipher.h:73
union ti_psa_cipher_operation_s::@4 driver
psa_status_t ti_psa_generate_random(uint8_t *output, size_t output_size)
psa_algorithm_t alg
Definition: ti_psa_crypto_cipher.h:88
AESCBC_Config aescbcConfig
Definition: ti_psa_crypto_cipher.h:61
struct ti_psa_cipher_operation_s::@4::@6 aescbc
psa_status_t ti_psa_cipher_generate_iv(psa_cipher_operation_t *psa_operation, uint8_t *iv, size_t iv_size, size_t *iv_length)
CryptoKey cryptoKey
Definition: ti_psa_crypto_cipher.h:107
AESCTR driver implementation for the Low Power F3 family.
unsigned int is_encrypt
Definition: ti_psa_crypto_cipher.h:85
psa_status_t ti_psa_cipher_abort(psa_cipher_operation_t *psa_operation)
AESECBXXF3_Object aesecbObject
Definition: ti_psa_crypto_cipher.h:53
uint8_t * curr_unprocessed_data
Definition: ti_psa_crypto_cipher.h:105
psa_status_t ti_psa_cipher_decrypt_setup(psa_cipher_operation_t *psa_operation, mbedtls_svc_key_id_t key, psa_algorithm_t alg)
static struct ti_psa_cipher_operation_s ti_psa_cipher_operation_init(void)
Definition: ti_psa_crypto_cipher.h:117
AESCTRXXF3 Object.
Definition: AESCTRXXF3.h:134
psa_status_t ti_psa_cipher_finish(psa_cipher_operation_t *psa_operation, uint8_t *output, size_t output_size, size_t *output_length)
AESECB driver implementation for the Low Power F3 family.
psa_status_t ti_psa_cipher_set_iv(psa_cipher_operation_t *psa_operation, const uint8_t *iv, size_t iv_length)
Definition: ti_psa_crypto_cipher.h:45
size_t unprocessed_len
Definition: ti_psa_crypto_cipher.h:91
#define TI_PSA_CIPHER_OPERATION_INIT
Definition: ti_psa_crypto_cipher.h:112
AESCTR_Config aesctrConfig
Definition: ti_psa_crypto_cipher.h:71
unsigned int id
Definition: ti_psa_crypto_cipher.h:82
size_t default_iv_length
Definition: ti_psa_crypto_cipher.h:87
struct ti_psa_cipher_operation_s::@4::@5 aesecb
psa_status_t ti_psa_cipher_decrypt(mbedtls_svc_key_id_t key, psa_algorithm_t alg, const uint8_t *input, size_t input_length, uint8_t *output, size_t output_size, size_t *output_length)
psa_status_t ti_psa_cipher_update(psa_cipher_operation_t *psa_operation, const uint8_t *input, size_t input_length, uint8_t *output, size_t output_size, size_t *output_length)
AESCBC driver implementation for the Low Power F3 devices.
AESECBXXF3 Object.
Definition: AESECBXXF3.h:109
uint8_t unprocessed_data[PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE]
Definition: ti_psa_crypto_cipher.h:101
unsigned int iv_set
Definition: ti_psa_crypto_cipher.h:84
© Copyright 1995-2026, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale