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 | #if ENABLE_FEAT_RNG |
| 18 | /* Use the RNDR instruction if the CPU supports it */ |
| 19 | if (is_armv8_5_rng_present()) { |
| 20 | return read_rndr(); |
| 21 | } |
| 22 | #endif |
| 23 | |
Michalis Pappas | e4c00bb | 2018-03-20 14:30:00 +0800 | [diff] [blame] | 24 | /* |
Tomas Pilar | 18b284b | 2020-10-28 15:35:53 +0000 | [diff] [blame] | 25 | * Ideally, a random number should be returned above. If a random |
| 26 | * number generator is not supported, return instead a |
Michalis Pappas | e4c00bb | 2018-03-20 14:30:00 +0800 | [diff] [blame] | 27 | * combination of a timer's value and a compile-time constant. |
Tomas Pilar | 18b284b | 2020-10-28 15:35:53 +0000 | [diff] [blame] | 28 | * This is better than nothing but not necessarily really secure. |
Michalis Pappas | e4c00bb | 2018-03-20 14:30:00 +0800 | [diff] [blame] | 29 | */ |
| 30 | return RANDOM_CANARY_VALUE ^ read_cntpct_el0(); |
| 31 | } |
| 32 | |