forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-11 04dd17822334871b23ea2862f7798fb0e0007777
kernel/arch/powerpc/crypto/crc-vpmsum_test.c
....@@ -1,10 +1,7 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * CRC vpmsum tester
34 * Copyright 2017 Daniel Axtens, IBM Corporation.
4
- *
5
- * This program is free software; you can redistribute it and/or modify
6
- * it under the terms of the GNU General Public License version 2 as
7
- * published by the Free Software Foundation.
85 */
96
107 #include <linux/crc-t10dif.h>
....@@ -12,6 +9,7 @@
129 #include <crypto/internal/hash.h>
1310 #include <linux/init.h>
1411 #include <linux/module.h>
12
+#include <linux/random.h>
1513 #include <linux/string.h>
1614 #include <linux/kernel.h>
1715 #include <linux/cpufeature.h>
....@@ -25,10 +23,11 @@
2523 static int __init crc_test_init(void)
2624 {
2725 u16 crc16 = 0, verify16 = 0;
28
- u32 crc32 = 0, verify32 = 0;
2926 __le32 verify32le = 0;
3027 unsigned char *data;
28
+ u32 verify32 = 0;
3129 unsigned long i;
30
+ __le32 crc32;
3231 int ret;
3332
3433 struct crypto_shash *crct10dif_tfm;
....@@ -78,16 +77,12 @@
7877
7978 pr_info("crc-vpmsum_test begins, %lu iterations\n", iterations);
8079 for (i=0; i<iterations; i++) {
81
- size_t len, offset;
80
+ size_t offset = prandom_u32_max(16);
81
+ size_t len = prandom_u32_max(MAX_CRC_LENGTH);
8282
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;
8983 if (len <= offset)
9084 continue;
85
+ prandom_bytes(data, len);
9186 len -= offset;
9287
9388 crypto_shash_update(crct10dif_shash, data+offset, len);
....@@ -105,11 +100,12 @@
105100 crypto_shash_final(crc32c_shash, (u8 *)(&crc32));
106101 verify32 = le32_to_cpu(verify32le);
107102 verify32le = ~cpu_to_le32(__crc32c_le(~verify32, data+offset, len));
108
- if (crc32 != (u32)verify32le) {
103
+ if (crc32 != verify32le) {
109104 pr_err("FAILURE in CRC32: got 0x%08x expected 0x%08x (len %lu)\n",
110105 crc32, verify32, len);
111106 break;
112107 }
108
+ cond_resched();
113109 }
114110 pr_info("crc-vpmsum_test done, completed %lu iterations\n", i);
115111 } while (0);