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> |
Andre Przywara | 31ed470 | 2020-10-08 00:45:22 +0100 | [diff] [blame] | 10 | #include <plat/common/plat_trng.h> |
Antonio Nino Diaz | a320ecd | 2019-01-15 14:19:50 +0000 | [diff] [blame] | 11 | #include <platform_def.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 12 | |
dp-arm | b3263b3 | 2017-02-28 14:43:15 +0000 | [diff] [blame] | 13 | u_register_t plat_get_stack_protector_canary(void) |
| 14 | { |
Andre Przywara | 927b399 | 2020-10-08 00:43:50 +0100 | [diff] [blame] | 15 | uint64_t entropy; |
dp-arm | b3263b3 | 2017-02-28 14:43:15 +0000 | [diff] [blame] | 16 | |
Andre Przywara | 31ed470 | 2020-10-08 00:45:22 +0100 | [diff] [blame] | 17 | if (!plat_get_entropy(&entropy)) { |
dp-arm | b3263b3 | 2017-02-28 14:43:15 +0000 | [diff] [blame] | 18 | ERROR("Not enough entropy to initialize canary value\n"); |
| 19 | panic(); |
| 20 | } |
| 21 | |
Andre Przywara | 927b399 | 2020-10-08 00:43:50 +0100 | [diff] [blame] | 22 | if (sizeof(entropy) == sizeof(u_register_t)) { |
| 23 | return entropy; |
| 24 | } |
| 25 | |
| 26 | return (entropy & 0xffffffffULL) ^ (entropy >> 32); |
dp-arm | b3263b3 | 2017-02-28 14:43:15 +0000 | [diff] [blame] | 27 | } |