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

Address noise_rand_bytes silent failure on Windows: #4

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
13 changes: 9 additions & 4 deletions src/protocol/rand_os.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,12 @@
*
* \note Not part of the public API.
*/
void noise_rand_bytes(void *bytes, size_t size)
{
void noise_rand_bytes(void *bytes, size_t size) {
if (size == 0 || bytes == NULL) {
fprintf(stderr, "Invalid size or buffer provided for noise_rand_bytes. Abort!\n");
exit(1);
}

#if defined(RANDOM_DEVICE)
int fd = open(RANDOM_DEVICE, O_RDONLY);
if (fd >= 0) {
Expand Down Expand Up @@ -95,9 +99,10 @@ void noise_rand_bytes(void *bytes, size_t size)
memset(bytes, 0, size);
if (CryptAcquireContextW(&provider, 0, 0, PROV_RSA_FULL,
CRYPT_VERIFYCONTEXT | CRYPT_SILENT)) {
CryptGenRandom(provider, size, bytes);
BOOL success = CryptGenRandom(provider, size, bytes);
CryptReleaseContext(provider, 0);
return;
if (success)
return;
}
#endif
fprintf(stderr, "Do not know how to generate random numbers! Abort!\n");
Expand Down