ti_psa_crypto_hash.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_HASH_H
23 #define TI_PSA_CRYPTO_HASH_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
33 
34 #include <ti/devices/DeviceFamily.h>
35 #include <ti/drivers/SHA2.h>
36 #if ((DeviceFamily_PARENT == DeviceFamily_PARENT_CC27XX) || (DeviceFamily_PARENT == DeviceFamily_PARENT_CC35XX))
38 #elif
39  #include <ti/drivers/sha2/SHA2CC26X2.h>
40 #endif
41 
46 #define PSA_HASH_SUSPEND_INPUT_LENGTH_FIELD_LENGTH(alg) \
47  (((alg == PSA_ALG_SHA_224) || (alg == PSA_ALG_SHA_256)) ? 8u \
48  : ((alg == PSA_ALG_SHA_384) || (alg == PSA_ALG_SHA_512)) ? 16u \
49  : 0u)
50 
55 #define PSA_HASH_SUSPEND_HASH_STATE_FIELD_LENGTH(alg) \
56  (((alg == PSA_ALG_SHA_224) || (alg == PSA_ALG_SHA_256)) ? 32u \
57  : ((alg == PSA_ALG_SHA_384) || (alg == PSA_ALG_SHA_512)) ? 64u \
58  : 0u)
59 
61 {
62  /* Driver config struct - pointer to this is referred to as the driver handle */
64  /* Driver object */
65 #if ((DeviceFamily_PARENT == DeviceFamily_PARENT_CC27XX) || (DeviceFamily_PARENT == DeviceFamily_PARENT_CC35XX))
66  SHA2XXF3HSM_Object sha2Object;
67 #elif (DeviceFamily_PARENT == DeviceFamily_PARENT_CC13X4_CC26X3_CC26X4)
68  SHA2CC26X2_Object sha2Object;
69 #endif
70  /* Used to mark the operation struct as ready.*/
71  unsigned int id;
72  /* alg identifier */
73  psa_algorithm_t alg;
74 };
75 
77 
78 #define TI_PSA_HASH_OPERATION_INIT \
79  (ti_psa_hash_operation_t) \
80  { \
81  0 \
82  }
84 {
86  return (v);
87 }
88 
89 /******************************************************************************/
90 /* Multi-step hash operations */
91 /******************************************************************************/
92 psa_status_t ti_psa_hash_abort(psa_hash_operation_t *psa_operation);
93 
94 psa_status_t ti_psa_hash_resume(psa_hash_operation_t *psa_operation,
95  const uint8_t *hash_state,
96  size_t hash_state_length);
97 
98 psa_status_t ti_psa_hash_setup(psa_hash_operation_t *psa_operation, psa_algorithm_t alg);
99 
100 psa_status_t ti_psa_hash_suspend(psa_hash_operation_t *psa_operation,
101  uint8_t *hash_state,
102  size_t hash_state_size,
103  size_t *hash_state_length);
104 
105 psa_status_t ti_psa_hash_update(psa_hash_operation_t *psa_operation, const uint8_t *input, size_t input_length);
106 
107 psa_status_t ti_psa_hash_finish(psa_hash_operation_t *psa_operation,
108  uint8_t *hash,
109  size_t hash_size,
110  size_t *hash_length);
111 
112 /******************************************************************************/
113 /* One-step hash operations */
114 /******************************************************************************/
115 psa_status_t ti_psa_hash_clone(const psa_hash_operation_t *source_operation, psa_hash_operation_t *target_operation);
116 
117 psa_status_t ti_psa_hash_compare(psa_algorithm_t alg,
118  const uint8_t *input,
119  size_t input_length,
120  const uint8_t *hash,
121  size_t hash_length);
122 
123 psa_status_t ti_psa_hash_compute(psa_algorithm_t alg,
124  const uint8_t *input,
125  size_t input_length,
126  uint8_t *hash,
127  size_t hash_size,
128  size_t *hash_length);
129 
130 psa_status_t ti_psa_hash_verify(psa_hash_operation_t *psa_operation, const uint8_t *hash, size_t hash_length);
131 
132 #endif /* TI_PSA_CRYPTO_HASH_H */
psa_status_t ti_psa_hash_compute(psa_algorithm_t alg, const uint8_t *input, size_t input_length, uint8_t *hash, size_t hash_size, size_t *hash_length)
unsigned int id
Definition: ti_psa_crypto_hash.h:71
psa_status_t ti_psa_hash_resume(psa_hash_operation_t *psa_operation, const uint8_t *hash_state, size_t hash_state_length)
psa_status_t ti_psa_hash_abort(psa_hash_operation_t *psa_operation)
psa_status_t ti_psa_hash_update(psa_hash_operation_t *psa_operation, const uint8_t *input, size_t input_length)
#define TI_PSA_HASH_OPERATION_INIT
Definition: ti_psa_crypto_hash.h:78
SHA2 Global configuration.
Definition: SHA2.h:553
psa_status_t ti_psa_hash_finish(psa_hash_operation_t *psa_operation, uint8_t *hash, size_t hash_size, size_t *hash_length)
psa_status_t ti_psa_hash_clone(const psa_hash_operation_t *source_operation, psa_hash_operation_t *target_operation)
SHA2XXF3HSM_Object sha2Object
Definition: ti_psa_crypto_hash.h:66
SHA2_Config sha2Config
Definition: ti_psa_crypto_hash.h:63
psa_status_t ti_psa_hash_compare(psa_algorithm_t alg, const uint8_t *input, size_t input_length, const uint8_t *hash, size_t hash_length)
Definition: ti_psa_crypto_hash.h:60
SHA2 driver header.
psa_status_t ti_psa_hash_suspend(psa_hash_operation_t *psa_operation, uint8_t *hash_state, size_t hash_state_size, size_t *hash_state_length)
static struct ti_psa_hash_operation_s ti_psa_hash_operation_init(void)
Definition: ti_psa_crypto_hash.h:83
psa_algorithm_t alg
Definition: ti_psa_crypto_hash.h:73
psa_status_t ti_psa_hash_setup(psa_hash_operation_t *psa_operation, psa_algorithm_t alg)
psa_status_t ti_psa_hash_verify(psa_hash_operation_t *psa_operation, const uint8_t *hash, size_t hash_length)
© Copyright 1995-2026, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale