2 * Header file for multi buffer SHA256 algorithm data structure
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.
9 * Copyright(c) 2016 Intel Corporation.
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.
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.
20 * Contact Information:
21 * Megha Dey <megha.dey@linux.intel.com>
25 * Copyright(c) 2016 Intel Corporation.
27 * Redistribution and use in source and binary forms, with or without
28 * modification, are permitted provided that the following conditions
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
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.
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.
54 # Macros for defining data structures
58 #START_FIELDS # JOB_AES
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, \
72 #%assign _JOB_AES_size _FIELD_OFFSET
73 #%assign _JOB_AES_align _STRUCT_ALIGN
75 #########################################################################
77 # Alternate "struc-like" syntax:
80 # RES_Q .ciphertext, 1
82 # RES_B .nested, _JOB_AES_SIZE, _JOB_AES_ALIGN
83 # RES_U .union, size1, align1, \
87 # # Following only needed if nesting
88 # %assign job_aes2_size _FIELD_OFFSET
89 # %assign job_aes2_align _STRUCT_ALIGN
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.
104 # RES_U defines a union. It's arguments are a name and two or more
105 # pairs of "size, alignment"
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.
111 # Note that for nesting, you still need to assign to STRUCT_NAME_size.
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.
119 #########################################################################
121 #ifndef _DATASTRUCT_ASM_
122 #define _DATASTRUCT_ASM_
124 #define SZ8 8*SHA256_DIGEST_WORD_SIZE
125 #define ROUNDS 64*SZ8
127 #define SHA256_DIGEST_WORD_SIZE 4
128 #define MAX_SHA256_LANES 8
129 #define SHA256_DIGEST_WORDS 8
130 #define SHA256_DIGEST_ROW_SIZE (MAX_SHA256_LANES * SHA256_DIGEST_WORD_SIZE)
131 #define SHA256_DIGEST_SIZE (SHA256_DIGEST_ROW_SIZE * SHA256_DIGEST_WORDS)
132 #define SHA256_BLK_SZ 64
140 # FIELD name size align
141 .macro FIELD name size align
142 _FIELD_OFFSET = (_FIELD_OFFSET + (\align) - 1) & (~ ((\align)-1))
143 \name = _FIELD_OFFSET
144 _FIELD_OFFSET = _FIELD_OFFSET + (\size)
145 .if (\align > _STRUCT_ALIGN)
146 _STRUCT_ALIGN = \align
152 _FIELD_OFFSET = (_FIELD_OFFSET + _STRUCT_ALIGN-1) & (~ (_STRUCT_ALIGN-1))
155 ########################################################################
165 tmp = (_FIELD_OFFSET - %%tmp)
172 ## RES_int name size align
173 .macro RES_int p1 p2 p3
178 _FIELD_OFFSET = (_FIELD_OFFSET + (align) - 1) & (~ ((align)-1))
181 _FIELD_OFFSET = _FIELD_OFFSET + (size)
182 .if (align > _STRUCT_ALIGN)
183 _STRUCT_ALIGN = align
187 # macro RES_B name, size [, align]
188 .macro RES_B _name, _size, _align=1
189 RES_int _name _size _align
192 # macro RES_W name, size [, align]
193 .macro RES_W _name, _size, _align=2
194 RES_int _name 2*(_size) _align
197 # macro RES_D name, size [, align]
198 .macro RES_D _name, _size, _align=4
199 RES_int _name 4*(_size) _align
202 # macro RES_Q name, size [, align]
203 .macro RES_Q _name, _size, _align=8
204 RES_int _name 8*(_size) _align
207 # macro RES_DQ name, size [, align]
208 .macro RES_DQ _name, _size, _align=16
209 RES_int _name 16*(_size) _align
212 # macro RES_Y name, size [, align]
213 .macro RES_Y _name, _size, _align=32
214 RES_int _name 32*(_size) _align
217 # macro RES_Z name, size [, align]
218 .macro RES_Z _name, _size, _align=64
219 RES_int _name 64*(_size) _align
225 ########################################################################
226 #### Define SHA256 Out Of Order Data Structures
227 ########################################################################
229 START_FIELDS # LANE_DATA
231 FIELD _job_in_lane, 8, 8 # pointer to job object
234 _LANE_DATA_size = _FIELD_OFFSET
235 _LANE_DATA_align = _STRUCT_ALIGN
237 ########################################################################
239 START_FIELDS # SHA256_ARGS_X4
241 FIELD _digest, 4*8*8, 4 # transposed digest
242 FIELD _data_ptr, 8*8, 8 # array of pointers to data
245 _SHA256_ARGS_X4_size = _FIELD_OFFSET
246 _SHA256_ARGS_X4_align = _STRUCT_ALIGN
247 _SHA256_ARGS_X8_size = _FIELD_OFFSET
248 _SHA256_ARGS_X8_align = _STRUCT_ALIGN
250 #######################################################################
252 START_FIELDS # MB_MGR
254 FIELD _args, _SHA256_ARGS_X4_size, _SHA256_ARGS_X4_align
256 FIELD _unused_lanes, 8, 8
257 FIELD _ldata, _LANE_DATA_size*8, _LANE_DATA_align
260 _MB_MGR_size = _FIELD_OFFSET
261 _MB_MGR_align = _STRUCT_ALIGN
263 _args_digest = _args + _digest
264 _args_data_ptr = _args + _data_ptr
266 #######################################################################
268 START_FIELDS #STACK_FRAME
270 FIELD _data, 16*SZ8, 1 # transposed digest
271 FIELD _digest, 8*SZ8, 1 # array of pointers to data
272 FIELD _ytmp, 4*SZ8, 1
276 _STACK_FRAME_size = _FIELD_OFFSET
277 _STACK_FRAME_align = _STRUCT_ALIGN
279 #######################################################################
281 ########################################################################
282 #### Define constants
283 ########################################################################
285 #define STS_UNKNOWN 0
286 #define STS_BEING_PROCESSED 1
287 #define STS_COMPLETED 2
289 ########################################################################
290 #### Define JOB_SHA256 structure
291 ########################################################################
293 START_FIELDS # JOB_SHA256
296 FIELD _buffer, 8, 8 # pointer to buffer
297 FIELD _len, 8, 8 # length in bytes
298 FIELD _result_digest, 8*4, 32 # Digest (output)
300 FIELD _user_data, 8, 8
303 _JOB_SHA256_size = _FIELD_OFFSET
304 _JOB_SHA256_align = _STRUCT_ALIGN