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