Skip to content

Commit b767d25

Browse files
marmarekberrange
authored andcommitted
crypto: add "none" random provider
In case of not using random-number needing feature, it makes sense to skip RNG init too. This is especially helpful when QEMU is sandboxed in Stubdomain under Xen, where there is very little entropy so initial getrandom() call delays the startup several seconds. In that setup, no random bytes are needed at all. Signed-off-by: Marek Marczykowski-Górecki <[email protected]> Signed-off-by: Daniel P. Berrangé <[email protected]>
1 parent 7d3660e commit b767d25

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

configure

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,7 @@ libpmem=""
509509
default_devices="yes"
510510
plugins="no"
511511
fuzzing="no"
512+
rng_none="no"
512513

513514
supported_cpu="no"
514515
supported_os="no"
@@ -1601,6 +1602,10 @@ for opt do
16011602
;;
16021603
--gdb=*) gdb_bin="$optarg"
16031604
;;
1605+
--enable-rng-none) rng_none=yes
1606+
;;
1607+
--disable-rng-none) rng_none=no
1608+
;;
16041609
*)
16051610
echo "ERROR: unknown option $opt"
16061611
echo "Try '$0 --help' for more information"
@@ -1898,6 +1903,7 @@ disabled with --disable-FEATURE, default is enabled if available:
18981903
debug-mutex mutex debugging support
18991904
libpmem libpmem support
19001905
xkbcommon xkbcommon support
1906+
rng-none dummy RNG, avoid using /dev/(u)random and getrandom()
19011907
19021908
NOTE: The object files are built at the place where configure is launched
19031909
EOF
@@ -6767,6 +6773,7 @@ echo "default devices $default_devices"
67676773
echo "plugin support $plugins"
67686774
echo "fuzzing support $fuzzing"
67696775
echo "gdb $gdb_bin"
6776+
echo "rng-none $rng_none"
67706777

67716778
if test "$supported_cpu" = "no"; then
67726779
echo
@@ -7744,6 +7751,10 @@ if test "$edk2_blobs" = "yes" ; then
77447751
echo "DECOMPRESS_EDK2_BLOBS=y" >> $config_host_mak
77457752
fi
77467753

7754+
if test "$rng_none" = "yes"; then
7755+
echo "CONFIG_RNG_NONE=y" >> $config_host_mak
7756+
fi
7757+
77477758
# use included Linux headers
77487759
if test "$linux" = "yes" ; then
77497760
mkdir -p linux-headers

crypto/Makefile.objs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,6 @@ crypto-obj-y += block-luks.o
3535

3636
util-obj-$(CONFIG_GCRYPT) += random-gcrypt.o
3737
util-obj-$(if $(CONFIG_GCRYPT),n,$(CONFIG_GNUTLS)) += random-gnutls.o
38-
util-obj-$(if $(CONFIG_GCRYPT),n,$(if $(CONFIG_GNUTLS),n,y)) += random-platform.o
38+
util-obj-$(if $(CONFIG_GCRYPT),n,$(if $(CONFIG_GNUTLS),n,$(CONFIG_RNG_NONE))) += random-none.o
39+
util-obj-$(if $(CONFIG_GCRYPT),n,$(if $(CONFIG_GNUTLS),n,$(if $(CONFIG_RNG_NONE),n,y))) += random-platform.o
3940
util-obj-y += aes.o init.o

crypto/random-none.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* QEMU Crypto "none" random number provider
3+
*
4+
* Copyright (c) 2020 Marek Marczykowski-Górecki
5+
6+
*
7+
* This library is free software; you can redistribute it and/or
8+
* modify it under the terms of the GNU Lesser General Public
9+
* License as published by the Free Software Foundation; either
10+
* version 2.1 of the License, or (at your option) any later version.
11+
*
12+
* This library is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
19+
*
20+
*/
21+
22+
#include "qemu/osdep.h"
23+
24+
#include "crypto/random.h"
25+
#include "qapi/error.h"
26+
27+
int qcrypto_random_init(Error **errp)
28+
{
29+
return 0;
30+
}
31+
32+
int qcrypto_random_bytes(void *buf,
33+
size_t buflen,
34+
Error **errp)
35+
{
36+
error_setg(errp, "Random bytes not available with \"none\" rng");
37+
return -1;
38+
}

0 commit comments

Comments
 (0)