aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorge Spelvin <lkml@sdf.org>2019-03-21 06:42:22 -0400
committerMichael Ellerman <mpe@ellerman.id.au>2019-04-20 08:03:11 -0400
commit80d04b7fabe161a23d143b3bfcfca1b002c23da1 (patch)
treec6e44382032d68519aa3975307fb0ece3c23d4b0
parent6917735e8f905da1f62ccdf62830b185524835c7 (diff)
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>
-rw-r--r--arch/powerpc/crypto/crc-vpmsum_test.c10
1 files 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)
78 78
79 pr_info("crc-vpmsum_test begins, %lu iterations\n", iterations); 79 pr_info("crc-vpmsum_test begins, %lu iterations\n", iterations);
80 for (i=0; i<iterations; i++) { 80 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);
82 83
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;
89 if (len <= offset) 84 if (len <= offset)
90 continue; 85 continue;
86 prandom_bytes(data, len);
91 len -= offset; 87 len -= offset;
92 88
93 crypto_shash_update(crct10dif_shash, data+offset, len); 89 crypto_shash_update(crct10dif_shash, data+offset, len);