arm_pauth.c 811 B

12345678910111213141516171819202122232425262728
  1. /*
  2. * Copyright (c) 2019, Arm Limited. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <arch_helpers.h>
  7. #include <cdefs.h>
  8. #include <stdint.h>
  9. /*
  10. * This is only a toy implementation to generate a seemingly random
  11. * 128-bit key from sp, x30 and cntpct_el0 values.
  12. * A production system must re-implement this function to generate
  13. * keys from a reliable randomness source.
  14. */
  15. uint128_t plat_init_apkey(void)
  16. {
  17. uint64_t return_addr = (uint64_t)__builtin_return_address(0U);
  18. uint64_t frame_addr = (uint64_t)__builtin_frame_address(0U);
  19. uint64_t cntpct = read_cntpct_el0();
  20. /* Generate 128-bit key */
  21. uint64_t key_lo = (return_addr << 13) ^ frame_addr ^ cntpct;
  22. uint64_t key_hi = (frame_addr << 15) ^ return_addr ^ cntpct;
  23. return ((uint128_t)(key_hi) << 64) | key_lo;
  24. }