* [PATCH] arch/powerpc/crypto/crc-vpmsum_test: Use cheaper random numbers for self-test
@ 2019-03-21 10:42 George Spelvin
2019-03-22 2:13 ` Daniel Axtens
2019-04-21 14:18 ` Michael Ellerman
0 siblings, 2 replies; 3+ messages in thread
From: George Spelvin @ 2019-03-21 10:42 UTC (permalink / raw)
To: Daniel Axtens, linuxppc-dev; +Cc: George Spelvin, Paul Mackerras, Herbert Xu
This code was filling a 64K buffer from /dev/urandom in order to
compute a CRC over (on average half of) it by two different methods,
comparing the CRCs, and repeating.
This is not a remotely security-critical application, so use the far
faster and cheaper prandom_u32() generator.
And, while we're at it, only fill as much of the buffer as we plan to use.
Signed-off-by: George Spelvin <lkml@sdf.org>
Cc: Daniel Axtens <dja@axtens.net>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Cc: linuxppc-dev@lists.ozlabs.org
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
---
arch/powerpc/crypto/crc-vpmsum_test.c | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/arch/powerpc/crypto/crc-vpmsum_test.c b/arch/powerpc/crypto/crc-vpmsum_test.c
index 0153a9c6f4af..98ea4f4d3dde 100644
--- a/arch/powerpc/crypto/crc-vpmsum_test.c
+++ b/arch/powerpc/crypto/crc-vpmsum_test.c
@@ -78,16 +78,12 @@ static int __init crc_test_init(void)
pr_info("crc-vpmsum_test begins, %lu iterations\n", iterations);
for (i=0; i<iterations; i++) {
- size_t len, offset;
+ size_t offset = prandom_u32_max(16);
+ size_t len = prandom_u32_max(MAX_CRC_LENGTH);
- get_random_bytes(data, MAX_CRC_LENGTH);
- get_random_bytes(&len, sizeof(len));
- get_random_bytes(&offset, sizeof(offset));
-
- len %= MAX_CRC_LENGTH;
- offset &= 15;
if (len <= offset)
continue;
+ prandom_bytes(data, len);
len -= offset;
crypto_shash_update(crct10dif_shash, data+offset, len);
--
2.20.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] arch/powerpc/crypto/crc-vpmsum_test: Use cheaper random numbers for self-test
2019-03-21 10:42 [PATCH] arch/powerpc/crypto/crc-vpmsum_test: Use cheaper random numbers for self-test George Spelvin
@ 2019-03-22 2:13 ` Daniel Axtens
2019-04-21 14:18 ` Michael Ellerman
1 sibling, 0 replies; 3+ messages in thread
From: Daniel Axtens @ 2019-03-22 2:13 UTC (permalink / raw)
To: George Spelvin, linuxppc-dev; +Cc: George Spelvin, Paul Mackerras, Herbert Xu
Hi George,
> This code was filling a 64K buffer from /dev/urandom in order to
> compute a CRC over (on average half of) it by two different methods,
> comparing the CRCs, and repeating.
>
> This is not a remotely security-critical application, so use the far
> faster and cheaper prandom_u32() generator.
>
I've had a quick look at the prandom_u32 generator and I agree that it's
suitable for this.
> And, while we're at it, only fill as much of the buffer as we plan to use.
This also looks good to me.
Acked-by: Daniel Axtens <dja@axtens.net>
Regards,
Daniel
>
> Signed-off-by: George Spelvin <lkml@sdf.org>
> Cc: Daniel Axtens <dja@axtens.net>
> Cc: Herbert Xu <herbert@gondor.apana.org.au>
> Cc: linuxppc-dev@lists.ozlabs.org
> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> Cc: Paul Mackerras <paulus@samba.org>
> Cc: Michael Ellerman <mpe@ellerman.id.au>
> ---
> arch/powerpc/crypto/crc-vpmsum_test.c | 10 +++-------
> 1 file changed, 3 insertions(+), 7 deletions(-)
>
> diff --git a/arch/powerpc/crypto/crc-vpmsum_test.c b/arch/powerpc/crypto/crc-vpmsum_test.c
> index 0153a9c6f4af..98ea4f4d3dde 100644
> --- a/arch/powerpc/crypto/crc-vpmsum_test.c
> +++ b/arch/powerpc/crypto/crc-vpmsum_test.c
> @@ -78,16 +78,12 @@ static int __init crc_test_init(void)
>
> pr_info("crc-vpmsum_test begins, %lu iterations\n", iterations);
> for (i=0; i<iterations; i++) {
> - size_t len, offset;
> + size_t offset = prandom_u32_max(16);
> + size_t len = prandom_u32_max(MAX_CRC_LENGTH);
>
> - get_random_bytes(data, MAX_CRC_LENGTH);
> - get_random_bytes(&len, sizeof(len));
> - get_random_bytes(&offset, sizeof(offset));
> -
> - len %= MAX_CRC_LENGTH;
> - offset &= 15;
> if (len <= offset)
> continue;
> + prandom_bytes(data, len);
> len -= offset;
>
> crypto_shash_update(crct10dif_shash, data+offset, len);
> --
> 2.20.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: arch/powerpc/crypto/crc-vpmsum_test: Use cheaper random numbers for self-test
2019-03-21 10:42 [PATCH] arch/powerpc/crypto/crc-vpmsum_test: Use cheaper random numbers for self-test George Spelvin
2019-03-22 2:13 ` Daniel Axtens
@ 2019-04-21 14:18 ` Michael Ellerman
1 sibling, 0 replies; 3+ messages in thread
From: Michael Ellerman @ 2019-04-21 14:18 UTC (permalink / raw)
To: George Spelvin, Daniel Axtens, linuxppc-dev
Cc: George Spelvin, Paul Mackerras, Herbert Xu
On Thu, 2019-03-21 at 10:42:22 UTC, George Spelvin wrote:
> This code was filling a 64K buffer from /dev/urandom in order to
> compute a CRC over (on average half of) it by two different methods,
> comparing the CRCs, and repeating.
>
> This is not a remotely security-critical application, so use the far
> faster and cheaper prandom_u32() generator.
>
> And, while we're at it, only fill as much of the buffer as we plan to use.
>
> Signed-off-by: George Spelvin <lkml@sdf.org>
> Cc: Daniel Axtens <dja@axtens.net>
> Cc: Herbert Xu <herbert@gondor.apana.org.au>
> Cc: linuxppc-dev@lists.ozlabs.org
> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> Cc: Paul Mackerras <paulus@samba.org>
> Cc: Michael Ellerman <mpe@ellerman.id.au>
> Acked-by: Daniel Axtens <dja@axtens.net>
Applied to powerpc next, thanks.
https://git.kernel.org/powerpc/c/80d04b7fabe161a23d143b3bfcfca1b0
cheers
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-04-21 14:38 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-21 10:42 [PATCH] arch/powerpc/crypto/crc-vpmsum_test: Use cheaper random numbers for self-test George Spelvin
2019-03-22 2:13 ` Daniel Axtens
2019-04-21 14:18 ` Michael Ellerman
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.