dp-arm | b3263b3 | 2017-02-28 14:43:15 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017, ARM Limited and Contributors. All rights reserved. |
| 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
dp-arm | b3263b3 | 2017-02-28 14:43:15 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <arch_helpers.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 8 | #include <common/debug.h> |
| 9 | #include <lib/utils.h> |
Antonio Nino Diaz | a320ecd | 2019-01-15 14:19:50 +0000 | [diff] [blame] | 10 | #include <platform_def.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 11 | |
dp-arm | b3263b3 | 2017-02-28 14:43:15 +0000 | [diff] [blame] | 12 | #include "juno_decl.h" |
dp-arm | b3263b3 | 2017-02-28 14:43:15 +0000 | [diff] [blame] | 13 | |
| 14 | u_register_t plat_get_stack_protector_canary(void) |
| 15 | { |
| 16 | u_register_t c[TRNG_NBYTES / sizeof(u_register_t)]; |
| 17 | u_register_t ret = 0; |
| 18 | size_t i; |
| 19 | |
| 20 | if (juno_getentropy(c, sizeof(c)) != 0) { |
| 21 | ERROR("Not enough entropy to initialize canary value\n"); |
| 22 | panic(); |
| 23 | } |
| 24 | |
| 25 | /* |
| 26 | * On Juno we get 128-bits of entropy in one round. |
| 27 | * Fuse the values together to form the canary. |
| 28 | */ |
| 29 | for (i = 0; i < ARRAY_SIZE(c); i++) |
| 30 | ret ^= c[i]; |
| 31 | return ret; |
| 32 | } |