]>
Commit | Line | Data |
---|---|---|
2cdacb68 MD |
1 | /* |
2 | * Header file for multi buffer SHA256 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) 2016 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 | * Megha Dey <megha.dey@linux.intel.com> | |
22 | * | |
23 | * BSD LICENSE | |
24 | * | |
25 | * Copyright(c) 2016 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 | # Macros for defining data structures | |
55 | ||
56 | # Usage example | |
57 | ||
58 | #START_FIELDS # JOB_AES | |
59 | ### name size align | |
60 | #FIELD _plaintext, 8, 8 # pointer to plaintext | |
61 | #FIELD _ciphertext, 8, 8 # pointer to ciphertext | |
62 | #FIELD _IV, 16, 8 # IV | |
63 | #FIELD _keys, 8, 8 # pointer to keys | |
64 | #FIELD _len, 4, 4 # length in bytes | |
65 | #FIELD _status, 4, 4 # status enumeration | |
66 | #FIELD _user_data, 8, 8 # pointer to user data | |
67 | #UNION _union, size1, align1, \ | |
68 | # size2, align2, \ | |
69 | # size3, align3, \ | |
70 | # ... | |
71 | #END_FIELDS | |
72 | #%assign _JOB_AES_size _FIELD_OFFSET | |
73 | #%assign _JOB_AES_align _STRUCT_ALIGN | |
74 | ||
75 | ######################################################################### | |
76 | ||
77 | # Alternate "struc-like" syntax: | |
78 | # STRUCT job_aes2 | |
79 | # RES_Q .plaintext, 1 | |
80 | # RES_Q .ciphertext, 1 | |
81 | # RES_DQ .IV, 1 | |
82 | # RES_B .nested, _JOB_AES_SIZE, _JOB_AES_ALIGN | |
83 | # RES_U .union, size1, align1, \ | |
84 | # size2, align2, \ | |
85 | # ... | |
86 | # ENDSTRUCT | |
87 | # # Following only needed if nesting | |
88 | # %assign job_aes2_size _FIELD_OFFSET | |
89 | # %assign job_aes2_align _STRUCT_ALIGN | |
90 | # | |
91 | # RES_* macros take a name, a count and an optional alignment. | |
92 | # The count in in terms of the base size of the macro, and the | |
93 | # default alignment is the base size. | |
94 | # The macros are: | |
95 | # Macro Base size | |
96 | # RES_B 1 | |
97 | # RES_W 2 | |
98 | # RES_D 4 | |
99 | # RES_Q 8 | |
100 | # RES_DQ 16 | |
101 | # RES_Y 32 | |
102 | # RES_Z 64 | |
103 | # | |
104 | # RES_U defines a union. It's arguments are a name and two or more | |
105 | # pairs of "size, alignment" | |
106 | # | |
107 | # The two assigns are only needed if this structure is being nested | |
108 | # within another. Even if the assigns are not done, one can still use | |
109 | # STRUCT_NAME_size as the size of the structure. | |
110 | # | |
111 | # Note that for nesting, you still need to assign to STRUCT_NAME_size. | |
112 | # | |
113 | # The differences between this and using "struc" directly are that each | |
114 | # type is implicitly aligned to its natural length (although this can be | |
115 | # over-ridden with an explicit third parameter), and that the structure | |
116 | # is padded at the end to its overall alignment. | |
117 | # | |
118 | ||
119 | ######################################################################### | |
120 | ||
121 | #ifndef _DATASTRUCT_ASM_ | |
122 | #define _DATASTRUCT_ASM_ | |
123 | ||
124 | #define PTR_SZ 8 | |
125 | #define SHA512_DIGEST_WORD_SIZE 8 | |
126 | #define SHA512_MB_MGR_NUM_LANES_AVX2 4 | |
127 | #define NUM_SHA512_DIGEST_WORDS 8 | |
128 | #define SZ4 4*SHA512_DIGEST_WORD_SIZE | |
129 | #define ROUNDS 80*SZ4 | |
130 | #define SHA512_DIGEST_ROW_SIZE (SHA512_MB_MGR_NUM_LANES_AVX2 * 8) | |
131 | ||
132 | # START_FIELDS | |
133 | .macro START_FIELDS | |
134 | _FIELD_OFFSET = 0 | |
135 | _STRUCT_ALIGN = 0 | |
136 | .endm | |
137 | ||
138 | # FIELD name size align | |
139 | .macro FIELD name size align | |
140 | _FIELD_OFFSET = (_FIELD_OFFSET + (\align) - 1) & (~ ((\align)-1)) | |
141 | \name = _FIELD_OFFSET | |
142 | _FIELD_OFFSET = _FIELD_OFFSET + (\size) | |
143 | .if (\align > _STRUCT_ALIGN) | |
144 | _STRUCT_ALIGN = \align | |
145 | .endif | |
146 | .endm | |
147 | ||
148 | # END_FIELDS | |
149 | .macro END_FIELDS | |
150 | _FIELD_OFFSET = (_FIELD_OFFSET + _STRUCT_ALIGN-1) & (~ (_STRUCT_ALIGN-1)) | |
151 | .endm | |
152 | ||
153 | .macro STRUCT p1 | |
154 | START_FIELDS | |
155 | .struc \p1 | |
156 | .endm | |
157 | ||
158 | .macro ENDSTRUCT | |
159 | tmp = _FIELD_OFFSET | |
160 | END_FIELDS | |
161 | tmp = (_FIELD_OFFSET - ##tmp) | |
162 | .if (tmp > 0) | |
163 | .lcomm tmp | |
164 | .endm | |
165 | ||
166 | ## RES_int name size align | |
167 | .macro RES_int p1 p2 p3 | |
168 | name = \p1 | |
169 | size = \p2 | |
170 | align = .\p3 | |
171 | ||
172 | _FIELD_OFFSET = (_FIELD_OFFSET + (align) - 1) & (~ ((align)-1)) | |
173 | .align align | |
174 | .lcomm name size | |
175 | _FIELD_OFFSET = _FIELD_OFFSET + (size) | |
176 | .if (align > _STRUCT_ALIGN) | |
177 | _STRUCT_ALIGN = align | |
178 | .endif | |
179 | .endm | |
180 | ||
181 | # macro RES_B name, size [, align] | |
182 | .macro RES_B _name, _size, _align=1 | |
183 | RES_int _name _size _align | |
184 | .endm | |
185 | ||
186 | # macro RES_W name, size [, align] | |
187 | .macro RES_W _name, _size, _align=2 | |
188 | RES_int _name 2*(_size) _align | |
189 | .endm | |
190 | ||
191 | # macro RES_D name, size [, align] | |
192 | .macro RES_D _name, _size, _align=4 | |
193 | RES_int _name 4*(_size) _align | |
194 | .endm | |
195 | ||
196 | # macro RES_Q name, size [, align] | |
197 | .macro RES_Q _name, _size, _align=8 | |
198 | RES_int _name 8*(_size) _align | |
199 | .endm | |
200 | ||
201 | # macro RES_DQ name, size [, align] | |
202 | .macro RES_DQ _name, _size, _align=16 | |
203 | RES_int _name 16*(_size) _align | |
204 | .endm | |
205 | ||
206 | # macro RES_Y name, size [, align] | |
207 | .macro RES_Y _name, _size, _align=32 | |
208 | RES_int _name 32*(_size) _align | |
209 | .endm | |
210 | ||
211 | # macro RES_Z name, size [, align] | |
212 | .macro RES_Z _name, _size, _align=64 | |
213 | RES_int _name 64*(_size) _align | |
214 | .endm | |
215 | ||
216 | #endif | |
217 | ||
218 | ################################################################### | |
219 | ### Define SHA512 Out Of Order Data Structures | |
220 | ################################################################### | |
221 | ||
222 | START_FIELDS # LANE_DATA | |
223 | ### name size align | |
224 | FIELD _job_in_lane, 8, 8 # pointer to job object | |
225 | END_FIELDS | |
226 | ||
227 | _LANE_DATA_size = _FIELD_OFFSET | |
228 | _LANE_DATA_align = _STRUCT_ALIGN | |
229 | ||
230 | #################################################################### | |
231 | ||
232 | START_FIELDS # SHA512_ARGS_X4 | |
233 | ### name size align | |
234 | FIELD _digest, 8*8*4, 4 # transposed digest | |
235 | FIELD _data_ptr, 8*4, 8 # array of pointers to data | |
236 | END_FIELDS | |
237 | ||
238 | _SHA512_ARGS_X4_size = _FIELD_OFFSET | |
239 | _SHA512_ARGS_X4_align = _STRUCT_ALIGN | |
240 | ||
241 | ##################################################################### | |
242 | ||
243 | START_FIELDS # MB_MGR | |
244 | ### name size align | |
245 | FIELD _args, _SHA512_ARGS_X4_size, _SHA512_ARGS_X4_align | |
246 | FIELD _lens, 8*4, 8 | |
247 | FIELD _unused_lanes, 8, 8 | |
248 | FIELD _ldata, _LANE_DATA_size*4, _LANE_DATA_align | |
249 | END_FIELDS | |
250 | ||
251 | _MB_MGR_size = _FIELD_OFFSET | |
252 | _MB_MGR_align = _STRUCT_ALIGN | |
253 | ||
254 | _args_digest = _args + _digest | |
255 | _args_data_ptr = _args + _data_ptr | |
256 | ||
257 | ####################################################################### | |
258 | ||
259 | ####################################################################### | |
260 | #### Define constants | |
261 | ####################################################################### | |
262 | ||
263 | #define STS_UNKNOWN 0 | |
264 | #define STS_BEING_PROCESSED 1 | |
265 | #define STS_COMPLETED 2 | |
266 | ||
267 | ####################################################################### | |
268 | #### Define JOB_SHA512 structure | |
269 | ####################################################################### | |
270 | ||
271 | START_FIELDS # JOB_SHA512 | |
272 | ### name size align | |
273 | FIELD _buffer, 8, 8 # pointer to buffer | |
274 | FIELD _len, 8, 8 # length in bytes | |
275 | FIELD _result_digest, 8*8, 32 # Digest (output) | |
276 | FIELD _status, 4, 4 | |
277 | FIELD _user_data, 8, 8 | |
278 | END_FIELDS | |
279 | ||
280 | _JOB_SHA512_size = _FIELD_OFFSET | |
281 | _JOB_SHA512_align = _STRUCT_ALIGN |