Skip to content
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

native_simulator: ensure nsi_host_random() returns 64 bits of randomness #83428

Closed
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
9 changes: 8 additions & 1 deletion scripts/native_simulator/common/src/nsi_host_trampolines.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,14 @@ int nsi_host_open(const char *pathname, int flags)

long nsi_host_random(void)
{
return random();
long ret = 0;
size_t bits = 8 * sizeof(ret);

/* Each call to random() returns 31 bits of randomness. */
for (size_t shift = 0; shift < bits; shift += 31) {
ret |= random() << shift;
}
return ret;
}

long nsi_host_read(int fd, void *buffer, unsigned long size)
Expand Down
Loading