xref: /isa-l_crypto/include/sha512_mb_internal.h (revision 371c22bef8122d95ed1edbb3e0c50661f6d8f897)
1 /**********************************************************************
2   Copyright(c) 2024 Intel Corporation All rights reserved.
3 
4   Redistribution and use in source and binary forms, with or without
5   modification, are permitted provided that the following conditions
6   are met:
7     * Redistributions of source code must retain the above copyright
8       notice, this list of conditions and the following disclaimer.
9     * Redistributions in binary form must reproduce the above copyright
10       notice, this list of conditions and the following disclaimer in
11       the documentation and/or other materials provided with the
12       distribution.
13     * Neither the name of Intel Corporation nor the names of its
14       contributors may be used to endorse or promote products derived
15       from this software without specific prior written permission.
16 
17   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 **********************************************************************/
29 
30 #ifndef _SHA512_MB_INTERNAL_H_
31 #define _SHA512_MB_INTERNAL_H_
32 
33 /**
34  *  @file sha512_mb_internal.h
35  *  @brief Multi-buffer CTX API function prototypes and structures
36  *
37  */
38 
39 #include <stdint.h>
40 #include <string.h>
41 
42 #include "sha512_mb.h"
43 #include "multi_buffer.h"
44 #include "types.h"
45 
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49 
50 #define ISAL_SHA512_X4_LANES        4
51 #define ISAL_SHA512_LOG2_BLOCK_SIZE 7
52 #define ISAL_SHA512_INITIAL_DIGEST                                                                 \
53         0x6a09e667f3bcc908, 0xbb67ae8584caa73b, 0x3c6ef372fe94f82b, 0xa54ff53a5f1d36f1,            \
54                 0x510e527fade682d1, 0x9b05688c2b3e6c1f, 0x1f83d9abfb41bd6b, 0x5be0cd19137e2179
55 
56 /**
57  * @brief Initialize the SHA512 multi-buffer manager structure.
58  * @requires SSE4.1 or AVX or AVX2 or AVX512
59  *
60  * @param mgr	Structure holding context level state info
61  * @returns void
62  */
63 void
64 _sha512_ctx_mgr_init(ISAL_SHA512_HASH_CTX_MGR *mgr);
65 
66 /**
67  * @brief  Submit a new SHA512 job to the multi-buffer manager.
68  * @requires SSE4.1 or AVX or AVX2 or AVX512
69  *
70  * @param  mgr Structure holding context level state info
71  * @param  ctx Structure holding ctx job info
72  * @param  buffer Pointer to buffer to be processed
73  * @param  len Length of buffer (in bytes) to be processed
74  * @param  flags Input flag specifying job type (first, update, last or entire)
75  * @returns NULL if no jobs complete or pointer to jobs structure.
76  */
77 ISAL_SHA512_HASH_CTX *
78 _sha512_ctx_mgr_submit(ISAL_SHA512_HASH_CTX_MGR *mgr, ISAL_SHA512_HASH_CTX *ctx, const void *buffer,
79                        uint32_t len, ISAL_HASH_CTX_FLAG flags);
80 
81 /**
82  * @brief Finish all submitted SHA512 jobs and return when complete.
83  * @requires SSE4.1 or AVX or AVX2 or AVX512
84  *
85  * @param mgr	Structure holding context level state info
86  * @returns NULL if no jobs to complete or pointer to jobs structure.
87  */
88 ISAL_SHA512_HASH_CTX *
89 _sha512_ctx_mgr_flush(ISAL_SHA512_HASH_CTX_MGR *mgr);
90 
91 /*******************************************************************
92  * Context level API function prototypes
93  ******************************************************************/
94 
95 /**
96  * @brief Initialize the context level SHA512 multi-buffer manager structure.
97  * @requires SSE4.1
98  *
99  * @param mgr Structure holding context level state info
100  * @returns void
101  */
102 void
103 _sha512_ctx_mgr_init_sse(ISAL_SHA512_HASH_CTX_MGR *mgr);
104 
105 /**
106  * @brief  Submit a new SHA512 job to the context level multi-buffer manager.
107  * @requires SSE4.1
108  *
109  * @param  mgr Structure holding context level state info
110  * @param  ctx Structure holding ctx job info
111  * @param  buffer Pointer to buffer to be processed
112  * @param  len Length of buffer (in bytes) to be processed
113  * @param  flags Input flag specifying job type (first, update, last or entire)
114  * @returns NULL if no jobs complete or pointer to jobs structure.
115  */
116 ISAL_SHA512_HASH_CTX *
117 _sha512_ctx_mgr_submit_sse(ISAL_SHA512_HASH_CTX_MGR *mgr, ISAL_SHA512_HASH_CTX *ctx,
118                            const void *buffer, uint32_t len, ISAL_HASH_CTX_FLAG flags);
119 
120 /**
121  * @brief Finish all submitted SHA512 jobs and return when complete.
122  * @requires SSE4.1
123  *
124  * @param mgr	Structure holding context level state info
125  * @returns NULL if no jobs to complete or pointer to jobs structure.
126  */
127 ISAL_SHA512_HASH_CTX *
128 _sha512_ctx_mgr_flush_sse(ISAL_SHA512_HASH_CTX_MGR *mgr);
129 
130 /**
131  * @brief Initialize the SHA512 multi-buffer manager structure.
132  * @requires AVX
133  *
134  * @param mgr Structure holding context level state info
135  * @returns void
136  */
137 void
138 _sha512_ctx_mgr_init_avx(ISAL_SHA512_HASH_CTX_MGR *mgr);
139 
140 /**
141  * @brief  Submit a new SHA512 job to the multi-buffer manager.
142  * @requires AVX
143  *
144  * @param  mgr Structure holding context level state info
145  * @param  ctx Structure holding ctx job info
146  * @param  buffer Pointer to buffer to be processed
147  * @param  len Length of buffer (in bytes) to be processed
148  * @param  flags Input flag specifying job type (first, update, last or entire)
149  * @returns NULL if no jobs complete or pointer to jobs structure.
150  */
151 ISAL_SHA512_HASH_CTX *
152 _sha512_ctx_mgr_submit_avx(ISAL_SHA512_HASH_CTX_MGR *mgr, ISAL_SHA512_HASH_CTX *ctx,
153                            const void *buffer, uint32_t len, ISAL_HASH_CTX_FLAG flags);
154 
155 /**
156  * @brief Finish all submitted SHA512 jobs and return when complete.
157  * @requires AVX
158  *
159  * @param mgr	Structure holding context level state info
160  * @returns NULL if no jobs to complete or pointer to jobs structure.
161  */
162 ISAL_SHA512_HASH_CTX *
163 _sha512_ctx_mgr_flush_avx(ISAL_SHA512_HASH_CTX_MGR *mgr);
164 
165 /**
166  * @brief Initialize the SHA512 multi-buffer manager structure.
167  * @requires AVX2
168  *
169  * @param mgr	Structure holding context level state info
170  * @returns void
171  */
172 void
173 _sha512_ctx_mgr_init_avx2(ISAL_SHA512_HASH_CTX_MGR *mgr);
174 
175 /**
176  * @brief  Submit a new SHA512 job to the multi-buffer manager.
177  * @requires AVX2
178  *
179  * @param  mgr Structure holding context level state info
180  * @param  ctx Structure holding ctx job info
181  * @param  buffer Pointer to buffer to be processed
182  * @param  len Length of buffer (in bytes) to be processed
183  * @param  flags Input flag specifying job type (first, update, last or entire)
184  * @returns NULL if no jobs complete or pointer to jobs structure.
185  */
186 ISAL_SHA512_HASH_CTX *
187 _sha512_ctx_mgr_submit_avx2(ISAL_SHA512_HASH_CTX_MGR *mgr, ISAL_SHA512_HASH_CTX *ctx,
188                             const void *buffer, uint32_t len, ISAL_HASH_CTX_FLAG flags);
189 
190 /**
191  * @brief Finish all submitted SHA512 jobs and return when complete.
192  * @requires AVX2
193  *
194  * @param mgr	Structure holding context level state info
195  * @returns NULL if no jobs to complete or pointer to jobs structure.
196  */
197 ISAL_SHA512_HASH_CTX *
198 _sha512_ctx_mgr_flush_avx2(ISAL_SHA512_HASH_CTX_MGR *mgr);
199 
200 /**
201  * @brief Initialize the SHA512 multi-buffer manager structure.
202  * @requires AVX512
203  *
204  * @param mgr	Structure holding context level state info
205  * @returns void
206  */
207 void
208 _sha512_ctx_mgr_init_avx512(ISAL_SHA512_HASH_CTX_MGR *mgr);
209 
210 /**
211  * @brief  Submit a new SHA512 job to the multi-buffer manager.
212  * @requires AVX512
213  *
214  * @param  mgr Structure holding context level state info
215  * @param  ctx Structure holding ctx job info
216  * @param  buffer Pointer to buffer to be processed
217  * @param  len Length of buffer (in bytes) to be processed
218  * @param  flags Input flag specifying job type (first, update, last or entire)
219  * @returns NULL if no jobs complete or pointer to jobs structure.
220  */
221 ISAL_SHA512_HASH_CTX *
222 _sha512_ctx_mgr_submit_avx512(ISAL_SHA512_HASH_CTX_MGR *mgr, ISAL_SHA512_HASH_CTX *ctx,
223                               const void *buffer, uint32_t len, ISAL_HASH_CTX_FLAG flags);
224 
225 /**
226  * @brief Finish all submitted SHA512 jobs and return when complete.
227  * @requires AVX512
228  *
229  * @param mgr	Structure holding context level state info
230  * @returns NULL if no jobs to complete or pointer to jobs structure.
231  */
232 ISAL_SHA512_HASH_CTX *
233 _sha512_ctx_mgr_flush_avx512(ISAL_SHA512_HASH_CTX_MGR *mgr);
234 
235 /**
236  * @brief Initialize the SHA512 multi-buffer manager structure.
237  * @requires SSE4
238  *
239  * @param mgr	Structure holding context level state info
240  * @returns void
241  */
242 void
243 _sha512_ctx_mgr_init_sb_sse4(ISAL_SHA512_HASH_CTX_MGR *mgr);
244 
245 /**
246  * @brief  Submit a new SHA512 job to the multi-buffer manager.
247  * @requires SSE4
248  *
249  * @param  mgr Structure holding context level state info
250  * @param  ctx Structure holding ctx job info
251  * @param  buffer Pointer to buffer to be processed
252  * @param  len Length of buffer (in bytes) to be processed
253  * @param  flags Input flag specifying job type (first, update, last or entire)
254  * @returns NULL if no jobs complete or pointer to jobs structure.
255  */
256 ISAL_SHA512_HASH_CTX *
257 _sha512_ctx_mgr_submit_sb_sse4(ISAL_SHA512_HASH_CTX_MGR *mgr, ISAL_SHA512_HASH_CTX *ctx,
258                                const void *buffer, uint32_t len, ISAL_HASH_CTX_FLAG flags);
259 
260 /**
261  * @brief Finish all submitted SHA512 jobs and return when complete.
262  * @requires SSE4
263  *
264  * @param mgr	Structure holding context level state info
265  * @returns NULL if no jobs to complete or pointer to jobs structure.
266  */
267 ISAL_SHA512_HASH_CTX *
268 _sha512_ctx_mgr_flush_sb_sse4(ISAL_SHA512_HASH_CTX_MGR *mgr);
269 
270 /*******************************************************************
271  * Scheduler (internal) level out-of-order function prototypes
272  ******************************************************************/
273 
274 void
275 _sha512_mb_mgr_init_sse(ISAL_SHA512_MB_JOB_MGR *state);
276 ISAL_SHA512_JOB *
277 _sha512_mb_mgr_submit_sse(ISAL_SHA512_MB_JOB_MGR *state, ISAL_SHA512_JOB *job);
278 ISAL_SHA512_JOB *
279 _sha512_mb_mgr_flush_sse(ISAL_SHA512_MB_JOB_MGR *state);
280 
281 #define _sha512_mb_mgr_init_avx _sha512_mb_mgr_init_sse
282 ISAL_SHA512_JOB *
283 _sha512_mb_mgr_submit_avx(ISAL_SHA512_MB_JOB_MGR *state, ISAL_SHA512_JOB *job);
284 ISAL_SHA512_JOB *
285 _sha512_mb_mgr_flush_avx(ISAL_SHA512_MB_JOB_MGR *state);
286 
287 void
288 _sha512_mb_mgr_init_avx2(ISAL_SHA512_MB_JOB_MGR *state);
289 ISAL_SHA512_JOB *
290 _sha512_mb_mgr_submit_avx2(ISAL_SHA512_MB_JOB_MGR *state, ISAL_SHA512_JOB *job);
291 ISAL_SHA512_JOB *
292 _sha512_mb_mgr_flush_avx2(ISAL_SHA512_MB_JOB_MGR *state);
293 
294 void
295 _sha512_mb_mgr_init_avx512(ISAL_SHA512_MB_JOB_MGR *state);
296 ISAL_SHA512_JOB *
297 _sha512_mb_mgr_submit_avx512(ISAL_SHA512_MB_JOB_MGR *state, ISAL_SHA512_JOB *job);
298 ISAL_SHA512_JOB *
299 _sha512_mb_mgr_flush_avx512(ISAL_SHA512_MB_JOB_MGR *state);
300 
301 // Single buffer SHA512 APIs, optimized for SLM.
302 void
303 _sha512_sse4(const void *M, void *D, uint64_t L);
304 // Note that these APIs comply with multi-buffer APIs' high level usage
305 void
306 _sha512_sb_mgr_init_sse4(ISAL_SHA512_MB_JOB_MGR *state);
307 ISAL_SHA512_JOB *
308 _sha512_sb_mgr_submit_sse4(ISAL_SHA512_MB_JOB_MGR *state, ISAL_SHA512_JOB *job);
309 ISAL_SHA512_JOB *
310 _sha512_sb_mgr_flush_sse4(ISAL_SHA512_MB_JOB_MGR *state);
311 #ifdef __cplusplus
312 }
313 #endif
314 
315 #endif // _SHA512_MB_INTERNAL_H_
316