blob: 3924af8fbeaacc9a3feb23a3bba917602d25ab62 [file] [log] [blame]
dp-armb3263b32017-02-28 14:43:15 +00001/*
2 * Copyright (c) 2017, ARM Limited and Contributors. All rights reserved.
3 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
dp-armb3263b32017-02-28 14:43:15 +00005 */
6
7#include <arch_helpers.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00008#include <common/debug.h>
9#include <lib/utils.h>
Andre Przywara31ed4702020-10-08 00:45:22 +010010#include <plat/common/plat_trng.h>
Antonio Nino Diaza320ecd2019-01-15 14:19:50 +000011#include <platform_def.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000012
dp-armb3263b32017-02-28 14:43:15 +000013u_register_t plat_get_stack_protector_canary(void)
14{
Andre Przywara927b3992020-10-08 00:43:50 +010015 uint64_t entropy;
dp-armb3263b32017-02-28 14:43:15 +000016
Andre Przywara31ed4702020-10-08 00:45:22 +010017 if (!plat_get_entropy(&entropy)) {
dp-armb3263b32017-02-28 14:43:15 +000018 ERROR("Not enough entropy to initialize canary value\n");
19 panic();
20 }
21
Andre Przywara927b3992020-10-08 00:43:50 +010022 if (sizeof(entropy) == sizeof(u_register_t)) {
23 return entropy;
24 }
25
26 return (entropy & 0xffffffffULL) ^ (entropy >> 32);
dp-armb3263b32017-02-28 14:43:15 +000027}