[PATCH v3 5/8] sandbox: rng: Add a random number generator(rng) driver

Sughosh Ganu sughosh.ganu at linaro.org
Mon Dec 16 19:59:15 CET 2019


hi Patrick,

On Mon, 16 Dec 2019 at 18:00, Patrick DELAUNAY <patrick.delaunay at st.com>
wrote:

> Hi,
>
> > From: U-Boot <u-boot-bounces at lists.denx.de> On Behalf Of Sughosh Ganu
> > Sent: vendredi 13 décembre 2019 08:14
> >
> > Add a sandbox driver for random number generation. Mostly aimed at
> providing a
> > unit test for rng uclass.
> >
> > Signed-off-by: Sughosh Ganu <sughosh.ganu at linaro.org>
> > Reviewed-by: Patrice Chotard <patrice.chotard at st.com>
> > ---
> >  arch/sandbox/dts/test.dts |  4 ++++
> >  drivers/rng/Kconfig       |  7 +++++++
> >  drivers/rng/Makefile      |  1 +
> >  drivers/rng/sandbox_rng.c | 36 ++++++++++++++++++++++++++++++++++++
> >  4 files changed, 48 insertions(+)
> >  create mode 100644 drivers/rng/sandbox_rng.c
>

<snip>

>
> > a/drivers/rng/sandbox_rng.c b/drivers/rng/sandbox_rng.c new file mode
> 100644
> > index 0000000..c5be552
> > --- /dev/null
> > +++ b/drivers/rng/sandbox_rng.c
> > @@ -0,0 +1,36 @@
> > +// SPDX-License-Identifier: GPL-2.0-or-later
> > +/*
> > + * Copyright (c) 2019, Linaro Limited
> > + */
> > +
> > +#include <common.h>
> > +#include <dm.h>
> > +#include <rng.h>
> > +
> > +static unsigned long random = 0xdeadbeef;
> > +
> > +static int sandbox_rng_read(struct udevice *dev, void *data, size_t
> > +len) {
>
> Add protection on length  I think:
>         If (len != sizeof(random))
>                 retrun - EINVAL;
>

Ok. Will add this check.


>
> or treat the case len > 4 with loop ?
>
> > +     random ^= ~0UL;
> > +     *(unsigned long *)data = random;
> > +
> > +     return sizeof(random);
>
> Read is OK, so I think the correct return value is 0:
>

Ok. Will change.


>
>         return 0;
>
> NB: result (int) can be not enough to return the value read (size_t)
>
> PS: it not really a random generator here but simple sequence
>        0xdeadbeef -> 0x21524110 -> 0xdeadbeef
>
>       It is enough for unitary test, but is is enough for sandbox ?
>       we could reused PRNG code from lib/rand.c ?
>

I actually wrote this solely from the point of view of adding a unit test
for the rng uclass. For which i think the simple sequence above should
suffice. Do you have a strong opinion on this. If so, i can change the
logic.

-sughosh

>
>


More information about the U-Boot mailing list