mirror of
https://github.com/Divested-Mobile/DivestOS-Build.git
synced 2024-10-01 01:35:54 -04:00
1df7c7f1d4
Signed-off-by: Tad <tad@spotco.us>
56 lines
2.1 KiB
Diff
56 lines
2.1 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Daniel Micay <danielmicay@gmail.com>
|
|
Date: Mon, 4 Mar 2019 04:26:04 -0500
|
|
Subject: [PATCH] use blocking getrandom and avoid urandom fallback
|
|
|
|
Signed-off-by: anupritaisno1 <www.anuprita804@gmail.com>
|
|
---
|
|
libc/bionic/getentropy.cpp | 26 ++------------------------
|
|
1 file changed, 2 insertions(+), 24 deletions(-)
|
|
|
|
diff --git a/libc/bionic/getentropy.cpp b/libc/bionic/getentropy.cpp
|
|
index 9c93e713b..9b4085267 100644
|
|
--- a/libc/bionic/getentropy.cpp
|
|
+++ b/libc/bionic/getentropy.cpp
|
|
@@ -33,22 +33,6 @@
|
|
|
|
#include "private/ScopedFd.h"
|
|
|
|
-static int getentropy_urandom(void* buffer, size_t buffer_size, int saved_errno) {
|
|
- ScopedFd fd(TEMP_FAILURE_RETRY(open("/dev/urandom", O_RDONLY | O_NOFOLLOW | O_CLOEXEC, 0)));
|
|
- if (fd.get() == -1) return -1;
|
|
-
|
|
- size_t collected = 0;
|
|
- while (collected < buffer_size) {
|
|
- ssize_t count = TEMP_FAILURE_RETRY(read(fd.get(), static_cast<char*>(buffer) + collected,
|
|
- buffer_size - collected));
|
|
- if (count == -1) return -1;
|
|
- collected += count;
|
|
- }
|
|
-
|
|
- errno = saved_errno;
|
|
- return 0;
|
|
-}
|
|
-
|
|
int getentropy(void* buffer, size_t buffer_size) {
|
|
if (buffer_size > 256) {
|
|
errno = EIO;
|
|
@@ -60,15 +44,9 @@ int getentropy(void* buffer, size_t buffer_size) {
|
|
size_t collected = 0;
|
|
while (collected < buffer_size) {
|
|
long count = TEMP_FAILURE_RETRY(getrandom(static_cast<char*>(buffer) + collected,
|
|
- buffer_size - collected, GRND_NONBLOCK));
|
|
+ buffer_size - collected, 0));
|
|
if (count == -1) {
|
|
- // EAGAIN: there isn't enough entropy right now.
|
|
- // ENOSYS/EINVAL: getrandom(2) or GRND_NONBLOCK isn't supported.
|
|
- // EFAULT: `buffer` is invalid.
|
|
- // Try /dev/urandom regardless because it can't hurt,
|
|
- // and we don't need to optimize the EFAULT case.
|
|
- // See http://b/33059407 and http://b/67015565.
|
|
- return getentropy_urandom(buffer, buffer_size, saved_errno);
|
|
+ return -1;
|
|
}
|
|
collected += count;
|
|
}
|