diff mbox series

[v3,19/23] hw/misc/exynos4210_rng: Use qemu_guest_getrandom

Message ID 20190315032629.21234-20-richard.henderson@linaro.org
State Superseded
Headers show
Series Add qemu_getrandom and ARMv8.5-RNG etc | expand

Commit Message

Richard Henderson March 15, 2019, 3:26 a.m. UTC
The random number is intended for use by the guest.  As such, we should
honor the -seed argument for reproducibility.

Cc: qemu-arm@nongnu.org
Cc: Igor Mitsyanko <i.mitsyanko@gmail.com>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

---
 hw/misc/exynos4210_rng.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

-- 
2.17.2

Comments

Philippe Mathieu-Daudé April 11, 2019, 9:53 a.m. UTC | #1
On 3/15/19 4:26 AM, Richard Henderson wrote:
> The random number is intended for use by the guest.  As such, we should

> honor the -seed argument for reproducibility.

> 

> Cc: qemu-arm@nongnu.org

> Cc: Igor Mitsyanko <i.mitsyanko@gmail.com>

> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

> ---

>  hw/misc/exynos4210_rng.c | 11 ++++-------

>  1 file changed, 4 insertions(+), 7 deletions(-)

> 

> diff --git a/hw/misc/exynos4210_rng.c b/hw/misc/exynos4210_rng.c

> index 4ecbebd2d7..0e70ffb404 100644

> --- a/hw/misc/exynos4210_rng.c

> +++ b/hw/misc/exynos4210_rng.c

> @@ -18,10 +18,10 @@

>   */

>  

>  #include "qemu/osdep.h"

> -#include "crypto/random.h"

>  #include "hw/sysbus.h"

>  #include "qapi/error.h"

>  #include "qemu/log.h"

> +#include "qemu/guest-random.h"

>  

>  #define DEBUG_EXYNOS_RNG 0

>  

> @@ -109,7 +109,6 @@ static void exynos4210_rng_set_seed(Exynos4210RngState *s, unsigned int i,

>  static void exynos4210_rng_run_engine(Exynos4210RngState *s)

>  {

>      Error *err = NULL;

> -    int ret;

>  

>      /* Seed set? */

>      if ((s->reg_status & EXYNOS4210_RNG_STATUS_SEED_SETTING_DONE) == 0) {

> @@ -127,13 +126,11 @@ static void exynos4210_rng_run_engine(Exynos4210RngState *s)

>      }

>  

>      /* Get randoms */

> -    ret = qcrypto_random_bytes((uint8_t *)s->randr_value,

> -                               sizeof(s->randr_value), &err);

> -    if (!ret) {

> +    if (qemu_guest_getrandom(s->randr_value, sizeof(s->randr_value), &err)) {

> +        error_report_err(err);

> +    } else {

>          /* Notify that PRNG is ready */

>          s->reg_status |= EXYNOS4210_RNG_STATUS_PRNG_DONE;

> -    } else {

> -        error_report_err(err);

>      }

>  

>  out:

> 


Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
diff mbox series

Patch

diff --git a/hw/misc/exynos4210_rng.c b/hw/misc/exynos4210_rng.c
index 4ecbebd2d7..0e70ffb404 100644
--- a/hw/misc/exynos4210_rng.c
+++ b/hw/misc/exynos4210_rng.c
@@ -18,10 +18,10 @@ 
  */
 
 #include "qemu/osdep.h"
-#include "crypto/random.h"
 #include "hw/sysbus.h"
 #include "qapi/error.h"
 #include "qemu/log.h"
+#include "qemu/guest-random.h"
 
 #define DEBUG_EXYNOS_RNG 0
 
@@ -109,7 +109,6 @@  static void exynos4210_rng_set_seed(Exynos4210RngState *s, unsigned int i,
 static void exynos4210_rng_run_engine(Exynos4210RngState *s)
 {
     Error *err = NULL;
-    int ret;
 
     /* Seed set? */
     if ((s->reg_status & EXYNOS4210_RNG_STATUS_SEED_SETTING_DONE) == 0) {
@@ -127,13 +126,11 @@  static void exynos4210_rng_run_engine(Exynos4210RngState *s)
     }
 
     /* Get randoms */
-    ret = qcrypto_random_bytes((uint8_t *)s->randr_value,
-                               sizeof(s->randr_value), &err);
-    if (!ret) {
+    if (qemu_guest_getrandom(s->randr_value, sizeof(s->randr_value), &err)) {
+        error_report_err(err);
+    } else {
         /* Notify that PRNG is ready */
         s->reg_status |= EXYNOS4210_RNG_STATUS_PRNG_DONE;
-    } else {
-        error_report_err(err);
     }
 
 out: