LinuxPPC-Dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Axtens <dja@axtens.net>
To: George Spelvin <lkml@sdf.org>, linuxppc-dev@lists.ozlabs.org
Cc: George Spelvin <lkml@sdf.org>, Paul Mackerras <paulus@samba.org>,
	Herbert Xu <herbert@gondor.apana.org.au>
Subject: Re: [PATCH] arch/powerpc/crypto/crc-vpmsum_test: Use cheaper random numbers for self-test
Date: Fri, 22 Mar 2019 13:13:56 +1100	[thread overview]
Message-ID: <87tvfvsljv.fsf@dja-thinkpad.axtens.net> (raw)
In-Reply-To: <201903211042.x2LAgMp3003053@sdf.org>

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

  reply	other threads:[~2019-03-22  2:15 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2019-04-21 14:18 ` Michael Ellerman

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=87tvfvsljv.fsf@dja-thinkpad.axtens.net \
    --to=dja@axtens.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=lkml@sdf.org \
    --cc=paulus@samba.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