[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH for-4.1 0/7] Add qemu_getrandom and ARMv8.5-RNG
From: |
Richard Henderson |
Subject: |
[Qemu-devel] [PATCH for-4.1 0/7] Add qemu_getrandom and ARMv8.5-RNG |
Date: |
Tue, 12 Mar 2019 23:26:23 -0700 |
While the comment for AT_RANDOM is still apropos, "not cryptically
secure but it's not the aim of QEMU", I think we can still do better
than N calls to rand(3).
The first patch sets up an interface that allows deterministic random
numbers across different threads, using jrand48. This function is:
(1) in POSIX, so is easy to assume,
(2) produces full 32-bit random numbers, as opposed to RAND_MAX,
making it easier to fill N bytes,
(3) has a much larger periodicity,
(4) is thread-safe (with restricted usage).
The second patch allows the use of getrandom(2), if available.
But if the -seed command-line option is used, we continue to
use the deterministic algorithm.
I leave the task of adding support for Windows BCryptGenRandom,
and BSD getentropy, to someone else. I didn't think it was worth it
to do anything with /dev/urandom, in case getrandom isn't present.
I replaced the existing major users of rand(3). There are a few left,
mostly within hw/. I'm really not sure whether it's worth changing
those, or what to do about them.
This could quickly be used to implement Power9's helper_darn{32,64},
or for implementing RDRAND for x86_64. I'm less sure about S390's
PRNO instruction; that seems to expose a lot of the DRNG at an
architectural level.
r~
Richard Henderson (7):
util: Add qemu_getrandom and support functions
util: Use getrandom for qemu_getrandom if available
linux-user: Use qemu_getrandom for AT_RANDOM
linux-user/aarch64: Use qemu_getrandom for arm_init_pauth_key
linux-user: Remove srand call
ui/vnc: Use qemu_getrandom for make_challenge
target/arm: Implement ARMv8.5-RNG
include/qemu/random.h | 58 ++++++++++++++
include/qom/cpu.h | 1 +
target/arm/cpu.h | 5 ++
cpus.c | 9 +++
linux-user/aarch64/cpu_loop.c | 16 +---
linux-user/elfload.c | 8 +-
linux-user/main.c | 11 +--
linux-user/syscall.c | 3 +
target/arm/cpu64.c | 1 +
target/arm/helper.c | 32 ++++++++
ui/vnc.c | 8 +-
util/random.c | 140 ++++++++++++++++++++++++++++++++++
vl.c | 4 +
configure | 18 ++++-
qemu-options.hx | 10 +++
util/Makefile.objs | 1 +
16 files changed, 290 insertions(+), 35 deletions(-)
create mode 100644 include/qemu/random.h
create mode 100644 util/random.c
--
2.17.1
- [Qemu-devel] [PATCH for-4.1 0/7] Add qemu_getrandom and ARMv8.5-RNG,
Richard Henderson <=
- [Qemu-devel] [PATCH for-4.1 4/7] linux-user/aarch64: Use qemu_getrandom for arm_init_pauth_key, Richard Henderson, 2019/03/13
- [Qemu-devel] [PATCH for-4.1 2/7] util: Use getrandom for qemu_getrandom if available, Richard Henderson, 2019/03/13
- [Qemu-devel] [PATCH for-4.1 5/7] linux-user: Remove srand call, Richard Henderson, 2019/03/13
- [Qemu-devel] [PATCH for-4.1 3/7] linux-user: Use qemu_getrandom for AT_RANDOM, Richard Henderson, 2019/03/13
- [Qemu-devel] [PATCH for-4.1 1/7] util: Add qemu_getrandom and support functions, Richard Henderson, 2019/03/13
- [Qemu-devel] [PATCH for-4.1 6/7] ui/vnc: Use qemu_getrandom for make_challenge, Richard Henderson, 2019/03/13
- [Qemu-devel] [PATCH for-4.1 7/7] target/arm: Implement ARMv8.5-RNG, Richard Henderson, 2019/03/13
- Re: [Qemu-devel] [PATCH for-4.1 0/7] Add qemu_getrandom and ARMv8.5-RNG, no-reply, 2019/03/13