xref: /rk3399_ARM-atf/drivers/auth/mbedtls/mbedtls_common.c (revision 82cb2c1ad9897473743f08437d0a3995bed561b9)
17d37aa17SJuan Castillo /*
266b4c166Sdp-arm  * Copyright (c) 2015-2017, ARM Limited and Contributors. All rights reserved.
37d37aa17SJuan Castillo  *
4*82cb2c1aSdp-arm  * SPDX-License-Identifier: BSD-3-Clause
57d37aa17SJuan Castillo  */
67d37aa17SJuan Castillo 
77d37aa17SJuan Castillo #include <assert.h>
87d37aa17SJuan Castillo 
97d37aa17SJuan Castillo /* mbed TLS headers */
10649dbf6fSJuan Castillo #include <mbedtls/memory_buffer_alloc.h>
117d37aa17SJuan Castillo 
127d37aa17SJuan Castillo /*
137d37aa17SJuan Castillo  * mbed TLS heap
147d37aa17SJuan Castillo  */
1566b4c166Sdp-arm #if (TBBR_KEY_ALG_ID == TBBR_ECDSA)
167d37aa17SJuan Castillo #define MBEDTLS_HEAP_SIZE		(14*1024)
1766b4c166Sdp-arm #elif (TBBR_KEY_ALG_ID == TBBR_RSA)
187d37aa17SJuan Castillo #define MBEDTLS_HEAP_SIZE		(8*1024)
197d37aa17SJuan Castillo #endif
207d37aa17SJuan Castillo static unsigned char heap[MBEDTLS_HEAP_SIZE];
217d37aa17SJuan Castillo 
227d37aa17SJuan Castillo /*
237d37aa17SJuan Castillo  * mbed TLS initialization function
247d37aa17SJuan Castillo  */
257d37aa17SJuan Castillo void mbedtls_init(void)
267d37aa17SJuan Castillo {
277d37aa17SJuan Castillo 	static int ready;
287d37aa17SJuan Castillo 
297d37aa17SJuan Castillo 	if (!ready) {
307d37aa17SJuan Castillo 		/* Initialize the mbed TLS heap */
31649dbf6fSJuan Castillo 		mbedtls_memory_buffer_alloc_init(heap, MBEDTLS_HEAP_SIZE);
327d37aa17SJuan Castillo 		ready = 1;
337d37aa17SJuan Castillo 	}
347d37aa17SJuan Castillo }
35