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_
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)
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
150 _FIELD_OFFSET = (_FIELD_OFFSET + _STRUCT_ALIGN-1) & (~ (_STRUCT_ALIGN-1))
161 tmp = (_FIELD_OFFSET - ##tmp)
166 ## RES_int name size align
167 .macro RES_int p1 p2 p3
172 _FIELD_OFFSET = (_FIELD_OFFSET + (align) - 1) & (~ ((align)-1))
175 _FIELD_OFFSET = _FIELD_OFFSET + (size)
176 .if (align > _STRUCT_ALIGN)
177 _STRUCT_ALIGN = align
181 # macro RES_B name, size [, align]
182 .macro RES_B _name, _size, _align=1
183 RES_int _name _size _align
186 # macro RES_W name, size [, align]
187 .macro RES_W _name, _size, _align=2
188 RES_int _name 2*(_size) _align
191 # macro RES_D name, size [, align]
192 .macro RES_D _name, _size, _align=4
193 RES_int _name 4*(_size) _align
196 # macro RES_Q name, size [, align]
197 .macro RES_Q _name, _size, _align=8
198 RES_int _name 8*(_size) _align
201 # macro RES_DQ name, size [, align]
202 .macro RES_DQ _name, _size, _align=16
203 RES_int _name 16*(_size) _align
206 # macro RES_Y name, size [, align]
207 .macro RES_Y _name, _size, _align=32
208 RES_int _name 32*(_size) _align
211 # macro RES_Z name, size [, align]
212 .macro RES_Z _name, _size, _align=64
213 RES_int _name 64*(_size) _align
218 ###################################################################
219 ### Define SHA512 Out Of Order Data Structures
220 ###################################################################
222 START_FIELDS # LANE_DATA
224 FIELD _job_in_lane, 8, 8 # pointer to job object
227 _LANE_DATA_size = _FIELD_OFFSET
228 _LANE_DATA_align = _STRUCT_ALIGN
230 ####################################################################
232 START_FIELDS # SHA512_ARGS_X4
234 FIELD _digest, 8*8*4, 4 # transposed digest
235 FIELD _data_ptr, 8*4, 8 # array of pointers to data
238 _SHA512_ARGS_X4_size = _FIELD_OFFSET
239 _SHA512_ARGS_X4_align = _STRUCT_ALIGN
241 #####################################################################
243 START_FIELDS # MB_MGR
245 FIELD _args, _SHA512_ARGS_X4_size, _SHA512_ARGS_X4_align
247 FIELD _unused_lanes, 8, 8
248 FIELD _ldata, _LANE_DATA_size*4, _LANE_DATA_align
251 _MB_MGR_size = _FIELD_OFFSET
252 _MB_MGR_align = _STRUCT_ALIGN
254 _args_digest = _args + _digest
255 _args_data_ptr = _args + _data_ptr
257 #######################################################################
259 #######################################################################
260 #### Define constants
261 #######################################################################
263 #define STS_UNKNOWN 0
264 #define STS_BEING_PROCESSED 1
265 #define STS_COMPLETED 2
267 #######################################################################
268 #### Define JOB_SHA512 structure
269 #######################################################################
271 START_FIELDS # JOB_SHA512
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)
277 FIELD _user_data, 8, 8
280 _JOB_SHA512_size = _FIELD_OFFSET
281 _JOB_SHA512_align = _STRUCT_ALIGN