| 
									
										
										
										
											2021-10-29 10:09:53 +05:30
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2022-03-03 09:34:39 +05:30
										 |  |  |  * SPDX-FileCopyrightText: 2018-2022 Espressif Systems (Shanghai) CO LTD | 
					
						
							| 
									
										
										
										
											2021-10-29 10:09:53 +05:30
										 |  |  |  * | 
					
						
							|  |  |  |  * SPDX-License-Identifier: Apache-2.0 | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-09-19 15:29:20 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  | #include <esp_attr.h>
 | 
					
						
							|  |  |  | #include <esp_heap_caps.h>
 | 
					
						
							|  |  |  | #include <sdkconfig.h>
 | 
					
						
							| 
									
										
										
										
											2018-11-11 15:44:54 +08:00
										 |  |  | #include "esp_mem.h"
 | 
					
						
							| 
									
										
										
										
											2018-09-19 15:29:20 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  | #ifndef CONFIG_MBEDTLS_CUSTOM_MEM_ALLOC
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-10 14:05:22 +05:30
										 |  |  | void *esp_mbedtls_mem_calloc(size_t n, size_t size) | 
					
						
							| 
									
										
										
										
											2018-09-19 15:29:20 +05:30
										 |  |  | { | 
					
						
							|  |  |  | #ifdef CONFIG_MBEDTLS_INTERNAL_MEM_ALLOC
 | 
					
						
							|  |  |  |     return heap_caps_calloc(n, size, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); | 
					
						
							|  |  |  | #elif CONFIG_MBEDTLS_EXTERNAL_MEM_ALLOC
 | 
					
						
							|  |  |  |     return heap_caps_calloc(n, size, MALLOC_CAP_SPIRAM|MALLOC_CAP_8BIT); | 
					
						
							| 
									
										
										
										
											2020-02-26 20:21:59 +08:00
										 |  |  | #elif CONFIG_MBEDTLS_IRAM_8BIT_MEM_ALLOC
 | 
					
						
							|  |  |  | #ifdef CONFIG_MBEDTLS_ASYMMETRIC_CONTENT_LEN
 | 
					
						
							|  |  |  |     if ((n*size) >= CONFIG_MBEDTLS_SSL_IN_CONTENT_LEN || (n*size) >= CONFIG_MBEDTLS_SSL_OUT_CONTENT_LEN) { | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  |     if ((n*size) >= CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN) { | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  |         return heap_caps_calloc_prefer(n, size, 2, MALLOC_CAP_INTERNAL|MALLOC_CAP_IRAM_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         return heap_caps_calloc(n, size, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 15:29:20 +05:30
										 |  |  | #else
 | 
					
						
							|  |  |  |     return calloc(n, size); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-10 14:05:22 +05:30
										 |  |  | void esp_mbedtls_mem_free(void *ptr) | 
					
						
							| 
									
										
										
										
											2018-09-19 15:29:20 +05:30
										 |  |  | { | 
					
						
							|  |  |  |     return heap_caps_free(ptr); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif /* !CONFIG_MBEDTLS_CUSTOM_MEM_ALLOC */
 |