rpi3_stack_protector.c 599 B

1234567891011121314151617181920212223242526272829
  1. /*
  2. * Copyright (c) 2017-2019, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <stdint.h>
  7. #include <lib/utils.h>
  8. #include <lib/utils_def.h>
  9. #include <drivers/rpi3/rng/rpi3_rng.h>
  10. /* Get 128 bits of entropy and fuse the values together to form the canary. */
  11. #define TRNG_NBYTES 16U
  12. u_register_t plat_get_stack_protector_canary(void)
  13. {
  14. size_t i;
  15. u_register_t buf[TRNG_NBYTES / sizeof(u_register_t)];
  16. u_register_t ret = 0U;
  17. rpi3_rng_read(buf, sizeof(buf));
  18. for (i = 0U; i < ARRAY_SIZE(buf); i++)
  19. ret ^= buf[i];
  20. return ret;
  21. }