aboutsummaryrefslogtreecommitdiff
path: root/plat/rpi3/rpi3_stack_protector.c
blob: 815f73135dd94e895ebbbc4043e517ec9d968758 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/*
 * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include <stdint.h>

#include <lib/utils.h>

#include "rpi3_private.h"

/* Get 128 bits of entropy and fuse the values together to form the canary. */
#define TRNG_NBYTES	16U

u_register_t plat_get_stack_protector_canary(void)
{
	size_t i;
	u_register_t buf[TRNG_NBYTES / sizeof(u_register_t)];
	u_register_t ret = 0U;

	rpi3_rng_read(buf, sizeof(buf));

	for (i = 0U; i < ARRAY_SIZE(buf); i++)
		ret ^= buf[i];

	return ret;
}