From: George Spelvin <lkml@sdf.org>
To: linux-kernel@vger.kernel.org, lkml@sdf.org
Cc: Herbert Xu <herbert@gondor.apana.org.au>, linux-crypto@vger.kernel.org
Subject: [RFC PATCH v1 14/50] crypto/testmgr.c: use prandom_u32_max() & prandom_bytes()
Date: Fri, 29 Nov 2019 15:24:22 -0500 [thread overview]
Message-ID: <202003281643.02SGhCt7025631@sdf.org> (raw)
...in a couple of places where they're appropriate.
There are many other places where successive code blocks make calls
like prandom_u32() % 2 followed immediately by prandom_u32() % 4.
This could be easily written to use three bits of one call, but
at some cost in clarity and obvious-correctness, which is more
important that efficiency in self-test code.
Signed-off-by: George Spelvin <lkml@sdf.org>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Cc: linux-crypto@vger.kernel.org
---
crypto/testmgr.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/crypto/testmgr.c b/crypto/testmgr.c
index e8f21f7348a48..bc9252768bdba 100644
--- a/crypto/testmgr.c
+++ b/crypto/testmgr.c
@@ -770,7 +770,7 @@ static void mutate_buffer(u8 *buf, size_t count)
if (prandom_u32() % 4 == 0) {
num_flips = min_t(size_t, 1 << (prandom_u32() % 8), count * 8);
for (i = 0; i < num_flips; i++) {
- pos = prandom_u32() % (count * 8);
+ pos = prandom_u32_max(count * 8);
buf[pos / 8] ^= 1 << (pos % 8);
}
}
@@ -821,8 +821,7 @@ static void generate_random_bytes(u8 *buf, size_t count)
break;
default:
/* Fully random bytes */
- for (i = 0; i < count; i++)
- buf[i] = (u8)prandom_u32();
+ prandom_bytes(buf, count);
}
}
--
2.26.0
reply other threads:[~2020-03-28 16:43 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=202003281643.02SGhCt7025631@sdf.org \
--to=lkml@sdf.org \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).