sha256_mb_mgr_datastruct.S 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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 SZ8 8*SHA256_DIGEST_WORD_SIZE
  117. #define ROUNDS 64*SZ8
  118. #define PTR_SZ 8
  119. #define SHA256_DIGEST_WORD_SIZE 4
  120. #define MAX_SHA256_LANES 8
  121. #define SHA256_DIGEST_WORDS 8
  122. #define SHA256_DIGEST_ROW_SIZE (MAX_SHA256_LANES * SHA256_DIGEST_WORD_SIZE)
  123. #define SHA256_DIGEST_SIZE (SHA256_DIGEST_ROW_SIZE * SHA256_DIGEST_WORDS)
  124. #define SHA256_BLK_SZ 64
  125. # START_FIELDS
  126. .macro START_FIELDS
  127. _FIELD_OFFSET = 0
  128. _STRUCT_ALIGN = 0
  129. .endm
  130. # FIELD name size align
  131. .macro FIELD name size align
  132. _FIELD_OFFSET = (_FIELD_OFFSET + (\align) - 1) & (~ ((\align)-1))
  133. \name = _FIELD_OFFSET
  134. _FIELD_OFFSET = _FIELD_OFFSET + (\size)
  135. .if (\align > _STRUCT_ALIGN)
  136. _STRUCT_ALIGN = \align
  137. .endif
  138. .endm
  139. # END_FIELDS
  140. .macro END_FIELDS
  141. _FIELD_OFFSET = (_FIELD_OFFSET + _STRUCT_ALIGN-1) & (~ (_STRUCT_ALIGN-1))
  142. .endm
  143. ########################################################################
  144. .macro STRUCT p1
  145. START_FIELDS
  146. .struc \p1
  147. .endm
  148. .macro ENDSTRUCT
  149. tmp = _FIELD_OFFSET
  150. END_FIELDS
  151. tmp = (_FIELD_OFFSET - %%tmp)
  152. .if (tmp > 0)
  153. .lcomm tmp
  154. .endif
  155. .endstruc
  156. .endm
  157. ## RES_int name size align
  158. .macro RES_int p1 p2 p3
  159. name = \p1
  160. size = \p2
  161. align = .\p3
  162. _FIELD_OFFSET = (_FIELD_OFFSET + (align) - 1) & (~ ((align)-1))
  163. .align align
  164. .lcomm name size
  165. _FIELD_OFFSET = _FIELD_OFFSET + (size)
  166. .if (align > _STRUCT_ALIGN)
  167. _STRUCT_ALIGN = align
  168. .endif
  169. .endm
  170. # macro RES_B name, size [, align]
  171. .macro RES_B _name, _size, _align=1
  172. RES_int _name _size _align
  173. .endm
  174. # macro RES_W name, size [, align]
  175. .macro RES_W _name, _size, _align=2
  176. RES_int _name 2*(_size) _align
  177. .endm
  178. # macro RES_D name, size [, align]
  179. .macro RES_D _name, _size, _align=4
  180. RES_int _name 4*(_size) _align
  181. .endm
  182. # macro RES_Q name, size [, align]
  183. .macro RES_Q _name, _size, _align=8
  184. RES_int _name 8*(_size) _align
  185. .endm
  186. # macro RES_DQ name, size [, align]
  187. .macro RES_DQ _name, _size, _align=16
  188. RES_int _name 16*(_size) _align
  189. .endm
  190. # macro RES_Y name, size [, align]
  191. .macro RES_Y _name, _size, _align=32
  192. RES_int _name 32*(_size) _align
  193. .endm
  194. # macro RES_Z name, size [, align]
  195. .macro RES_Z _name, _size, _align=64
  196. RES_int _name 64*(_size) _align
  197. .endm
  198. #endif
  199. ########################################################################
  200. #### Define SHA256 Out Of Order Data Structures
  201. ########################################################################
  202. START_FIELDS # LANE_DATA
  203. ### name size align
  204. FIELD _job_in_lane, 8, 8 # pointer to job object
  205. END_FIELDS
  206. _LANE_DATA_size = _FIELD_OFFSET
  207. _LANE_DATA_align = _STRUCT_ALIGN
  208. ########################################################################
  209. START_FIELDS # SHA256_ARGS_X4
  210. ### name size align
  211. FIELD _digest, 4*8*8, 4 # transposed digest
  212. FIELD _data_ptr, 8*8, 8 # array of pointers to data
  213. END_FIELDS
  214. _SHA256_ARGS_X4_size = _FIELD_OFFSET
  215. _SHA256_ARGS_X4_align = _STRUCT_ALIGN
  216. _SHA256_ARGS_X8_size = _FIELD_OFFSET
  217. _SHA256_ARGS_X8_align = _STRUCT_ALIGN
  218. #######################################################################
  219. START_FIELDS # MB_MGR
  220. ### name size align
  221. FIELD _args, _SHA256_ARGS_X4_size, _SHA256_ARGS_X4_align
  222. FIELD _lens, 4*8, 8
  223. FIELD _unused_lanes, 8, 8
  224. FIELD _ldata, _LANE_DATA_size*8, _LANE_DATA_align
  225. END_FIELDS
  226. _MB_MGR_size = _FIELD_OFFSET
  227. _MB_MGR_align = _STRUCT_ALIGN
  228. _args_digest = _args + _digest
  229. _args_data_ptr = _args + _data_ptr
  230. #######################################################################
  231. START_FIELDS #STACK_FRAME
  232. ### name size align
  233. FIELD _data, 16*SZ8, 1 # transposed digest
  234. FIELD _digest, 8*SZ8, 1 # array of pointers to data
  235. FIELD _ytmp, 4*SZ8, 1
  236. FIELD _rsp, 8, 1
  237. END_FIELDS
  238. _STACK_FRAME_size = _FIELD_OFFSET
  239. _STACK_FRAME_align = _STRUCT_ALIGN
  240. #######################################################################
  241. ########################################################################
  242. #### Define constants
  243. ########################################################################
  244. #define STS_UNKNOWN 0
  245. #define STS_BEING_PROCESSED 1
  246. #define STS_COMPLETED 2
  247. ########################################################################
  248. #### Define JOB_SHA256 structure
  249. ########################################################################
  250. START_FIELDS # JOB_SHA256
  251. ### name size align
  252. FIELD _buffer, 8, 8 # pointer to buffer
  253. FIELD _len, 8, 8 # length in bytes
  254. FIELD _result_digest, 8*4, 32 # Digest (output)
  255. FIELD _status, 4, 4
  256. FIELD _user_data, 8, 8
  257. END_FIELDS
  258. _JOB_SHA256_size = _FIELD_OFFSET
  259. _JOB_SHA256_align = _STRUCT_ALIGN