1
+ /*
2
+ * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
3
+ * Copyright (C) 2019-2020, STMicroelectronics, All Rights Reserved
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
+ * This file implements ST shared HASH services based on API from mbed TLS
19
+ */
20
+
21
+ /* Includes ------------------------------------------------------------------*/
22
+ #if !defined(MBEDTLS_CONFIG_FILE )
23
+ #include "config.h"
24
+ #else
25
+ #include MBEDTLS_CONFIG_FILE
26
+ #endif
27
+
28
+ #if defined(MBEDTLS_SHA1_ALT ) || defined(MBEDTLS_SHA256_ALT ) || defined(MBEDTLS_MD5_ALT )
29
+
30
+ #include "hash_stm32.h"
31
+
32
+ /* Variables -----------------------------------------------------------------*/
33
+ /* Mutex protection because of one Hash Hw instance is shared over several */
34
+ /* algorithms (SHA-1, SHA-256, MD5 implementations may be enabled together) */
35
+ #if defined(MBEDTLS_THREADING_C )
36
+ mbedtls_threading_mutex_t hash_mutex ;
37
+ unsigned char hash_mutex_started = 0 ;
38
+ #endif /* MBEDTLS_THREADING_C */
39
+
40
+ unsigned int hash_context_count = 0 ;
41
+
42
+ /* Functions -----------------------------------------------------------------*/
43
+
44
+ /* Implementation that should never be optimized out by the compiler */
45
+ void hash_zeroize (void * v , size_t n )
46
+ {
47
+ volatile unsigned char * p = (unsigned char * )v ;
48
+ while (n -- ) {
49
+ * p ++ = 0 ;
50
+ }
51
+ }
52
+
53
+ /* HAL function that should be implemented in the user file */
54
+ /**
55
+ * @brief HASH MSP Initialization
56
+ * This function configures the hardware resources used in this example
57
+ * @param hhash: HASH handle pointer
58
+ * @retval None
59
+ */
60
+ void HAL_HASH_MspInit (HASH_HandleTypeDef * hhash )
61
+ {
62
+ /* Peripheral clock enable */
63
+ __HAL_RCC_HASH_CLK_ENABLE ();
64
+ }
65
+
66
+ /**
67
+ * @brief HASH MSP De-Initialization
68
+ * This function freeze the hardware resources used in this example
69
+ * @param hhash: HASH handle pointer
70
+ * @retval None
71
+ */
72
+ void HAL_HASH_MspDeInit (HASH_HandleTypeDef * hhash )
73
+ {
74
+ /* Peripheral clock disable */
75
+ __HAL_RCC_HASH_CLK_DISABLE ();
76
+ }
77
+
78
+ #endif /* MBEDTLS_SHA1_ALT or MBEDTLS_SHA256_ALT or MBEDTLS_MD5_ALT */
0 commit comments