Message ID | 20190315032629.21234-23-richard.henderson@linaro.org |
---|---|
State | Superseded |
Headers | show |
Series | Add qemu_getrandom and ARMv8.5-RNG etc | expand |
On Thu, Mar 14, 2019 at 08:26:28PM -0700, Richard Henderson wrote: > We now have an interface for guest visible random numbers. > > Cc: qemu-ppc@nongnu.org > Cc: David Gibson <david@gibson.dropbear.id.au> > Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Acked-by: David Gibson <david@gibson.dropbear.id.au> Do you want me to take this through my tree? > --- > target/ppc/int_helper.c | 38 +++++++++++++++++++++++++++----------- > 1 file changed, 27 insertions(+), 11 deletions(-) > > diff --git a/target/ppc/int_helper.c b/target/ppc/int_helper.c > index 162add561e..c26531e598 100644 > --- a/target/ppc/int_helper.c > +++ b/target/ppc/int_helper.c > @@ -23,6 +23,8 @@ > #include "exec/helper-proto.h" > #include "crypto/aes.h" > #include "fpu/softfloat.h" > +#include "qapi/error.h" > +#include "qemu/guest-random.h" > > #include "helper_regs.h" > /*****************************************************************************/ > @@ -156,25 +158,39 @@ uint32_t helper_cmpeqb(target_ulong ra, target_ulong rb) > #undef haszero > #undef hasvalue > > -/* Return invalid random number. > - * > - * FIXME: Add rng backend or other mechanism to get cryptographically suitable > - * random number > - */ > target_ulong helper_darn32(void) > { > - return -1; > + Error *err = NULL; > + uint32_t ret; > + > + if (qemu_guest_getrandom(&ret, 4, &err) < 0) { > + qemu_log_mask(LOG_UNIMP, "darn: Crypto failure: %s", > + error_get_pretty(err)); > + error_free(err); > + return -1; > + } > + > + return ret; > } > > target_ulong helper_darn64(void) > { > - return -1; > + Error *err = NULL; > + uint64_t ret; > + > + do { > + if (qemu_guest_getrandom(&ret, 8, &err) < 0) { > + qemu_log_mask(LOG_UNIMP, "darn: Crypto failure: %s", > + error_get_pretty(err)); > + error_free(err); > + return -1; > + } > + /* Since -1 is the error condition, try again for that case. */ > + } while (unlikely(ret == -1)); > + > + return ret; > } > > -#endif > - > -#if defined(TARGET_PPC64) > - > uint64_t helper_bpermd(uint64_t rs, uint64_t rb) > { > int i; -- David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
On 3/20/19 5:39 PM, David Gibson wrote: > On Thu, Mar 14, 2019 at 08:26:28PM -0700, Richard Henderson wrote: >> We now have an interface for guest visible random numbers. >> >> Cc: qemu-ppc@nongnu.org >> Cc: David Gibson <david@gibson.dropbear.id.au> >> Signed-off-by: Richard Henderson <richard.henderson@linaro.org> > > Acked-by: David Gibson <david@gibson.dropbear.id.au> > > Do you want me to take this through my tree? I don't mind keeping it all together if you don't. Otherwise you'll just have to wait for the base part of the patch set to land. r~
On Wed, Mar 20, 2019 at 08:50:40PM -0700, Richard Henderson wrote: > On 3/20/19 5:39 PM, David Gibson wrote: > > On Thu, Mar 14, 2019 at 08:26:28PM -0700, Richard Henderson wrote: > >> We now have an interface for guest visible random numbers. > >> > >> Cc: qemu-ppc@nongnu.org > >> Cc: David Gibson <david@gibson.dropbear.id.au> > >> Signed-off-by: Richard Henderson <richard.henderson@linaro.org> > > > > Acked-by: David Gibson <david@gibson.dropbear.id.au> > > > > Do you want me to take this through my tree? > > I don't mind keeping it all together if you don't. Sounds good, I'll let you handle it then. > Otherwise you'll just have to wait for the base part of the patch set to land. > > > r~ > -- David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
diff --git a/target/ppc/int_helper.c b/target/ppc/int_helper.c index 162add561e..c26531e598 100644 --- a/target/ppc/int_helper.c +++ b/target/ppc/int_helper.c @@ -23,6 +23,8 @@ #include "exec/helper-proto.h" #include "crypto/aes.h" #include "fpu/softfloat.h" +#include "qapi/error.h" +#include "qemu/guest-random.h" #include "helper_regs.h" /*****************************************************************************/ @@ -156,25 +158,39 @@ uint32_t helper_cmpeqb(target_ulong ra, target_ulong rb) #undef haszero #undef hasvalue -/* Return invalid random number. - * - * FIXME: Add rng backend or other mechanism to get cryptographically suitable - * random number - */ target_ulong helper_darn32(void) { - return -1; + Error *err = NULL; + uint32_t ret; + + if (qemu_guest_getrandom(&ret, 4, &err) < 0) { + qemu_log_mask(LOG_UNIMP, "darn: Crypto failure: %s", + error_get_pretty(err)); + error_free(err); + return -1; + } + + return ret; } target_ulong helper_darn64(void) { - return -1; + Error *err = NULL; + uint64_t ret; + + do { + if (qemu_guest_getrandom(&ret, 8, &err) < 0) { + qemu_log_mask(LOG_UNIMP, "darn: Crypto failure: %s", + error_get_pretty(err)); + error_free(err); + return -1; + } + /* Since -1 is the error condition, try again for that case. */ + } while (unlikely(ret == -1)); + + return ret; } -#endif - -#if defined(TARGET_PPC64) - uint64_t helper_bpermd(uint64_t rs, uint64_t rb) { int i;
We now have an interface for guest visible random numbers. Cc: qemu-ppc@nongnu.org Cc: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Richard Henderson <richard.henderson@linaro.org> --- target/ppc/int_helper.c | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) -- 2.17.2