Antonio Nino Diaz | 4b7059d | 2018-07-13 15:26:49 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
Antonio Nino Diaz | 4b32e62 | 2018-08-16 16:52:57 +0100 | [diff] [blame] | 7 | #include <stdint.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 8 | |
| 9 | #include <lib/utils.h> |
Antonio Nino Diaz | 4b7059d | 2018-07-13 15:26:49 +0100 | [diff] [blame] | 10 | |
| 11 | #include "rpi3_private.h" |
| 12 | |
| 13 | /* Get 128 bits of entropy and fuse the values together to form the canary. */ |
| 14 | #define TRNG_NBYTES 16U |
| 15 | |
| 16 | u_register_t plat_get_stack_protector_canary(void) |
| 17 | { |
| 18 | size_t i; |
| 19 | u_register_t buf[TRNG_NBYTES / sizeof(u_register_t)]; |
| 20 | u_register_t ret = 0U; |
| 21 | |
| 22 | rpi3_rng_read(buf, sizeof(buf)); |
| 23 | |
| 24 | for (i = 0U; i < ARRAY_SIZE(buf); i++) |
| 25 | ret ^= buf[i]; |
| 26 | |
| 27 | return ret; |
| 28 | } |