From: matthias.bgg at kernel.org <matthias.bgg@kernel.org>
To: u-boot@lists.denx.de
Subject: [PATCH 1/2] lib: uuid: use RNG device if present
Date: Wed, 16 Dec 2020 11:41:16 +0100 [thread overview]
Message-ID: <20201216104117.10836-2-matthias.bgg@kernel.org> (raw)
In-Reply-To: <20201216104117.10836-1-matthias.bgg@kernel.org>
From: Matthias Brugger <mbrugger@suse.com>
When calculating a random UUID we use a weak seed.
Use a RNG device if present to increase entropy.
Signed-off-by: Matthias Brugger <mbrugger@suse.com>
---
lib/uuid.c | 20 +++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)
diff --git a/lib/uuid.c b/lib/uuid.c
index e62d5ca264..219d4b7767 100644
--- a/lib/uuid.c
+++ b/lib/uuid.c
@@ -15,6 +15,7 @@
#include <asm/io.h>
#include <part_efi.h>
#include <malloc.h>
+#include <rng.h>
/*
* UUID - Universally Unique IDentifier - 128 bits unique number.
@@ -249,9 +250,22 @@ void gen_rand_uuid(unsigned char *uuid_bin)
{
u32 ptr[4];
struct uuid *uuid = (struct uuid *)ptr;
- int i;
-
- srand(get_ticks() + rand());
+ int i, ret;
+ struct udevice *devp;
+ u8 randv = 0;
+
+#if defined(CONFIG_DM_RNG)
+ ret = uclass_get_device(UCLASS_RNG, 0, &devp);
+ if (ret) {
+ ret = dm_rng_read(dev, randv, sizeof(randv));
+ if (ret < 0)
+ randv = 0;
+ }
+ if (randv)
+ srand(randv);
+ else
+#endif
+ srand(get_ticks() + rand());
/* Set all fields randomly */
for (i = 0; i < 4; i++)
--
2.29.2
next prev parent reply other threads:[~2020-12-16 10:41 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-16 10:41 [PATCH 0/2] Use RNG to get random behaviour matthias.bgg at kernel.org
2020-12-16 10:41 ` matthias.bgg at kernel.org [this message]
2020-12-16 13:22 ` [PATCH 1/2] lib: uuid: use RNG device if present Torsten Duwe
2020-12-16 10:41 ` [PATCH 2/2] net: Use NDRNG device in srand_mac() matthias.bgg at kernel.org
2020-12-16 13:20 ` Torsten Duwe
2020-12-16 15:56 ` Matthias Brugger
2020-12-16 13:17 ` [PATCH 0/2] Use RNG to get random behaviour Torsten Duwe
2020-12-16 13:42 ` Peter Robinson
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=20201216104117.10836-2-matthias.bgg@kernel.org \
--to=matthias.bgg@kernel.org \
--cc=u-boot@lists.denx.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