]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
powerpc/crypto: Use cheaper random numbers for crc-vpmsum self-test
authorGeorge Spelvin <lkml@sdf.org>
Thu, 21 Mar 2019 10:42:22 +0000 (10:42 +0000)
committerMichael Ellerman <mpe@ellerman.id.au>
Sat, 20 Apr 2019 12:03:11 +0000 (22:03 +1000)
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>
arch/powerpc/crypto/crc-vpmsum_test.c

index 0153a9c6f4af5561a44eb4a878db63129145548b..98ea4f4d3dde81516ef04f5d8d1866b5af6e7a8b 100644 (file)
@@ -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);