[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] error: qcrypto_random_bytes() tried to read from /dev/[u]ra
From: |
GM . Ijewski |
Subject: |
[Qemu-devel] error: qcrypto_random_bytes() tried to read from /dev/[u]random, even on windows |
Date: |
Mon, 24 Apr 2017 14:17:56 +0200 |
Now it calls CryptGenRandom() if is it compiled for windows.
It might be possible to save the cryptographic provider in between
invocations, e.g. by making it static -- I have no idea how
computationally
intensive that operation actually is.
Signed-off-by: Geert Martin Ijewski <address@hidden>
diff --git a/crypto/random-platform.c b/crypto/random-platform.c
index 82b755a..7aa0476 100644
--- a/crypto/random-platform.c
+++ b/crypto/random-platform.c
@@ -26,6 +26,7 @@ int qcrypto_random_bytes(uint8_t *buf G_GNUC_UNUSED,
size_t buflen G_GNUC_UNUSED,
Error **errp)
{
+#ifndef _WIN32
int fd;
int ret = -1;
int got;
@@ -61,4 +62,26 @@ int qcrypto_random_bytes(uint8_t *buf G_GNUC_UNUSED,
cleanup:
close(fd);
return ret;
+#else
+ HCRYPTPROV hCryptProv;
+
+ if (!CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL,
0)) {
+ if (NTE_BAD_KEYSET == GetLastError()) {
+ if (!CryptAcquireContext(&hCryptProv, NULL, NULL,
+ PROV_RSA_FULL, CRYPT_NEWKEYSET))
{
+ error_setg_errno(errp, GetLastError(),
+ "Unable to create cryptographic provider");
+ }
+ }
+ }
+
+ if (!CryptGenRandom(hCryptProv, buflen, buf)) {
+ error_setg_errno(errp, GetLastError(),
+ "Unable to read random bytes");
+ return -1;
+ }
+
+ CryptReleaseContext(hCryptProv, 0);
+ return 0;
+#endif
}
diff --git a/include/sysemu/os-win32.h b/include/sysemu/os-win32.h
index ff18b23..4a5d908 100644
--- a/include/sysemu/os-win32.h
+++ b/include/sysemu/os-win32.h
@@ -29,6 +29,7 @@
#include <winsock2.h>
#include <windows.h>
#include <ws2tcpip.h>
+#include <Wincrypt.h>
#if defined(_WIN64)
/* On w64, setjmp is implemented by _setjmp which needs a second
parameter.
- [Qemu-devel] error: qcrypto_random_bytes() tried to read from /dev/[u]random, even on windows,
GM . Ijewski <=
- Re: [Qemu-devel] error: qcrypto_random_bytes() tried to read from /dev/[u]random, even on windows, Daniel P. Berrange, 2017/04/24
- Re: [Qemu-devel] error: qcrypto_random_bytes() tried to read from /dev/[u]random, even on windows, Peter Maydell, 2017/04/24
- Re: [Qemu-devel] error: qcrypto_random_bytes() tried to read from /dev/[u]random, even on windows, Daniel P. Berrange, 2017/04/24
- Re: [Qemu-devel] error: qcrypto_random_bytes() tried to read from /dev/[u]random, even on windows, Peter Maydell, 2017/04/24
- Re: [Qemu-devel] error: qcrypto_random_bytes() tried to read from /dev/[u]random, even on windows, Daniel P. Berrange, 2017/04/24
- Re: [Qemu-devel] error: qcrypto_random_bytes() tried to read from /dev/[u]random, even on windows, Peter Maydell, 2017/04/24
- Re: [Qemu-devel] error: qcrypto_random_bytes() tried to read from /dev/[u]random, even on windows, Daniel P. Berrange, 2017/04/24
- Re: [Qemu-devel] error: qcrypto_random_bytes() tried to read from /dev/[u]random, even on windows, Peter Maydell, 2017/04/24
- Re: [Qemu-devel] error: qcrypto_random_bytes() tried to read from /dev/[u]random, even on windows, Daniel P. Berrange, 2017/04/24
- Re: [Qemu-devel] error: qcrypto_random_bytes() tried to read from /dev/[u]random, even on windows, Geert Martin Ijewski, 2017/04/24