sha512_mb_mgr_datastruct.S 8.8 KB

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