Skip to content

Commit

Permalink
macOS has no getrandom?!
Browse files Browse the repository at this point in the history
  • Loading branch information
tfpf committed Oct 1, 2023
1 parent 58d5aa8 commit c6260a0
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/hdrbg.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ hdrbg_err = HDRBG_ERR_NONE;
#if defined _WIN32
#include <windows.h>
#include <bcrypt.h>
#elif defined __linux__ || defined __APPLE__
#elif defined __linux__
#include <sys/random.h>
#endif

Expand Down Expand Up @@ -214,7 +214,7 @@ streamtobytes(FILE *fptr_, uint8_t *m_bytes, size_t m_length)
return 0;
}
return m_length;
#elif (defined __linux__ || defined __APPLE__) && CHAR_BIT == 8
#elif defined __linux__ && CHAR_BIT == 8
ssize_t len = getrandom(m_bytes, m_length, 0);
if(len < 0)
{
Expand All @@ -227,7 +227,7 @@ streamtobytes(FILE *fptr_, uint8_t *m_bytes, size_t m_length)
}
return len;
#else
FILE *fptr = fopen("/dev/urandom");
FILE *fptr = fopen("/dev/urandom", "rb");
if(fptr == NULL)
{
hdrbg_err = HDRBG_ERR_NO_ENTROPY;
Expand Down

0 comments on commit c6260a0

Please sign in to comment.