Skip to content

Commit 80d04b7

Browse files
George Spelvinmpe
authored andcommitted
powerpc/crypto: Use cheaper random numbers for crc-vpmsum 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. Signed-off-by: George Spelvin <lkml@sdf.org> Acked-by: Daniel Axtens <dja@axtens.net> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
1 parent 6917735 commit 80d04b7

1 file changed

Lines changed: 3 additions & 7 deletions

File tree

‎arch/powerpc/crypto/crc-vpmsum_test.c‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,12 @@ static int __init crc_test_init(void)
7878

7979
pr_info("crc-vpmsum_test begins, %lu iterations\n", iterations);
8080
for (i=0; i<iterations; i++) {
81-
size_t len, offset;
81+
size_t offset = prandom_u32_max(16);
82+
size_t len = prandom_u32_max(MAX_CRC_LENGTH);
8283

83-
get_random_bytes(data, MAX_CRC_LENGTH);
84-
get_random_bytes(&len, sizeof(len));
85-
get_random_bytes(&offset, sizeof(offset));
86-
87-
len %= MAX_CRC_LENGTH;
88-
offset &= 15;
8984
if (len <= offset)
9085
continue;
86+
prandom_bytes(data, len);
9187
len -= offset;
9288

9389
crypto_shash_update(crct10dif_shash, data+offset, len);

0 commit comments

Comments
 (0)