2020-01-16 00:54:13

by Randy Dunlap

[permalink] [raw]
Subject: Re: [PATCH v28 06/12] LRNG - add SP800-90A DRBG extension

On 1/15/20 2:33 AM, Stephan Müller wrote:

>
> CC: "Eric W. Biederman" <[email protected]>
> CC: "Alexander E. Patrakov" <[email protected]>
> CC: "Ahmed S. Darwish" <[email protected]>
> CC: "Theodore Y. Ts'o" <[email protected]>
> CC: Willy Tarreau <[email protected]>
> CC: Matthew Garrett <[email protected]>
> CC: Vito Caputo <[email protected]>
> CC: Andreas Dilger <[email protected]>
> CC: Jan Kara <[email protected]>
> CC: Ray Strode <[email protected]>
> CC: William Jon McCann <[email protected]>
> CC: zhangjs <[email protected]>
> CC: Andy Lutomirski <[email protected]>
> CC: Florian Weimer <[email protected]>
> CC: Lennart Poettering <[email protected]>
> CC: Nicolai Stange <[email protected]>
> Reviewed-by: Roman Drahtmueller <[email protected]>
> Tested-by: Roman Drahtmüller <[email protected]>
> Tested-by: Marcelo Henrique Cerri <[email protected]>
> Tested-by: Neil Horman <[email protected]>
> Signed-off-by: Stephan Mueller <[email protected]>
> ---
> drivers/char/lrng/Kconfig | 11 ++
> drivers/char/lrng/Makefile | 1 +
> drivers/char/lrng/lrng_drbg.c | 260 ++++++++++++++++++++++++++++++++++
> 3 files changed, 272 insertions(+)
> create mode 100644 drivers/char/lrng/lrng_drbg.c
>
> diff --git a/drivers/char/lrng/Kconfig b/drivers/char/lrng/Kconfig
> index cb701bb0b8b6..15fb623d9d1f 100644
> --- a/drivers/char/lrng/Kconfig
> +++ b/drivers/char/lrng/Kconfig
> @@ -71,4 +71,15 @@ menuconfig LRNG_DRNG_SWITCH
> accessible via the external interfaces. With this configuration
> option other DRNGs can be selected and loaded at runtime.
>
> +if LRNG_DRNG_SWITCH
> +config LRNG_DRBG
> + tristate "SP800-90A support for the LRNG"
> + select CRYPTO_DRBG_MENU
> + select CRYPTO_CMAC if CRYPTO_DRBG_CTR

Don't select these if CRYPTO is not already set/enabled.
It causes Kconfig warnings and possible build errors.

> + help
> + Enable the SP800-90A DRBG support for the LRNG. Once the
> + module is loaded, output from /dev/random, /dev/urandom,
> + getrandom(2), or get_random_bytes is provided by a DRBG.
> +endif # LRNG_DRNG_SWITCH
> +
> endif # LRNG

> diff --git a/drivers/char/lrng/lrng_drbg.c b/drivers/char/lrng/lrng_drbg.c
> new file mode 100644
> index 000000000000..8bf2badb1fe0
> --- /dev/null
> +++ b/drivers/char/lrng/lrng_drbg.c
> @@ -0,0 +1,260 @@
> +// SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause
> +/*
> + * Backend for the LRNG providing the cryptographic primitives using the
> + * kernel crypto API and its DRBG.
> + *
> + * Copyright (C) 2016 - 2020, Stephan Mueller <[email protected]>
> + */
> +
> +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
> +
> +#include <crypto/drbg.h>
> +#include <linux/init.h>
> +#include <linux/module.h>
> +#include <linux/lrng.h>
> +
> +/*
> + * Define a DRBG plus a hash / MAC used to extract data from the entropy pool.
> + * For LRNG_HASH_NAME you can use a hash or a MAC (HMAC or CMAC) of your choice
> + * (Note, you should use the suggested selections below -- using SHA-1 or MD5
> + * is not wise). The idea is that the used cipher primitive can be selected to
> + * be the same as used for the DRBG. I.e. the LRNG only uses one cipher
> + * primitive using the same cipher implementation with the options offered in
> + * the following. This means, if the CTR DRBG is selected and AES-NI is present,
> + * both the CTR DRBG and the selected cmac(aes) use AES-NI.
> + *
> + * The security strengths of the DRBGs are all 256 bits according to
> + * SP800-57 section 5.6.1.
> + *
> + * This definition is allowed to be changed.
> + */
> +#ifdef CONFIG_CRYPTO_DRBG_CTR
> +static unsigned int lrng_drbg_type = 0;
> +#elif defined CONFIG_CRYPTO_DRBG_HMAC
> +static unsigned int lrng_drbg_type = 1;
> +#elif defined CONFIG_CRYPTO_DRBG_HASH
> +static unsigned int lrng_drbg_type = 2;
> +#else
> +#error "Unknown DRBG in use"
> +#endif
> +
> +/* The parameter must be r/o in sysfs as otherwise races appear. */
> +module_param(lrng_drbg_type, uint, 0444);
> +MODULE_PARM_DESC(lrng_drbg_type, "DRBG type used for LRNG (0->CTR_DRBG, "
> + "1->HMAC_DRBG, 2->Hash_DRBG)");

One line for the string, please, not split.

--
~Randy
Reported-by: Randy Dunlap <[email protected]>


2020-01-16 07:31:15

by Stephan Müller

[permalink] [raw]
Subject: Re: [PATCH v28 06/12] LRNG - add SP800-90A DRBG extension

Am Donnerstag, 16. Januar 2020, 01:14:35 CET schrieb Randy Dunlap:

Hi Randy,

> On 1/15/20 2:33 AM, Stephan M?ller wrote:
> > CC: "Eric W. Biederman" <[email protected]>
> > CC: "Alexander E. Patrakov" <[email protected]>
> > CC: "Ahmed S. Darwish" <[email protected]>
> > CC: "Theodore Y. Ts'o" <[email protected]>
> > CC: Willy Tarreau <[email protected]>
> > CC: Matthew Garrett <[email protected]>
> > CC: Vito Caputo <[email protected]>
> > CC: Andreas Dilger <[email protected]>
> > CC: Jan Kara <[email protected]>
> > CC: Ray Strode <[email protected]>
> > CC: William Jon McCann <[email protected]>
> > CC: zhangjs <[email protected]>
> > CC: Andy Lutomirski <[email protected]>
> > CC: Florian Weimer <[email protected]>
> > CC: Lennart Poettering <[email protected]>
> > CC: Nicolai Stange <[email protected]>
> > Reviewed-by: Roman Drahtmueller <[email protected]>
> > Tested-by: Roman Drahtm?ller <[email protected]>
> > Tested-by: Marcelo Henrique Cerri <[email protected]>
> > Tested-by: Neil Horman <[email protected]>
> > Signed-off-by: Stephan Mueller <[email protected]>
> > ---
> >
> > drivers/char/lrng/Kconfig | 11 ++
> > drivers/char/lrng/Makefile | 1 +
> > drivers/char/lrng/lrng_drbg.c | 260 ++++++++++++++++++++++++++++++++++
> > 3 files changed, 272 insertions(+)
> > create mode 100644 drivers/char/lrng/lrng_drbg.c
> >
> > diff --git a/drivers/char/lrng/Kconfig b/drivers/char/lrng/Kconfig
> > index cb701bb0b8b6..15fb623d9d1f 100644
> > --- a/drivers/char/lrng/Kconfig
> > +++ b/drivers/char/lrng/Kconfig
> > @@ -71,4 +71,15 @@ menuconfig LRNG_DRNG_SWITCH
> >
> > accessible via the external interfaces. With this configuration
> > option other DRNGs can be selected and loaded at runtime.
> >
> > +if LRNG_DRNG_SWITCH
> > +config LRNG_DRBG
> > + tristate "SP800-90A support for the LRNG"
> > + select CRYPTO_DRBG_MENU
> > + select CRYPTO_CMAC if CRYPTO_DRBG_CTR
>
> Don't select these if CRYPTO is not already set/enabled.
> It causes Kconfig warnings and possible build errors.

I added "depends on CRYPTO"
>
> > + help
> > + Enable the SP800-90A DRBG support for the LRNG. Once the
> > + module is loaded, output from /dev/random, /dev/urandom,
> > + getrandom(2), or get_random_bytes is provided by a DRBG.
> > +endif # LRNG_DRNG_SWITCH
> > +
> >
> > endif # LRNG
> >
> > diff --git a/drivers/char/lrng/lrng_drbg.c b/drivers/char/lrng/lrng_drbg.c
> > new file mode 100644
> > index 000000000000..8bf2badb1fe0
> > --- /dev/null
> > +++ b/drivers/char/lrng/lrng_drbg.c
> > @@ -0,0 +1,260 @@
> > +// SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause
> > +/*
> > + * Backend for the LRNG providing the cryptographic primitives using the
> > + * kernel crypto API and its DRBG.
> > + *
> > + * Copyright (C) 2016 - 2020, Stephan Mueller <[email protected]>
> > + */
> > +
> > +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
> > +
> > +#include <crypto/drbg.h>
> > +#include <linux/init.h>
> > +#include <linux/module.h>
> > +#include <linux/lrng.h>
> > +
> > +/*
> > + * Define a DRBG plus a hash / MAC used to extract data from the entropy
> > pool. + * For LRNG_HASH_NAME you can use a hash or a MAC (HMAC or CMAC)
> > of your choice + * (Note, you should use the suggested selections below
> > -- using SHA-1 or MD5 + * is not wise). The idea is that the used cipher
> > primitive can be selected to + * be the same as used for the DRBG. I.e.
> > the LRNG only uses one cipher + * primitive using the same cipher
> > implementation with the options offered in + * the following. This means,
> > if the CTR DRBG is selected and AES-NI is present, + * both the CTR DRBG
> > and the selected cmac(aes) use AES-NI.
> > + *
> > + * The security strengths of the DRBGs are all 256 bits according to
> > + * SP800-57 section 5.6.1.
> > + *
> > + * This definition is allowed to be changed.
> > + */
> > +#ifdef CONFIG_CRYPTO_DRBG_CTR
> > +static unsigned int lrng_drbg_type = 0;
> > +#elif defined CONFIG_CRYPTO_DRBG_HMAC
> > +static unsigned int lrng_drbg_type = 1;
> > +#elif defined CONFIG_CRYPTO_DRBG_HASH
> > +static unsigned int lrng_drbg_type = 2;
> > +#else
> > +#error "Unknown DRBG in use"
> > +#endif
> > +
> > +/* The parameter must be r/o in sysfs as otherwise races appear. */
> > +module_param(lrng_drbg_type, uint, 0444);
> > +MODULE_PARM_DESC(lrng_drbg_type, "DRBG type used for LRNG (0->CTR_DRBG, "
> > + "1->HMAC_DRBG, 2->Hash_DRBG)");
>
> One line for the string, please, not split.

Changed

Thank you.

Ciao
Stephan