| 1 | #ifndef AWS_COMMON_DEVICE_RANDOM_H |
| 2 | #define AWS_COMMON_DEVICE_RANDOM_H |
| 3 | /** |
| 4 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 5 | * SPDX-License-Identifier: Apache-2.0. |
| 6 | */ |
| 7 | #include <aws/common/common.h> |
| 8 | |
| 9 | AWS_PUSH_SANE_WARNING_LEVEL |
| 10 | |
| 11 | struct aws_byte_buf; |
| 12 | |
| 13 | AWS_EXTERN_C_BEGIN |
| 14 | |
| 15 | /** |
| 16 | * Get an unpredictably random 64bit number, suitable for cryptographic use. |
| 17 | */ |
| 18 | AWS_COMMON_API int aws_device_random_u64(uint64_t *output); |
| 19 | |
| 20 | /** |
| 21 | * Get an unpredictably random 32bit number, suitable for cryptographic use. |
| 22 | */ |
| 23 | AWS_COMMON_API int aws_device_random_u32(uint32_t *output); |
| 24 | |
| 25 | /** |
| 26 | * Get an unpredictably random 16bit number, suitable for cryptographic use. |
| 27 | */ |
| 28 | AWS_COMMON_API int aws_device_random_u16(uint16_t *output); |
| 29 | |
| 30 | /** |
| 31 | * Get an unpredictably random 8bit number, suitable for cryptographic use. |
| 32 | */ |
| 33 | AWS_COMMON_API int aws_device_random_u8(uint8_t *output); |
| 34 | |
| 35 | /** |
| 36 | * Fill the rest of a buffer with unpredictably random bytes, suitable for cryptographic use. |
| 37 | */ |
| 38 | AWS_COMMON_API int aws_device_random_buffer(struct aws_byte_buf *output); |
| 39 | |
| 40 | /** |
| 41 | * Write N unpredictably random bytes to a buffer, suitable for cryptographic use. |
| 42 | * If there is insufficient space in the buffer, AWS_ERROR_SHORT_BUFFER is raised |
| 43 | * and the buffer will be unchanged. |
| 44 | */ |
| 45 | AWS_COMMON_API int aws_device_random_buffer_append(struct aws_byte_buf *output, size_t n); |
| 46 | |
| 47 | AWS_EXTERN_C_END |
| 48 | AWS_POP_SANE_WARNING_LEVEL |
| 49 | |
| 50 | #endif /* AWS_COMMON_DEVICE_RANDOM_H */ |