blob: c8471190a99ef816a249020d366cb07faa9ac9d6 [file] [log] [blame]
Antonio Nino Diazff6844c2019-01-31 11:01:10 +00001/*
2 * Copyright (c) 2019, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <cdefs.h>
8#include <stdint.h>
9
10/*
11 * Instruction pointer authentication key A. The low 64-bit are at [0], and the
12 * high bits at [1]. They are run-time constants so they are placed in the
13 * rodata section. They are written before MMU is turned on and the permissions
14 * are effective.
15 */
16uint64_t plat_apiakey[2] __section("rodata.apiakey");
17
18/*
19 * This is only a toy implementation to generate a seemingly random 128-bit key
20 * from sp and x30 values. A production system must re-implement this function
21 * to generate keys from a reliable randomness source.
22 */
23uint64_t *plat_init_apiakey(void)
24{
25 uintptr_t return_addr = (uintptr_t)__builtin_return_address(0U);
26 uintptr_t frame_addr = (uintptr_t)__builtin_frame_address(0U);
27
28 plat_apiakey[0] = (return_addr << 13) ^ frame_addr;
29 plat_apiakey[1] = (frame_addr << 15) ^ return_addr;
30
31 return plat_apiakey;
32}