summaryrefslogtreecommitdiff
path: root/src/SimpleRandomizer.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2018-11-25 22:51:57 +0900
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2018-11-25 22:51:57 +0900
commit03f40af361e7a1e57722fb4207929fdd1ad39263 (patch)
tree43a412c505489ad57805f5529739e1ebfe98eb79 /src/SimpleRandomizer.cc
parent6c30b13a91646d5b9ed26d12806850d33ec6f94b (diff)
Remove linux getrandom and use C++ stdlib instead
Diffstat (limited to 'src/SimpleRandomizer.cc')
-rw-r--r--src/SimpleRandomizer.cc25
1 files changed, 2 insertions, 23 deletions
diff --git a/src/SimpleRandomizer.cc b/src/SimpleRandomizer.cc
index 539855e5..8a055d66 100644
--- a/src/SimpleRandomizer.cc
+++ b/src/SimpleRandomizer.cc
@@ -45,12 +45,6 @@
#include "LogFactory.h"
#include "fmt.h"
-#ifdef HAVE_GETRANDOM_INTERFACE
-# include <errno.h>
-# include <linux/errno.h>
-# include "getrandom_linux.h"
-#endif
-
namespace aria2 {
std::unique_ptr<SimpleRandomizer> SimpleRandomizer::randomizer_;
@@ -96,22 +90,7 @@ void SimpleRandomizer::getRandomBytes(unsigned char* buf, size_t len)
#ifdef __MINGW32__
BOOL r = CryptGenRandom(provider_, len, reinterpret_cast<BYTE*>(buf));
assert(r);
-#else // ! __MINGW32__
-# if defined(HAVE_GETRANDOM_INTERFACE)
- static bool have_random_support = true;
- if (have_random_support) {
- auto rv = getrandom_linux(buf, len);
- if (rv != -1) {
- // getrandom is not supposed to fail, ever, so, we want to assert here.
- assert(rv >= 0 && (size_t)rv == len);
- return;
- }
- have_random_support = false;
- A2_LOG_INFO("Disabled getrandom support, because kernel does not "
- "implement this feature (ENOSYS)");
- }
-// Fall through to generic implementation
-# endif // defined(HAVE_GETRANDOM_INTERFACE)
+#else // ! __MINGW32__
auto ubuf = reinterpret_cast<result_type*>(buf);
size_t q = len / sizeof(result_type);
auto dis = std::uniform_int_distribution<result_type>();
@@ -121,7 +100,7 @@ void SimpleRandomizer::getRandomBytes(unsigned char* buf, size_t len)
const size_t r = len % sizeof(result_type);
auto last = dis(gen_);
memcpy(ubuf, &last, r);
-#endif // ! __MINGW32__
+#endif // ! __MINGW32__
}
} // namespace aria2