]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /********************************************************************** |
2 | Copyright(c) 2011-2015 Intel Corporation All rights reserved. | |
3 | ||
4 | Redistribution and use in source and binary forms, with or without | |
5 | modification, are permitted provided that the following conditions | |
6 | are met: | |
7 | * Redistributions of source code must retain the above copyright | |
8 | notice, this list of conditions and the following disclaimer. | |
9 | * Redistributions in binary form must reproduce the above copyright | |
10 | notice, this list of conditions and the following disclaimer in | |
11 | the documentation and/or other materials provided with the | |
12 | distribution. | |
13 | * Neither the name of Intel Corporation nor the names of its | |
14 | contributors may be used to endorse or promote products derived | |
15 | from this software without specific prior written permission. | |
16 | ||
17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
28 | **********************************************************************/ | |
29 | ||
30 | #include <limits.h> | |
31 | #include <stdint.h> | |
32 | ||
33 | #if __WORDSIZE == 64 || _WIN64 || __x86_64__ | |
34 | # define notbit0 0xfefefefefefefefeULL | |
35 | # define bit7 0x8080808080808080ULL | |
36 | # define gf8poly 0x1d1d1d1d1d1d1d1dULL | |
37 | #else | |
38 | # define notbit0 0xfefefefeUL | |
39 | # define bit7 0x80808080UL | |
40 | # define gf8poly 0x1d1d1d1dUL | |
41 | #endif | |
42 | ||
43 | int pq_gen_base(int vects, int len, void **array) | |
44 | { | |
45 | int i, j; | |
46 | unsigned long p, q, s; | |
47 | unsigned long **src = (unsigned long **)array; | |
48 | int blocks = len / sizeof(long); | |
49 | ||
50 | for (i = 0; i < blocks; i++) { | |
51 | q = p = src[vects - 3][i]; | |
52 | ||
53 | for (j = vects - 4; j >= 0; j--) { | |
54 | p ^= s = src[j][i]; | |
55 | q = s ^ (((q << 1) & notbit0) ^ // shift each byte | |
56 | ((((q & bit7) << 1) - ((q & bit7) >> 7)) // mask out bytes | |
57 | & gf8poly)); // apply poly | |
58 | } | |
59 | ||
60 | src[vects - 2][i] = p; // second to last pointer is p | |
61 | src[vects - 1][i] = q; // last pointer is q | |
62 | } | |
63 | return 0; | |
64 | } | |
65 | ||
66 | int pq_check_base(int vects, int len, void **array) | |
67 | { | |
68 | int i, j; | |
69 | unsigned char p, q, s; | |
70 | unsigned char **src = (unsigned char **)array; | |
71 | ||
72 | for (i = 0; i < len; i++) { | |
73 | q = p = src[vects - 3][i]; | |
74 | ||
75 | for (j = vects - 4; j >= 0; j--) { | |
76 | s = src[j][i]; | |
77 | p ^= s; | |
78 | ||
79 | // mult by GF{2} | |
80 | q = s ^ ((q << 1) ^ ((q & 0x80) ? 0x1d : 0)); | |
81 | } | |
82 | ||
83 | if (src[vects - 2][i] != p) // second to last pointer is p | |
84 | return i | 1; | |
85 | if (src[vects - 1][i] != q) // last pointer is q | |
86 | return i | 2; | |
87 | } | |
88 | return 0; | |
89 | } | |
90 | ||
91 | int xor_gen_base(int vects, int len, void **array) | |
92 | { | |
93 | int i, j; | |
94 | unsigned char parity; | |
95 | unsigned char **src = (unsigned char **)array; | |
96 | ||
97 | for (i = 0; i < len; i++) { | |
98 | parity = src[0][i]; | |
99 | for (j = 1; j < vects - 1; j++) | |
100 | parity ^= src[j][i]; | |
101 | ||
102 | src[vects - 1][i] = parity; // last pointer is dest | |
103 | ||
104 | } | |
105 | ||
106 | return 0; | |
107 | } | |
108 | ||
109 | int xor_check_base(int vects, int len, void **array) | |
110 | { | |
111 | int i, j, fail = 0; | |
112 | ||
113 | unsigned char parity; | |
114 | unsigned char **src = (unsigned char **)array; | |
115 | ||
116 | for (i = 0; i < len; i++) { | |
117 | parity = 0; | |
118 | for (j = 0; j < vects; j++) | |
119 | parity ^= src[j][i]; | |
120 | ||
121 | if (parity != 0) { | |
122 | fail = 1; | |
123 | break; | |
124 | } | |
125 | } | |
126 | if (fail && len > 0) | |
127 | return len; | |
128 | return fail; | |
129 | } | |
130 | ||
131 | struct slver { | |
132 | unsigned short snum; | |
133 | unsigned char ver; | |
134 | unsigned char core; | |
135 | }; | |
136 | ||
137 | struct slver pq_gen_base_slver_0001012a; | |
138 | struct slver pq_gen_base_slver = { 0x012a, 0x01, 0x00 }; | |
139 | ||
140 | struct slver xor_gen_base_slver_0001012b; | |
141 | struct slver xor_gen_base_slver = { 0x012b, 0x01, 0x00 }; | |
142 | ||
143 | struct slver pq_check_base_slver_0001012c; | |
144 | struct slver pq_check_base_slver = { 0x012c, 0x01, 0x00 }; | |
145 | ||
146 | struct slver xor_check_base_slver_0001012d; | |
147 | struct slver xor_check_base_slver = { 0x012d, 0x01, 0x00 }; |