From: Sascha Hauer <s.hauer@pengutronix.de>
To: Oleksij Rempel <o.rempel@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH v6 3/8] lib: random: add get_crypto_bytes interface and use HWRNG if posssible
Date: Wed, 22 Mar 2017 08:33:37 +0100 [thread overview]
Message-ID: <20170322073337.htisik3gw54cnce7@pengutronix.de> (raw)
In-Reply-To: <20170321140025.25784-4-o.rempel@pengutronix.de>
On Tue, Mar 21, 2017 at 03:00:20PM +0100, Oleksij Rempel wrote:
> For crypto applications we need to use some thing else as PRNG.
> So provide get_crypto_bytes() and use HWRNG as main source.
> PRNG is allowed as fallback if user decided to configure it so.
>
> static unsigned int random_seed;
>
> @@ -18,6 +19,11 @@ void srand(unsigned int seed)
> random_seed = seed;
> }
>
> +/**
> + * get_random_bytes - get pseudo random numbers.
> + * This interface can be good enough to generate MAC address
> + * or use for NAND test.
> + */
> void get_random_bytes(void *_buf, int len)
> {
> char *buf = _buf;
> @@ -25,3 +31,53 @@ void get_random_bytes(void *_buf, int len)
> while (len--)
> *buf++ = rand() % 256;
> }
> +
> +/**
> + * get_crypto_bytes - get random numbers suitable for cryptographic needs.
> + */
> +static int _get_crypto_bytes(void *_buf, int len)
> +{
> + struct hwrng *rng;
> + u8 *buf = _buf;
This extra u8 buffer pointer seems unnecessary. Why not use the input
void * throughout the function?
> +
> + if (!IS_ENABLED(CONFIG_HWRNG))
> + return -ENOENT;
> +
> + rng = hwrng_get_first();
Instead of having to test for CONFIG_HWRNG in the users
hwrng_get_first() could be a static inline function when CONFIG_HWRNG is
disabled.
Sascha
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2017-03-22 7:34 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-21 14:00 [PATCH v6 0/8] upstream hwrng framework Oleksij Rempel
2017-03-21 14:00 ` [PATCH v6 1/8] Release v2017.02.0 Oleksij Rempel
2017-03-21 14:08 ` Oleksij Rempel
2017-03-21 14:00 ` [PATCH v6 2/8] drivers: add simple hw_random implementation Oleksij Rempel
2017-03-22 7:34 ` Sascha Hauer
2017-03-21 14:00 ` [PATCH v6 3/8] lib: random: add get_crypto_bytes interface and use HWRNG if posssible Oleksij Rempel
2017-03-22 7:33 ` Sascha Hauer [this message]
2017-03-21 14:00 ` [PATCH v6 4/8] caamrng: port to hwrng framework Oleksij Rempel
2017-03-21 14:00 ` [PATCH v6 5/8] fs: add prng device Oleksij Rempel
2017-03-21 14:00 ` [PATCH v6 6/8] crypto: caam - fix RNG buffer cache alignment Oleksij Rempel
2017-03-21 14:00 ` [PATCH v6 7/8] common: password: make use of get_crypto_bytes Oleksij Rempel
2017-03-21 14:00 ` [PATCH v6 8/8] add seed command Oleksij Rempel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170322073337.htisik3gw54cnce7@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=o.rempel@pengutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox