arch/powerpc/crypto/crc-vpmsum_test: Use cheaper random numbers for self-test
Subsystems (2)
PATCH 1/1 arch/powerpc/crypto/crc-vpmsum_test: Use cheaper random numbers for self-test
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.
--- arch/powerpc/crypto/crc-vpmsum_test.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
arch/powerpc/crypto/crc-vpmsum_test.c +3 -7
@@ -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);
Signature · 1 line
2.20.1
Hi George,
Quoted 7 lines
This code was filling a 64K buffer from
/dev/urandomin 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.
Quoted 1 line
And, while we're at it, only fill as much of the buffer as we plan to use.
This also looks good to me.
Regards,
Daniel
Quoted 38 lines
Signed-off-by George Spelvin <[email protected]>Cc Daniel Axtens <[email protected]>Cc Herbert Xu <[email protected]>Cc Benjamin Herrenschmidt <[email protected]>Cc Paul Mackerras <[email protected]>Cc Michael Ellerman <[email protected]>--- arch/powerpc/crypto/crc-vpmsum_test.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)arch/powerpc/crypto/crc-vpmsum_test.c +3
-7@@ -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);Signature · 1 line
2.20.1
Michael Ellerman
AppliedQuoted 9 lines · George Spelvin
This code was filling a 64K buffer from
/dev/urandomin 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.
Quoted 8 lines
Signed-off-by George Spelvin <[email protected]>Cc Daniel Axtens <[email protected]>Cc Herbert Xu <[email protected]>Cc Benjamin Herrenschmidt <[email protected]>Cc Paul Mackerras <[email protected]>Cc Michael Ellerman <[email protected]>Acked-by Daniel Axtens <[email protected]>
Applied to powerpc next, thanks.
https://git.kernel.org/powerpc/c/80d04b7fabe161a23d143b3bfcfca1b0
cheers