xref: /rk3399_ARM-atf/plat/rpi/common/rpi3_stack_protector.c (revision 4f2b984852556afc3543d90150c46be4aaadbc75)
1*4f2b9848SAndre Przywara /*
2*4f2b9848SAndre Przywara  * Copyright (c) 2017-2019, ARM Limited and Contributors. All rights reserved.
3*4f2b9848SAndre Przywara  *
4*4f2b9848SAndre Przywara  * SPDX-License-Identifier: BSD-3-Clause
5*4f2b9848SAndre Przywara  */
6*4f2b9848SAndre Przywara 
7*4f2b9848SAndre Przywara #include <stdint.h>
8*4f2b9848SAndre Przywara 
9*4f2b9848SAndre Przywara #include <lib/utils.h>
10*4f2b9848SAndre Przywara #include <lib/utils_def.h>
11*4f2b9848SAndre Przywara 
12*4f2b9848SAndre Przywara #include <drivers/rpi3/rng/rpi3_rng.h>
13*4f2b9848SAndre Przywara 
14*4f2b9848SAndre Przywara /* Get 128 bits of entropy and fuse the values together to form the canary. */
15*4f2b9848SAndre Przywara #define TRNG_NBYTES	16U
16*4f2b9848SAndre Przywara 
17*4f2b9848SAndre Przywara u_register_t plat_get_stack_protector_canary(void)
18*4f2b9848SAndre Przywara {
19*4f2b9848SAndre Przywara 	size_t i;
20*4f2b9848SAndre Przywara 	u_register_t buf[TRNG_NBYTES / sizeof(u_register_t)];
21*4f2b9848SAndre Przywara 	u_register_t ret = 0U;
22*4f2b9848SAndre Przywara 
23*4f2b9848SAndre Przywara 	rpi3_rng_read(buf, sizeof(buf));
24*4f2b9848SAndre Przywara 
25*4f2b9848SAndre Przywara 	for (i = 0U; i < ARRAY_SIZE(buf); i++)
26*4f2b9848SAndre Przywara 		ret ^= buf[i];
27*4f2b9848SAndre Przywara 
28*4f2b9848SAndre Przywara 	return ret;
29*4f2b9848SAndre Przywara }
30