Skip to content

Feature/isaac #3997

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/rt/rust_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,21 @@ inline void isaac_seed(rust_kernel* kernel, uint8_t* dest, size_t size)
(_T("CryptReleaseContext"), CryptReleaseContext(hProv, 0));
#else
int fd = open("/dev/urandom", O_RDONLY);
assert(fd > 0);
if (fd == -1)
kernel->fatal("error opening /dev/urandom: %s", strerror(errno));
size_t amount = 0;
do {
ssize_t ret = read(fd, dest+amount, size-amount);
assert(ret >= 0);
if (ret < 0)
kernel->fatal("error reading /dev/urandom: %s", strerror(errno));
else if (ret == 0)
kernel->fatal("somehow hit eof reading from /dev/urandom");
amount += (size_t)ret;
} while (amount < size);
int ret = close(fd);
assert(ret == 0);
if (ret != 0)
kernel->log(log_warn, "error closing /dev/urandom: %s",
strerror(errno));
#endif
}

Expand Down