xref: /rk3399_ARM-atf/plat/arm/board/juno/juno_stack_protector.c (revision fd7b287cbe9147ca9e07dd9f30c49c58bbdd92a8)
1 /*
2  * Copyright (c) 2017, ARM Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #include <arch_helpers.h>
8 #include <common/debug.h>
9 #include <lib/utils.h>
10 #include <platform_def.h>
11 
12 #include "juno_decl.h"
13 
14 u_register_t plat_get_stack_protector_canary(void)
15 {
16 	u_register_t c[TRNG_NBYTES / sizeof(u_register_t)];
17 	u_register_t ret = 0;
18 	size_t i;
19 
20 	if (juno_getentropy(c, sizeof(c)) != 0) {
21 		ERROR("Not enough entropy to initialize canary value\n");
22 		panic();
23 	}
24 
25 	/*
26 	 * On Juno we get 128-bits of entropy in one round.
27 	 * Fuse the values together to form the canary.
28 	 */
29 	for (i = 0; i < ARRAY_SIZE(c); i++)
30 		ret ^= c[i];
31 	return ret;
32 }
33