powerpc: Hard wire PT_SOFTE value to 1 in ptrace & signals
[linux/fpc-iii.git] / arch / powerpc / crypto / crc-vpmsum_test.c
blob0153a9c6f4af5561a44eb4a878db63129145548b
1 /*
2 * CRC vpmsum tester
3 * Copyright 2017 Daniel Axtens, IBM Corporation.
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.
8 */
10 #include <linux/crc-t10dif.h>
11 #include <linux/crc32.h>
12 #include <crypto/internal/hash.h>
13 #include <linux/init.h>
14 #include <linux/module.h>
15 #include <linux/string.h>
16 #include <linux/kernel.h>
17 #include <linux/cpufeature.h>
18 #include <asm/switch_to.h>
20 static unsigned long iterations = 10000;
22 #define MAX_CRC_LENGTH 65535
25 static int __init crc_test_init(void)
27 u16 crc16 = 0, verify16 = 0;
28 u32 crc32 = 0, verify32 = 0;
29 __le32 verify32le = 0;
30 unsigned char *data;
31 unsigned long i;
32 int ret;
34 struct crypto_shash *crct10dif_tfm;
35 struct crypto_shash *crc32c_tfm;
37 if (!cpu_has_feature(CPU_FTR_ARCH_207S))
38 return -ENODEV;
40 data = kmalloc(MAX_CRC_LENGTH, GFP_KERNEL);
41 if (!data)
42 return -ENOMEM;
44 crct10dif_tfm = crypto_alloc_shash("crct10dif", 0, 0);
46 if (IS_ERR(crct10dif_tfm)) {
47 pr_err("Error allocating crc-t10dif\n");
48 goto free_buf;
51 crc32c_tfm = crypto_alloc_shash("crc32c", 0, 0);
53 if (IS_ERR(crc32c_tfm)) {
54 pr_err("Error allocating crc32c\n");
55 goto free_16;
58 do {
59 SHASH_DESC_ON_STACK(crct10dif_shash, crct10dif_tfm);
60 SHASH_DESC_ON_STACK(crc32c_shash, crc32c_tfm);
62 crct10dif_shash->tfm = crct10dif_tfm;
63 ret = crypto_shash_init(crct10dif_shash);
65 if (ret) {
66 pr_err("Error initing crc-t10dif\n");
67 goto free_32;
71 crc32c_shash->tfm = crc32c_tfm;
72 ret = crypto_shash_init(crc32c_shash);
74 if (ret) {
75 pr_err("Error initing crc32c\n");
76 goto free_32;
79 pr_info("crc-vpmsum_test begins, %lu iterations\n", iterations);
80 for (i=0; i<iterations; i++) {
81 size_t len, offset;
83 get_random_bytes(data, MAX_CRC_LENGTH);
84 get_random_bytes(&len, sizeof(len));
85 get_random_bytes(&offset, sizeof(offset));
87 len %= MAX_CRC_LENGTH;
88 offset &= 15;
89 if (len <= offset)
90 continue;
91 len -= offset;
93 crypto_shash_update(crct10dif_shash, data+offset, len);
94 crypto_shash_final(crct10dif_shash, (u8 *)(&crc16));
95 verify16 = crc_t10dif_generic(verify16, data+offset, len);
98 if (crc16 != verify16) {
99 pr_err("FAILURE in CRC16: got 0x%04x expected 0x%04x (len %lu)\n",
100 crc16, verify16, len);
101 break;
104 crypto_shash_update(crc32c_shash, data+offset, len);
105 crypto_shash_final(crc32c_shash, (u8 *)(&crc32));
106 verify32 = le32_to_cpu(verify32le);
107 verify32le = ~cpu_to_le32(__crc32c_le(~verify32, data+offset, len));
108 if (crc32 != (u32)verify32le) {
109 pr_err("FAILURE in CRC32: got 0x%08x expected 0x%08x (len %lu)\n",
110 crc32, verify32, len);
111 break;
114 pr_info("crc-vpmsum_test done, completed %lu iterations\n", i);
115 } while (0);
117 free_32:
118 crypto_free_shash(crc32c_tfm);
120 free_16:
121 crypto_free_shash(crct10dif_tfm);
123 free_buf:
124 kfree(data);
126 return 0;
129 static void __exit crc_test_exit(void) {}
131 module_init(crc_test_init);
132 module_exit(crc_test_exit);
133 module_param(iterations, long, 0400);
135 MODULE_AUTHOR("Daniel Axtens <dja@axtens.net>");
136 MODULE_DESCRIPTION("Vector polynomial multiply-sum CRC tester");
137 MODULE_LICENSE("GPL");