Skip to content
Snippets Groups Projects
Commit 6c4f4655 authored by Roman Khlopkov's avatar Roman Khlopkov 🔜
Browse files

Merge branch 'develop' of gitlab.demlabs.net:dap/dap-sdk into develop

parents ade50a7e 63da6a93
No related branches found
No related tags found
No related merge requests found
Pipeline #51009 passed with stage
in 12 minutes and 20 seconds
...@@ -2,17 +2,31 @@ ...@@ -2,17 +2,31 @@
This code was taken from the SPHINCS reference implementation and is public domain. This code was taken from the SPHINCS reference implementation and is public domain.
*/ */
#include <fcntl.h> #if defined(_WIN32)
#include <unistd.h> #include <windows.h>
#else
#include <fcntl.h>
#include <unistd.h>
#include <pthread.h>
static _Thread_local int fd = -1;
#endif
#include "randombytes.h" #include "randombytes.h"
static int fd = -1;
void randombytes(unsigned char *x, unsigned long long xlen) void randombytes(unsigned char *x, unsigned long long xlen)
{ {
#if defined(_WIN32)
HCRYPTPROV p;
if (CryptAcquireContext(&p, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT) == FALSE) {
return;
}
if (CryptGenRandom(p, xlen, (BYTE*)x) == FALSE) {
return;
}
CryptReleaseContext(p, 0);
#else
unsigned long long i; unsigned long long i;
if (fd == -1) { if (fd == -1) {
for (;;) { for (;;) {
fd = open("/dev/urandom", O_RDONLY); fd = open("/dev/urandom", O_RDONLY);
...@@ -22,7 +36,6 @@ void randombytes(unsigned char *x, unsigned long long xlen) ...@@ -22,7 +36,6 @@ void randombytes(unsigned char *x, unsigned long long xlen)
sleep(1); sleep(1);
} }
} }
while (xlen > 0) { while (xlen > 0) {
if (xlen < 1048576) { if (xlen < 1048576) {
i = xlen; i = xlen;
...@@ -40,4 +53,5 @@ void randombytes(unsigned char *x, unsigned long long xlen) ...@@ -40,4 +53,5 @@ void randombytes(unsigned char *x, unsigned long long xlen)
x += i; x += i;
xlen -= i; xlen -= i;
} }
#endif
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment