Antonio Nino Diaz | 4b7059d | 2018-07-13 15:26:49 +0100 | [diff] [blame] | 1 | /* |
Madhukar Pappireddy | 50123b7 | 2019-07-05 12:04:49 -0500 | [diff] [blame] | 2 | * Copyright (c) 2017-2019, ARM Limited and Contributors. All rights reserved. |
Antonio Nino Diaz | 4b7059d | 2018-07-13 15:26:49 +0100 | [diff] [blame] | 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> |
Madhukar Pappireddy | 50123b7 | 2019-07-05 12:04:49 -0500 | [diff] [blame] | 10 | #include <lib/utils_def.h> |
Antonio Nino Diaz | 4b7059d | 2018-07-13 15:26:49 +0100 | [diff] [blame] | 11 | |
Andre Przywara | 4ea3bd3 | 2019-07-09 14:32:11 +0100 | [diff] [blame] | 12 | #include <drivers/rpi3/rng/rpi3_rng.h> |
Antonio Nino Diaz | 4b7059d | 2018-07-13 15:26:49 +0100 | [diff] [blame] | 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 | } |