xref: /rk3399_ARM-atf/drivers/auth/mbedtls/mbedtls_common.c (revision 66b4c1660ab9094ffb5412ae0ca98eb4a8111662)
17d37aa17SJuan Castillo /*
2*66b4c166Sdp-arm  * Copyright (c) 2015-2017, ARM Limited and Contributors. All rights reserved.
37d37aa17SJuan Castillo  *
47d37aa17SJuan Castillo  * Redistribution and use in source and binary forms, with or without
57d37aa17SJuan Castillo  * modification, are permitted provided that the following conditions are met:
67d37aa17SJuan Castillo  *
77d37aa17SJuan Castillo  * Redistributions of source code must retain the above copyright notice, this
87d37aa17SJuan Castillo  * list of conditions and the following disclaimer.
97d37aa17SJuan Castillo  *
107d37aa17SJuan Castillo  * Redistributions in binary form must reproduce the above copyright notice,
117d37aa17SJuan Castillo  * this list of conditions and the following disclaimer in the documentation
127d37aa17SJuan Castillo  * and/or other materials provided with the distribution.
137d37aa17SJuan Castillo  *
147d37aa17SJuan Castillo  * Neither the name of ARM nor the names of its contributors may be used
157d37aa17SJuan Castillo  * to endorse or promote products derived from this software without specific
167d37aa17SJuan Castillo  * prior written permission.
177d37aa17SJuan Castillo  *
187d37aa17SJuan Castillo  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
197d37aa17SJuan Castillo  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
207d37aa17SJuan Castillo  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
217d37aa17SJuan Castillo  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
227d37aa17SJuan Castillo  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
237d37aa17SJuan Castillo  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
247d37aa17SJuan Castillo  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
257d37aa17SJuan Castillo  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
267d37aa17SJuan Castillo  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
277d37aa17SJuan Castillo  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
287d37aa17SJuan Castillo  * POSSIBILITY OF SUCH DAMAGE.
297d37aa17SJuan Castillo  */
307d37aa17SJuan Castillo 
317d37aa17SJuan Castillo #include <assert.h>
327d37aa17SJuan Castillo 
337d37aa17SJuan Castillo /* mbed TLS headers */
34649dbf6fSJuan Castillo #include <mbedtls/memory_buffer_alloc.h>
357d37aa17SJuan Castillo 
367d37aa17SJuan Castillo /*
377d37aa17SJuan Castillo  * mbed TLS heap
387d37aa17SJuan Castillo  */
39*66b4c166Sdp-arm #if (TBBR_KEY_ALG_ID == TBBR_ECDSA)
407d37aa17SJuan Castillo #define MBEDTLS_HEAP_SIZE		(14*1024)
41*66b4c166Sdp-arm #elif (TBBR_KEY_ALG_ID == TBBR_RSA)
427d37aa17SJuan Castillo #define MBEDTLS_HEAP_SIZE		(8*1024)
437d37aa17SJuan Castillo #endif
447d37aa17SJuan Castillo static unsigned char heap[MBEDTLS_HEAP_SIZE];
457d37aa17SJuan Castillo 
467d37aa17SJuan Castillo /*
477d37aa17SJuan Castillo  * mbed TLS initialization function
487d37aa17SJuan Castillo  */
497d37aa17SJuan Castillo void mbedtls_init(void)
507d37aa17SJuan Castillo {
517d37aa17SJuan Castillo 	static int ready;
527d37aa17SJuan Castillo 
537d37aa17SJuan Castillo 	if (!ready) {
547d37aa17SJuan Castillo 		/* Initialize the mbed TLS heap */
55649dbf6fSJuan Castillo 		mbedtls_memory_buffer_alloc_init(heap, MBEDTLS_HEAP_SIZE);
567d37aa17SJuan Castillo 		ready = 1;
577d37aa17SJuan Castillo 	}
587d37aa17SJuan Castillo }
59