Michalis Pappas | e4c00bb | 2018-03-20 14:30:00 +0800 | [diff] [blame] | 1 | /* |
Tomas Pilar | 18b284b | 2020-10-28 15:35:53 +0000 | [diff] [blame] | 2 | * Copyright (c) 2021, ARM Limited and Contributors. All rights reserved. |
Michalis Pappas | e4c00bb | 2018-03-20 14:30:00 +0800 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
Michalis Pappas | e4c00bb | 2018-03-20 14:30:00 +0800 | [diff] [blame] | 7 | #include <stdint.h> |
| 8 | |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 9 | #include <arch_helpers.h> |
Tomas Pilar | 18b284b | 2020-10-28 15:35:53 +0000 | [diff] [blame] | 10 | #include <arch_features.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 11 | #include <plat/common/platform.h> |
| 12 | |
Michalis Pappas | e4c00bb | 2018-03-20 14:30:00 +0800 | [diff] [blame] | 13 | #define RANDOM_CANARY_VALUE ((u_register_t) 3288484550995823360ULL) |
| 14 | |
| 15 | u_register_t plat_get_stack_protector_canary(void) |
| 16 | { |
Tomas Pilar | 18b284b | 2020-10-28 15:35:53 +0000 | [diff] [blame] | 17 | /* Use the RNDR instruction if the CPU supports it */ |
Andre Przywara | 436b4bb | 2023-02-22 17:55:59 +0000 | [diff] [blame] | 18 | if (is_feat_rng_supported()) { |
Tomas Pilar | 18b284b | 2020-10-28 15:35:53 +0000 | [diff] [blame] | 19 | return read_rndr(); |
| 20 | } |
Tomas Pilar | 18b284b | 2020-10-28 15:35:53 +0000 | [diff] [blame] | 21 | |
Michalis Pappas | e4c00bb | 2018-03-20 14:30:00 +0800 | [diff] [blame] | 22 | /* |
Tomas Pilar | 18b284b | 2020-10-28 15:35:53 +0000 | [diff] [blame] | 23 | * Ideally, a random number should be returned above. If a random |
| 24 | * number generator is not supported, return instead a |
Michalis Pappas | e4c00bb | 2018-03-20 14:30:00 +0800 | [diff] [blame] | 25 | * combination of a timer's value and a compile-time constant. |
Tomas Pilar | 18b284b | 2020-10-28 15:35:53 +0000 | [diff] [blame] | 26 | * This is better than nothing but not necessarily really secure. |
Michalis Pappas | e4c00bb | 2018-03-20 14:30:00 +0800 | [diff] [blame] | 27 | */ |
| 28 | return RANDOM_CANARY_VALUE ^ read_cntpct_el0(); |
| 29 | } |
| 30 | |