ti_psa_crypto_mac.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_MAC_H
23 #define TI_PSA_CRYPTO_MAC_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/sha2/SHA2CC26X2.h>
41  #include <ti/drivers/aescmac/AESCMACCC26XX.h>
42 #endif
43 
45 {
46  union
47  {
48  struct
49  {
51 #if ((DeviceFamily_PARENT == DeviceFamily_PARENT_CC27XX) || (DeviceFamily_PARENT == DeviceFamily_PARENT_CC35XX))
52  SHA2XXF3HSM_Object sha2Object;
53 #elif ((DeviceFamily_PARENT == DeviceFamily_PARENT_CC13X2_CC26X2) || \
54  (DeviceFamily_PARENT == DeviceFamily_PARENT_CC13X4_CC26X3_CC26X4))
55  SHA2CC26X2_Object sha2Object;
56 #endif
57  } sha2;
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  AESCMACCC26XX_Object aescmacObject;
66 #endif
67  } aescmac;
68  struct
69  {
71 #if ((DeviceFamily_PARENT == DeviceFamily_PARENT_CC27XX) || (DeviceFamily_PARENT == DeviceFamily_PARENT_CC35XX))
73 #elif ((DeviceFamily_PARENT == DeviceFamily_PARENT_CC13X2_CC26X2) || \
74  (DeviceFamily_PARENT == DeviceFamily_PARENT_CC13X4_CC26X3_CC26X4))
75  AESCMACCC26XX_Object aescbcmacObject;
76 #endif
77  } aescbcmac;
78  } driver;
85  unsigned int id;
86  size_t mac_size;
87  psa_algorithm_t alg;
89 
90  /* Buffer for data that has not been processed yet. Word-aligned for max
91  * performance and in case any drivers require aligned input buffer.
92  * Double-buffer is used when PSA crypto is built into the TFM to prevent
93  * corruption before the data can be consumed since the underlying crypto
94  * drivers are used in callback mode. */
95 #ifdef TFM_BUILD
96  uint8_t unprocessedData[PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE * 2] __attribute__((aligned(4)));
97 #else
98  uint8_t unprocessedData[PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE] __attribute__((aligned(4)));
99 #endif /* TFM_BUILD */
100 
101  /* Pointer to the current unprocessed data */
103 
105  bool is_sign;
106 };
107 
109 
110 #define TI_PSA_MAC_OPERATION_INIT \
111  (ti_psa_mac_operation_t) \
112  { \
113  0 \
114  }
115 
117 {
119  return (v);
120 }
121 
122 /******************************************************************************/
123 /* Multi-Step Message Authentication Code (MAC) */
124 /******************************************************************************/
125 psa_status_t ti_psa_mac_abort(psa_mac_operation_t *psa_operation);
126 
127 psa_status_t ti_psa_mac_sign_finish(psa_mac_operation_t *psa_operation,
128  uint8_t *mac,
129  size_t mac_size,
130  size_t *mac_length);
131 
132 psa_status_t ti_psa_mac_sign_setup(psa_mac_operation_t *psa_operation, mbedtls_svc_key_id_t key, psa_algorithm_t alg);
133 
134 psa_status_t ti_psa_mac_update(psa_mac_operation_t *psa_operation, const uint8_t *input, size_t input_length);
135 
136 psa_status_t ti_psa_mac_verify_finish(psa_mac_operation_t *psa_operation, const uint8_t *mac, size_t mac_length);
137 
138 psa_status_t ti_psa_mac_verify_setup(psa_mac_operation_t *psa_operation, mbedtls_svc_key_id_t key, psa_algorithm_t alg);
139 
140 /******************************************************************************/
141 /* One-Step Message Authentication Code (MAC) */
142 /******************************************************************************/
143 psa_status_t ti_psa_mac_compute(mbedtls_svc_key_id_t key,
144  psa_algorithm_t alg,
145  const uint8_t *input,
146  size_t input_length,
147  uint8_t *mac,
148  size_t mac_size,
149  size_t *mac_length);
150 
151 psa_status_t ti_psa_mac_verify(mbedtls_svc_key_id_t key,
152  psa_algorithm_t alg,
153  const uint8_t *input,
154  size_t input_length,
155  const uint8_t *mac,
156  size_t mac_length);
157 
158 #endif /* TI_PSA_CRYPTO_MAC_H */
psa_status_t ti_psa_mac_abort(psa_mac_operation_t *psa_operation)
The CryptoKey type is an opaque representation of a cryptographic key.
struct ti_psa_mac_operation_s::@8::@11 aescbcmac
psa_status_t ti_psa_mac_sign_setup(psa_mac_operation_t *psa_operation, mbedtls_svc_key_id_t key, psa_algorithm_t alg)
AES Global configuration.
Definition: AESCommon.h:154
union ti_psa_mac_operation_s::@8 driver
CryptoKey cryptoKey
Definition: ti_psa_crypto_mac.h:104
psa_status_t ti_psa_mac_verify_finish(psa_mac_operation_t *psa_operation, const uint8_t *mac, size_t mac_length)
SHA2 Global configuration.
Definition: SHA2.h:553
CryptoKey datastructure.
Definition: CryptoKey.h:211
struct ti_psa_mac_operation_s::@8::@10 aescmac
AESCMACXXF3_Object aescmacObject
Definition: ti_psa_crypto_mac.h:62
unsigned int id
Definition: ti_psa_crypto_mac.h:85
SHA2XXF3HSM_Object sha2Object
Definition: ti_psa_crypto_mac.h:52
uint8_t * curr_unprocessed_data
Definition: ti_psa_crypto_mac.h:102
psa_status_t ti_psa_mac_compute(mbedtls_svc_key_id_t key, psa_algorithm_t alg, const uint8_t *input, size_t input_length, uint8_t *mac, size_t mac_size, size_t *mac_length)
uint8_t unprocessedData[PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE]
Definition: ti_psa_crypto_mac.h:98
SHA2_Config sha2Config
Definition: ti_psa_crypto_mac.h:50
AESCMAC_Config aescbcmacConfig
Definition: ti_psa_crypto_mac.h:70
size_t mac_size
Definition: ti_psa_crypto_mac.h:86
size_t unprocessed_len
Definition: ti_psa_crypto_mac.h:88
Definition: ti_psa_crypto_mac.h:44
bool is_sign
Definition: ti_psa_crypto_mac.h:105
static struct ti_psa_mac_operation_s ti_psa_mac_operation_init(void)
Definition: ti_psa_crypto_mac.h:116
struct ti_psa_mac_operation_s::@8::@9 sha2
psa_status_t ti_psa_mac_verify(mbedtls_svc_key_id_t key, psa_algorithm_t alg, const uint8_t *input, size_t input_length, const uint8_t *mac, size_t mac_length)
#define TI_PSA_MAC_OPERATION_INIT
Definition: ti_psa_crypto_mac.h:110
psa_status_t ti_psa_mac_update(psa_mac_operation_t *psa_operation, const uint8_t *input, size_t input_length)
AESCMACXXF3_Object aescbcmacObject
Definition: ti_psa_crypto_mac.h:72
psa_algorithm_t alg
Definition: ti_psa_crypto_mac.h:87
AESCMAC_Config aescmacConfig
Definition: ti_psa_crypto_mac.h:60
AESCMACXXF3 Object.
Definition: AESCMACXXF3.h:128
psa_status_t ti_psa_mac_sign_finish(psa_mac_operation_t *psa_operation, uint8_t *mac, size_t mac_size, size_t *mac_length)
psa_status_t ti_psa_mac_verify_setup(psa_mac_operation_t *psa_operation, mbedtls_svc_key_id_t key, psa_algorithm_t alg)
AESCMAC (CMAC & CBC-MAC) driver implementation for the Low Power F3 family.
© Copyright 1995-2026, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale