| 1 |
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. |
| 2 |
// SPDX-License-Identifier: Apache-2.0 OR ISC |
| 3 |
|
| 4 |
#include <openssl/rand.h> |
| 5 |
|
| 6 |
#include "internal.h" |
| 7 |
|
| 8 |
#if defined(OPENSSL_RAND_CCRANDOMGENERATEBYTES) |
| 9 |
|
| 10 |
#include <CommonCrypto/CommonRandom.h> |
| 11 |
|
| 12 |
#include <stdio.h> |
| 13 |
#include <stdlib.h> |
| 14 |
|
| 15 |
void CRYPTO_sysrand(uint8_t *out, size_t requested) { |
| 16 |
|
| 17 |
if (requested == 0) { |
| 18 |
return; |
| 19 |
} |
| 20 |
|
| 21 |
// To get system randomness on iOS we use |CCRandomGenerateBytes|. On MacOS we |
| 22 |
// use |getentropy| but iOS doesn't expose that. |
| 23 |
if (CCRandomGenerateBytes(out, requested) != kCCSuccess) { |
| 24 |
fprintf(stderr, "CCRandomGenerateBytes failed.\n"); |
| 25 |
abort(); |
| 26 |
} |
| 27 |
} |
| 28 |
|
| 29 |
#endif |