blob: aae5fac72c29fece35eb89298b34152acd7814b1 [file] [log] [blame]
Antonio Nino Diaz4b7059d2018-07-13 15:26:49 +01001/*
Madhukar Pappireddy50123b72019-07-05 12:04:49 -05002 * Copyright (c) 2017-2019, ARM Limited and Contributors. All rights reserved.
Antonio Nino Diaz4b7059d2018-07-13 15:26:49 +01003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Antonio Nino Diaz4b32e622018-08-16 16:52:57 +01007#include <stdint.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00008
9#include <lib/utils.h>
Madhukar Pappireddy50123b72019-07-05 12:04:49 -050010#include <lib/utils_def.h>
Antonio Nino Diaz4b7059d2018-07-13 15:26:49 +010011
Andre Przywara4ea3bd32019-07-09 14:32:11 +010012#include <drivers/rpi3/rng/rpi3_rng.h>
Antonio Nino Diaz4b7059d2018-07-13 15:26:49 +010013
14/* Get 128 bits of entropy and fuse the values together to form the canary. */
15#define TRNG_NBYTES 16U
16
17u_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}