pull/2000/merge
Arkadiusz Bokowy 2023-09-15 14:20:02 -06:00 committed by GitHub
commit 72220336ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View File

@ -915,6 +915,9 @@ AC_CHECK_FUNCS([gettimeofday],
AC_CHECK_FUNCS([strptime],
[AM_CONDITIONAL([HAVE_STRPTIME], true)],
[AM_CONDITIONAL([HAVE_STRPTIME], false)])
AC_CHECK_FUNCS([getentropy],
[AM_CONDITIONAL([HAVE_GETENTROPY], true)],
[AM_CONDITIONAL([HAVE_GETENTROPY], false)])
AC_CHECK_FUNCS([daemon], [have_daemon=yes])
AM_CONDITIONAL([HAVE_DAEMON], [test "x$have_daemon" = "xyes"])

View File

@ -106,6 +106,20 @@ void SimpleRandomizer::getRandomBytes(unsigned char* buf, size_t len)
auto iter = len / blocklen;
auto p = buf;
#if !HAVE_GETENTROPY
auto getentropy = [this](void *buffer, size_t length) {
auto buf = reinterpret_cast<unsigned int*>(buffer);
auto dis = std::uniform_int_distribution<unsigned int>();
for (size_t q = length / sizeof(unsigned int); q > 0; --q, ++buf) {
*buf = dis(gen_);
}
const size_t r = length % sizeof(unsigned int);
auto last = dis(gen_);
memcpy(buf, &last, r);
return 0;
};
#endif // !HAVE_GETENTROPY
for (size_t i = 0; i < iter; ++i) {
auto rv = getentropy(p, blocklen);
if (rv != 0) {
@ -128,7 +142,7 @@ void SimpleRandomizer::getRandomBytes(unsigned char* buf, size_t len)
assert(0);
abort();
}
#endif // ! __MINGW32__
#endif // !__MINGW32__ && !__APPLE__
}
} // namespace aria2