device_random.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /**
  2. * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
  3. * SPDX-License-Identifier: Apache-2.0.
  4. */
  5. #include <aws/common/device_random.h>
  6. #include <aws/common/byte_buf.h>
  7. #ifdef _MSC_VER
  8. /* disables warning non const declared initializers for Microsoft compilers */
  9. # pragma warning(disable : 4204)
  10. # pragma warning(disable : 4706)
  11. #endif
  12. int aws_device_random_u64(uint64_t *output) {
  13. struct aws_byte_buf buf = aws_byte_buf_from_empty_array((uint8_t *)output, sizeof(uint64_t));
  14. return aws_device_random_buffer(&buf);
  15. }
  16. int aws_device_random_u32(uint32_t *output) {
  17. struct aws_byte_buf buf = aws_byte_buf_from_empty_array((uint8_t *)output, sizeof(uint32_t));
  18. return aws_device_random_buffer(&buf);
  19. }
  20. int aws_device_random_u16(uint16_t *output) {
  21. struct aws_byte_buf buf = aws_byte_buf_from_empty_array((uint8_t *)output, sizeof(uint16_t));
  22. return aws_device_random_buffer(&buf);
  23. }
  24. int aws_device_random_u8(uint8_t *output) {
  25. struct aws_byte_buf buf = aws_byte_buf_from_empty_array((uint8_t *)output, sizeof(uint8_t));
  26. return aws_device_random_buffer(&buf);
  27. }