diff options
author | Tim Chen <tim.c.chen@linux.intel.com> | 2014-07-31 13:29:54 -0400 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2014-08-25 08:32:26 -0400 |
commit | 116177782392739f06868cfc2e6df5267aec4639 (patch) | |
tree | 837d0e08e706a269ab5841d9eaa302a487ee4247 /arch/x86/crypto | |
parent | 1e65b81a90df50bf450193065cc9073b706b8dda (diff) |
crypto: sha-mb - SHA1 multibuffer algorithm data structures
This patch introduces the data structures and prototypes of functions
needed for computing SHA1 hash using multi-buffer. Included are the
structures of the multi-buffer SHA1 job, job scheduler in C and x86
assembly.
Signed-off-by: Tim Chen <tim.c.chen@linux.intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'arch/x86/crypto')
-rw-r--r-- | arch/x86/crypto/sha-mb/sha1_mb_mgr_datastruct.S | 287 | ||||
-rw-r--r-- | arch/x86/crypto/sha-mb/sha_mb_ctx.h | 136 | ||||
-rw-r--r-- | arch/x86/crypto/sha-mb/sha_mb_mgr.h | 110 |
3 files changed, 533 insertions, 0 deletions
diff --git a/arch/x86/crypto/sha-mb/sha1_mb_mgr_datastruct.S b/arch/x86/crypto/sha-mb/sha1_mb_mgr_datastruct.S new file mode 100644 index 000000000000..86688c6e7a25 --- /dev/null +++ b/arch/x86/crypto/sha-mb/sha1_mb_mgr_datastruct.S | |||
@@ -0,0 +1,287 @@ | |||
1 | /* | ||
2 | * Header file for multi buffer SHA1 algorithm data structure | ||
3 | * | ||
4 | * This file is provided under a dual BSD/GPLv2 license. When using or | ||
5 | * redistributing this file, you may do so under either license. | ||
6 | * | ||
7 | * GPL LICENSE SUMMARY | ||
8 | * | ||
9 | * Copyright(c) 2014 Intel Corporation. | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or modify | ||
12 | * it under the terms of version 2 of the GNU General Public License as | ||
13 | * published by the Free Software Foundation. | ||
14 | * | ||
15 | * This program is distributed in the hope that it will be useful, but | ||
16 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
18 | * General Public License for more details. | ||
19 | * | ||
20 | * Contact Information: | ||
21 | * James Guilford <james.guilford@intel.com> | ||
22 | * Tim Chen <tim.c.chen@linux.intel.com> | ||
23 | * | ||
24 | * BSD LICENSE | ||
25 | * | ||
26 | * Copyright(c) 2014 Intel Corporation. | ||
27 | * | ||
28 | * Redistribution and use in source and binary forms, with or without | ||
29 | * modification, are permitted provided that the following conditions | ||
30 | * are met: | ||
31 | * | ||
32 | * * Redistributions of source code must retain the above copyright | ||
33 | * notice, this list of conditions and the following disclaimer. | ||
34 | * * Redistributions in binary form must reproduce the above copyright | ||
35 | * notice, this list of conditions and the following disclaimer in | ||
36 | * the documentation and/or other materials provided with the | ||
37 | * distribution. | ||
38 | * * Neither the name of Intel Corporation nor the names of its | ||
39 | * contributors may be used to endorse or promote products derived | ||
40 | * from this software without specific prior written permission. | ||
41 | * | ||
42 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
43 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
44 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
45 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
46 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
47 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
48 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
49 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
50 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
51 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
52 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
53 | */ | ||
54 | |||
55 | # Macros for defining data structures | ||
56 | |||
57 | # Usage example | ||
58 | |||
59 | #START_FIELDS # JOB_AES | ||
60 | ### name size align | ||
61 | #FIELD _plaintext, 8, 8 # pointer to plaintext | ||
62 | #FIELD _ciphertext, 8, 8 # pointer to ciphertext | ||
63 | #FIELD _IV, 16, 8 # IV | ||
64 | #FIELD _keys, 8, 8 # pointer to keys | ||
65 | #FIELD _len, 4, 4 # length in bytes | ||
66 | #FIELD _status, 4, 4 # status enumeration | ||
67 | #FIELD _user_data, 8, 8 # pointer to user data | ||
68 | #UNION _union, size1, align1, \ | ||
69 | # size2, align2, \ | ||
70 | # size3, align3, \ | ||
71 | # ... | ||
72 | #END_FIELDS | ||
73 | #%assign _JOB_AES_size _FIELD_OFFSET | ||
74 | #%assign _JOB_AES_align _STRUCT_ALIGN | ||
75 | |||
76 | ######################################################################### | ||
77 | |||
78 | # Alternate "struc-like" syntax: | ||
79 | # STRUCT job_aes2 | ||
80 | # RES_Q .plaintext, 1 | ||
81 | # RES_Q .ciphertext, 1 | ||
82 | # RES_DQ .IV, 1 | ||
83 | # RES_B .nested, _JOB_AES_SIZE, _JOB_AES_ALIGN | ||
84 | # RES_U .union, size1, align1, \ | ||
85 | # size2, align2, \ | ||
86 | # ... | ||
87 | # ENDSTRUCT | ||
88 | # # Following only needed if nesting | ||
89 | # %assign job_aes2_size _FIELD_OFFSET | ||
90 | # %assign job_aes2_align _STRUCT_ALIGN | ||
91 | # | ||
92 | # RES_* macros take a name, a count and an optional alignment. | ||
93 | # The count in in terms of the base size of the macro, and the | ||
94 | # default alignment is the base size. | ||
95 | # The macros are: | ||
96 | # Macro Base size | ||
97 | # RES_B 1 | ||
98 | # RES_W 2 | ||
99 | # RES_D 4 | ||
100 | # RES_Q 8 | ||
101 | # RES_DQ 16 | ||
102 | # RES_Y 32 | ||
103 | # RES_Z 64 | ||
104 | # | ||
105 | # RES_U defines a union. It's arguments are a name and two or more | ||
106 | # pairs of "size, alignment" | ||
107 | # | ||
108 | # The two assigns are only needed if this structure is being nested | ||
109 | # within another. Even if the assigns are not done, one can still use | ||
110 | # STRUCT_NAME_size as the size of the structure. | ||
111 | # | ||
112 | # Note that for nesting, you still need to assign to STRUCT_NAME_size. | ||
113 | # | ||
114 | # The differences between this and using "struc" directly are that each | ||
115 | # type is implicitly aligned to its natural length (although this can be | ||
116 | # over-ridden with an explicit third parameter), and that the structure | ||
117 | # is padded at the end to its overall alignment. | ||
118 | # | ||
119 | |||
120 | ######################################################################### | ||
121 | |||
122 | #ifndef _SHA1_MB_MGR_DATASTRUCT_ASM_ | ||
123 | #define _SHA1_MB_MGR_DATASTRUCT_ASM_ | ||
124 | |||
125 | ## START_FIELDS | ||
126 | .macro START_FIELDS | ||
127 | _FIELD_OFFSET = 0 | ||
128 | _STRUCT_ALIGN = 0 | ||
129 | .endm | ||
130 | |||
131 | ## FIELD name size align | ||
132 | .macro FIELD name size align | ||
133 | _FIELD_OFFSET = (_FIELD_OFFSET + (\align) - 1) & (~ ((\align)-1)) | ||
134 | \name = _FIELD_OFFSET | ||
135 | _FIELD_OFFSET = _FIELD_OFFSET + (\size) | ||
136 | .if (\align > _STRUCT_ALIGN) | ||
137 | _STRUCT_ALIGN = \align | ||
138 | .endif | ||
139 | .endm | ||
140 | |||
141 | ## END_FIELDS | ||
142 | .macro END_FIELDS | ||
143 | _FIELD_OFFSET = (_FIELD_OFFSET + _STRUCT_ALIGN-1) & (~ (_STRUCT_ALIGN-1)) | ||
144 | .endm | ||
145 | |||
146 | ######################################################################## | ||
147 | |||
148 | .macro STRUCT p1 | ||
149 | START_FIELDS | ||
150 | .struc \p1 | ||
151 | .endm | ||
152 | |||
153 | .macro ENDSTRUCT | ||
154 | tmp = _FIELD_OFFSET | ||
155 | END_FIELDS | ||
156 | tmp = (_FIELD_OFFSET - %%tmp) | ||
157 | .if (tmp > 0) | ||
158 | .lcomm tmp | ||
159 | .endif | ||
160 | .endstruc | ||
161 | .endm | ||
162 | |||
163 | ## RES_int name size align | ||
164 | .macro RES_int p1 p2 p3 | ||
165 | name = \p1 | ||
166 | size = \p2 | ||
167 | align = .\p3 | ||
168 | |||
169 | _FIELD_OFFSET = (_FIELD_OFFSET + (align) - 1) & (~ ((align)-1)) | ||
170 | .align align | ||
171 | .lcomm name size | ||
172 | _FIELD_OFFSET = _FIELD_OFFSET + (size) | ||
173 | .if (align > _STRUCT_ALIGN) | ||
174 | _STRUCT_ALIGN = align | ||
175 | .endif | ||
176 | .endm | ||
177 | |||
178 | |||
179 | |||
180 | # macro RES_B name, size [, align] | ||
181 | .macro RES_B _name, _size, _align=1 | ||
182 | RES_int _name _size _align | ||
183 | .endm | ||
184 | |||
185 | # macro RES_W name, size [, align] | ||
186 | .macro RES_W _name, _size, _align=2 | ||
187 | RES_int _name 2*(_size) _align | ||
188 | .endm | ||
189 | |||
190 | # macro RES_D name, size [, align] | ||
191 | .macro RES_D _name, _size, _align=4 | ||
192 | RES_int _name 4*(_size) _align | ||
193 | .endm | ||
194 | |||
195 | # macro RES_Q name, size [, align] | ||
196 | .macro RES_Q _name, _size, _align=8 | ||
197 | RES_int _name 8*(_size) _align | ||
198 | .endm | ||
199 | |||
200 | # macro RES_DQ name, size [, align] | ||
201 | .macro RES_DQ _name, _size, _align=16 | ||
202 | RES_int _name 16*(_size) _align | ||
203 | .endm | ||
204 | |||
205 | # macro RES_Y name, size [, align] | ||
206 | .macro RES_Y _name, _size, _align=32 | ||
207 | RES_int _name 32*(_size) _align | ||
208 | .endm | ||
209 | |||
210 | # macro RES_Z name, size [, align] | ||
211 | .macro RES_Z _name, _size, _align=64 | ||
212 | RES_int _name 64*(_size) _align | ||
213 | .endm | ||
214 | |||
215 | |||
216 | #endif | ||
217 | |||
218 | ######################################################################## | ||
219 | #### Define constants | ||
220 | ######################################################################## | ||
221 | |||
222 | ######################################################################## | ||
223 | #### Define SHA1 Out Of Order Data Structures | ||
224 | ######################################################################## | ||
225 | |||
226 | START_FIELDS # LANE_DATA | ||
227 | ### name size align | ||
228 | FIELD _job_in_lane, 8, 8 # pointer to job object | ||
229 | END_FIELDS | ||
230 | |||
231 | _LANE_DATA_size = _FIELD_OFFSET | ||
232 | _LANE_DATA_align = _STRUCT_ALIGN | ||
233 | |||
234 | ######################################################################## | ||
235 | |||
236 | START_FIELDS # SHA1_ARGS_X8 | ||
237 | ### name size align | ||
238 | FIELD _digest, 4*5*8, 16 # transposed digest | ||
239 | FIELD _data_ptr, 8*8, 8 # array of pointers to data | ||
240 | END_FIELDS | ||
241 | |||
242 | _SHA1_ARGS_X4_size = _FIELD_OFFSET | ||
243 | _SHA1_ARGS_X4_align = _STRUCT_ALIGN | ||
244 | _SHA1_ARGS_X8_size = _FIELD_OFFSET | ||
245 | _SHA1_ARGS_X8_align = _STRUCT_ALIGN | ||
246 | |||
247 | ######################################################################## | ||
248 | |||
249 | START_FIELDS # MB_MGR | ||
250 | ### name size align | ||
251 | FIELD _args, _SHA1_ARGS_X4_size, _SHA1_ARGS_X4_align | ||
252 | FIELD _lens, 4*8, 8 | ||
253 | FIELD _unused_lanes, 8, 8 | ||
254 | FIELD _ldata, _LANE_DATA_size*8, _LANE_DATA_align | ||
255 | END_FIELDS | ||
256 | |||
257 | _MB_MGR_size = _FIELD_OFFSET | ||
258 | _MB_MGR_align = _STRUCT_ALIGN | ||
259 | |||
260 | _args_digest = _args + _digest | ||
261 | _args_data_ptr = _args + _data_ptr | ||
262 | |||
263 | |||
264 | ######################################################################## | ||
265 | #### Define constants | ||
266 | ######################################################################## | ||
267 | |||
268 | #define STS_UNKNOWN 0 | ||
269 | #define STS_BEING_PROCESSED 1 | ||
270 | #define STS_COMPLETED 2 | ||
271 | |||
272 | ######################################################################## | ||
273 | #### Define JOB_SHA1 structure | ||
274 | ######################################################################## | ||
275 | |||
276 | START_FIELDS # JOB_SHA1 | ||
277 | |||
278 | ### name size align | ||
279 | FIELD _buffer, 8, 8 # pointer to buffer | ||
280 | FIELD _len, 4, 4 # length in bytes | ||
281 | FIELD _result_digest, 5*4, 32 # Digest (output) | ||
282 | FIELD _status, 4, 4 | ||
283 | FIELD _user_data, 8, 8 | ||
284 | END_FIELDS | ||
285 | |||
286 | _JOB_SHA1_size = _FIELD_OFFSET | ||
287 | _JOB_SHA1_align = _STRUCT_ALIGN | ||
diff --git a/arch/x86/crypto/sha-mb/sha_mb_ctx.h b/arch/x86/crypto/sha-mb/sha_mb_ctx.h new file mode 100644 index 000000000000..e36069d0c1bd --- /dev/null +++ b/arch/x86/crypto/sha-mb/sha_mb_ctx.h | |||
@@ -0,0 +1,136 @@ | |||
1 | /* | ||
2 | * Header file for multi buffer SHA context | ||
3 | * | ||
4 | * This file is provided under a dual BSD/GPLv2 license. When using or | ||
5 | * redistributing this file, you may do so under either license. | ||
6 | * | ||
7 | * GPL LICENSE SUMMARY | ||
8 | * | ||
9 | * Copyright(c) 2014 Intel Corporation. | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or modify | ||
12 | * it under the terms of version 2 of the GNU General Public License as | ||
13 | * published by the Free Software Foundation. | ||
14 | * | ||
15 | * This program is distributed in the hope that it will be useful, but | ||
16 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
18 | * General Public License for more details. | ||
19 | * | ||
20 | * Contact Information: | ||
21 | * Tim Chen <tim.c.chen@linux.intel.com> | ||
22 | * | ||
23 | * BSD LICENSE | ||
24 | * | ||
25 | * Copyright(c) 2014 Intel Corporation. | ||
26 | * | ||
27 | * Redistribution and use in source and binary forms, with or without | ||
28 | * modification, are permitted provided that the following conditions | ||
29 | * are met: | ||
30 | * | ||
31 | * * Redistributions of source code must retain the above copyright | ||
32 | * notice, this list of conditions and the following disclaimer. | ||
33 | * * Redistributions in binary form must reproduce the above copyright | ||
34 | * notice, this list of conditions and the following disclaimer in | ||
35 | * the documentation and/or other materials provided with the | ||
36 | * distribution. | ||
37 | * * Neither the name of Intel Corporation nor the names of its | ||
38 | * contributors may be used to endorse or promote products derived | ||
39 | * from this software without specific prior written permission. | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
42 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
43 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
44 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
45 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
46 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
47 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
48 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
49 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
50 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
51 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
52 | */ | ||
53 | |||
54 | #ifndef _SHA_MB_CTX_INTERNAL_H | ||
55 | #define _SHA_MB_CTX_INTERNAL_H | ||
56 | |||
57 | #include "sha_mb_mgr.h" | ||
58 | |||
59 | #define HASH_UPDATE 0x00 | ||
60 | #define HASH_FIRST 0x01 | ||
61 | #define HASH_LAST 0x02 | ||
62 | #define HASH_ENTIRE 0x03 | ||
63 | #define HASH_DONE 0x04 | ||
64 | #define HASH_FINAL 0x08 | ||
65 | |||
66 | #define HASH_CTX_STS_IDLE 0x00 | ||
67 | #define HASH_CTX_STS_PROCESSING 0x01 | ||
68 | #define HASH_CTX_STS_LAST 0x02 | ||
69 | #define HASH_CTX_STS_COMPLETE 0x04 | ||
70 | |||
71 | enum hash_ctx_error { | ||
72 | HASH_CTX_ERROR_NONE = 0, | ||
73 | HASH_CTX_ERROR_INVALID_FLAGS = -1, | ||
74 | HASH_CTX_ERROR_ALREADY_PROCESSING = -2, | ||
75 | HASH_CTX_ERROR_ALREADY_COMPLETED = -3, | ||
76 | |||
77 | #ifdef HASH_CTX_DEBUG | ||
78 | HASH_CTX_ERROR_DEBUG_DIGEST_MISMATCH = -4, | ||
79 | #endif | ||
80 | }; | ||
81 | |||
82 | |||
83 | #define hash_ctx_user_data(ctx) ((ctx)->user_data) | ||
84 | #define hash_ctx_digest(ctx) ((ctx)->job.result_digest) | ||
85 | #define hash_ctx_processing(ctx) ((ctx)->status & HASH_CTX_STS_PROCESSING) | ||
86 | #define hash_ctx_complete(ctx) ((ctx)->status == HASH_CTX_STS_COMPLETE) | ||
87 | #define hash_ctx_status(ctx) ((ctx)->status) | ||
88 | #define hash_ctx_error(ctx) ((ctx)->error) | ||
89 | #define hash_ctx_init(ctx) \ | ||
90 | do { \ | ||
91 | (ctx)->error = HASH_CTX_ERROR_NONE; \ | ||
92 | (ctx)->status = HASH_CTX_STS_COMPLETE; \ | ||
93 | } while (0) | ||
94 | |||
95 | |||
96 | /* Hash Constants and Typedefs */ | ||
97 | #define SHA1_DIGEST_LENGTH 5 | ||
98 | #define SHA1_LOG2_BLOCK_SIZE 6 | ||
99 | |||
100 | #define SHA1_PADLENGTHFIELD_SIZE 8 | ||
101 | |||
102 | #ifdef SHA_MB_DEBUG | ||
103 | #define assert(expr) \ | ||
104 | do { \ | ||
105 | if (unlikely(!(expr))) { \ | ||
106 | printk(KERN_ERR "Assertion failed! %s,%s,%s,line=%d\n", \ | ||
107 | #expr, __FILE__, __func__, __LINE__); \ | ||
108 | } \ | ||
109 | } while (0) | ||
110 | #else | ||
111 | #define assert(expr) do {} while (0) | ||
112 | #endif | ||
113 | |||
114 | struct sha1_ctx_mgr { | ||
115 | struct sha1_mb_mgr mgr; | ||
116 | }; | ||
117 | |||
118 | /* typedef struct sha1_ctx_mgr sha1_ctx_mgr; */ | ||
119 | |||
120 | struct sha1_hash_ctx { | ||
121 | /* Must be at struct offset 0 */ | ||
122 | struct job_sha1 job; | ||
123 | /* status flag */ | ||
124 | int status; | ||
125 | /* error flag */ | ||
126 | int error; | ||
127 | |||
128 | uint32_t total_length; | ||
129 | const void *incoming_buffer; | ||
130 | uint32_t incoming_buffer_length; | ||
131 | uint8_t partial_block_buffer[SHA1_BLOCK_SIZE * 2]; | ||
132 | uint32_t partial_block_buffer_length; | ||
133 | void *user_data; | ||
134 | }; | ||
135 | |||
136 | #endif | ||
diff --git a/arch/x86/crypto/sha-mb/sha_mb_mgr.h b/arch/x86/crypto/sha-mb/sha_mb_mgr.h new file mode 100644 index 000000000000..08ad1a9acfd7 --- /dev/null +++ b/arch/x86/crypto/sha-mb/sha_mb_mgr.h | |||
@@ -0,0 +1,110 @@ | |||
1 | /* | ||
2 | * Header file for multi buffer SHA1 algorithm manager | ||
3 | * | ||
4 | * This file is provided under a dual BSD/GPLv2 license. When using or | ||
5 | * redistributing this file, you may do so under either license. | ||
6 | * | ||
7 | * GPL LICENSE SUMMARY | ||
8 | * | ||
9 | * Copyright(c) 2014 Intel Corporation. | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or modify | ||
12 | * it under the terms of version 2 of the GNU General Public License as | ||
13 | * published by the Free Software Foundation. | ||
14 | * | ||
15 | * This program is distributed in the hope that it will be useful, but | ||
16 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
18 | * General Public License for more details. | ||
19 | * | ||
20 | * Contact Information: | ||
21 | * James Guilford <james.guilford@intel.com> | ||
22 | * Tim Chen <tim.c.chen@linux.intel.com> | ||
23 | * | ||
24 | * BSD LICENSE | ||
25 | * | ||
26 | * Copyright(c) 2014 Intel Corporation. | ||
27 | * | ||
28 | * Redistribution and use in source and binary forms, with or without | ||
29 | * modification, are permitted provided that the following conditions | ||
30 | * are met: | ||
31 | * | ||
32 | * * Redistributions of source code must retain the above copyright | ||
33 | * notice, this list of conditions and the following disclaimer. | ||
34 | * * Redistributions in binary form must reproduce the above copyright | ||
35 | * notice, this list of conditions and the following disclaimer in | ||
36 | * the documentation and/or other materials provided with the | ||
37 | * distribution. | ||
38 | * * Neither the name of Intel Corporation nor the names of its | ||
39 | * contributors may be used to endorse or promote products derived | ||
40 | * from this software without specific prior written permission. | ||
41 | * | ||
42 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
43 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
44 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
45 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
46 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
47 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
48 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
49 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
50 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
51 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
52 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
53 | */ | ||
54 | #ifndef __SHA_MB_MGR_H | ||
55 | #define __SHA_MB_MGR_H | ||
56 | |||
57 | |||
58 | #include <linux/types.h> | ||
59 | |||
60 | #define NUM_SHA1_DIGEST_WORDS 5 | ||
61 | |||
62 | enum job_sts { STS_UNKNOWN = 0, | ||
63 | STS_BEING_PROCESSED = 1, | ||
64 | STS_COMPLETED = 2, | ||
65 | STS_INTERNAL_ERROR = 3, | ||
66 | STS_ERROR = 4 | ||
67 | }; | ||
68 | |||
69 | struct job_sha1 { | ||
70 | u8 *buffer; | ||
71 | u32 len; | ||
72 | u32 result_digest[NUM_SHA1_DIGEST_WORDS] __aligned(32); | ||
73 | enum job_sts status; | ||
74 | void *user_data; | ||
75 | }; | ||
76 | |||
77 | /* SHA1 out-of-order scheduler */ | ||
78 | |||
79 | /* typedef uint32_t sha1_digest_array[5][8]; */ | ||
80 | |||
81 | struct sha1_args_x8 { | ||
82 | uint32_t digest[5][8]; | ||
83 | uint8_t *data_ptr[8]; | ||
84 | }; | ||
85 | |||
86 | struct sha1_lane_data { | ||
87 | struct job_sha1 *job_in_lane; | ||
88 | }; | ||
89 | |||
90 | struct sha1_mb_mgr { | ||
91 | struct sha1_args_x8 args; | ||
92 | |||
93 | uint32_t lens[8]; | ||
94 | |||
95 | /* each byte is index (0...7) of unused lanes */ | ||
96 | uint64_t unused_lanes; | ||
97 | /* byte 4 is set to FF as a flag */ | ||
98 | struct sha1_lane_data ldata[8]; | ||
99 | }; | ||
100 | |||
101 | |||
102 | #define SHA1_MB_MGR_NUM_LANES_AVX2 8 | ||
103 | |||
104 | void sha1_mb_mgr_init_avx2(struct sha1_mb_mgr *state); | ||
105 | struct job_sha1 *sha1_mb_mgr_submit_avx2(struct sha1_mb_mgr *state, | ||
106 | struct job_sha1 *job); | ||
107 | struct job_sha1 *sha1_mb_mgr_flush_avx2(struct sha1_mb_mgr *state); | ||
108 | struct job_sha1 *sha1_mb_mgr_get_comp_job_avx2(struct sha1_mb_mgr *state); | ||
109 | |||
110 | #endif | ||