xref: /isa-l_crypto/include/md5_mb_internal.h (revision 0b8ee81f89a4a769b4b080d575a8fa09e90db402)
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 _MD5_MB_INTERNAL_H_
31 #define _MD5_MB_INTERNAL_H_
32 
33 /**
34  *  @file md5_mb_internal.h
35  *  @brief Multi-buffer CTX API MD5 function prototypes and structures
36  */
37 
38 #include <stdint.h>
39 #include <string.h>
40 
41 #include "md5_mb.h"
42 #include "multi_buffer.h"
43 #include "types.h"
44 
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48 
49 #define ISAL_MD5_LOG2_BLOCK_SIZE 6
50 #define ISAL_MD5_INITIAL_DIGEST  0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476
51 
52 /**
53  * @brief Initialize the MD5 multi-buffer manager structure.
54  * @requires SSE4.1 or AVX or AVX2 or AVX512
55  *
56  * @param mgr	Structure holding context level state info
57  * @returns void
58  */
59 void
60 _md5_ctx_mgr_init(ISAL_MD5_HASH_CTX_MGR *mgr);
61 
62 /**
63  * @brief  Submit a new MD5 job to the multi-buffer manager.
64  * @requires SSE4.1 or AVX or AVX2 or AVX512
65  *
66  * @param  mgr Structure holding context level state info
67  * @param  ctx Structure holding ctx job info
68  * @param  buffer Pointer to buffer to be processed
69  * @param  len Length of buffer (in bytes) to be processed
70  * @param  flags Input flag specifying job type (first, update, last or entire)
71  * @returns NULL if no jobs complete or pointer to jobs structure.
72  */
73 ISAL_MD5_HASH_CTX *
74 _md5_ctx_mgr_submit(ISAL_MD5_HASH_CTX_MGR *mgr, ISAL_MD5_HASH_CTX *ctx, const void *buffer,
75                     uint32_t len, ISAL_HASH_CTX_FLAG flags);
76 
77 /**
78  * @brief Finish all submitted MD5 jobs and return when complete.
79  * @requires SSE4.1 or AVX or AVX2 or AVX512
80  *
81  * @param mgr	Structure holding context level state info
82  * @returns NULL if no jobs to complete or pointer to jobs structure.
83  */
84 ISAL_MD5_HASH_CTX *
85 _md5_ctx_mgr_flush(ISAL_MD5_HASH_CTX_MGR *mgr);
86 
87 /*******************************************************************
88  * CTX level API function prototypes
89  ******************************************************************/
90 
91 /**
92  * @brief Initialize the context level MD5 multi-buffer manager structure.
93  * @requires SSE4.1
94  *
95  * @param mgr Structure holding context level state info
96  * @returns void
97  */
98 void
99 _md5_ctx_mgr_init_sse(ISAL_MD5_HASH_CTX_MGR *mgr);
100 
101 /**
102  * @brief  Submit a new MD5 job to the context level multi-buffer manager.
103  * @requires SSE4.1
104  *
105  * @param  mgr Structure holding context level state info
106  * @param  ctx Structure holding ctx job info
107  * @param  buffer Pointer to buffer to be processed
108  * @param  len Length of buffer (in bytes) to be processed
109  * @param  flags Input flag specifying job type (first, update, last or entire)
110  * @returns NULL if no jobs complete or pointer to jobs structure.
111  */
112 ISAL_MD5_HASH_CTX *
113 _md5_ctx_mgr_submit_sse(ISAL_MD5_HASH_CTX_MGR *mgr, ISAL_MD5_HASH_CTX *ctx, const void *buffer,
114                         uint32_t len, ISAL_HASH_CTX_FLAG flags);
115 
116 /**
117  * @brief Finish all submitted MD5 jobs and return when complete.
118  * @requires SSE4.1
119  *
120  * @param mgr	Structure holding context level state info
121  * @returns NULL if no jobs to complete or pointer to jobs structure.
122  */
123 ISAL_MD5_HASH_CTX *
124 _md5_ctx_mgr_flush_sse(ISAL_MD5_HASH_CTX_MGR *mgr);
125 
126 /**
127  * @brief Initialize the MD5 multi-buffer manager structure.
128  * @requires AVX
129  *
130  * @param mgr Structure holding context level state info
131  * @returns void
132  */
133 void
134 _md5_ctx_mgr_init_avx(ISAL_MD5_HASH_CTX_MGR *mgr);
135 
136 /**
137  * @brief  Submit a new MD5 job to the multi-buffer manager.
138  * @requires AVX
139  *
140  * @param  mgr Structure holding context level state info
141  * @param  ctx Structure holding ctx job info
142  * @param  buffer Pointer to buffer to be processed
143  * @param  len Length of buffer (in bytes) to be processed
144  * @param  flags Input flag specifying job type (first, update, last or entire)
145  * @returns NULL if no jobs complete or pointer to jobs structure.
146  */
147 ISAL_MD5_HASH_CTX *
148 _md5_ctx_mgr_submit_avx(ISAL_MD5_HASH_CTX_MGR *mgr, ISAL_MD5_HASH_CTX *ctx, const void *buffer,
149                         uint32_t len, ISAL_HASH_CTX_FLAG flags);
150 
151 /**
152  * @brief Finish all submitted MD5 jobs and return when complete.
153  * @requires AVX
154  *
155  * @param mgr	Structure holding context level state info
156  * @returns NULL if no jobs to complete or pointer to jobs structure.
157  */
158 ISAL_MD5_HASH_CTX *
159 _md5_ctx_mgr_flush_avx(ISAL_MD5_HASH_CTX_MGR *mgr);
160 
161 /**
162  * @brief Initialize the MD5 multi-buffer manager structure.
163  * @requires AVX2
164  *
165  * @param mgr	Structure holding context level state info
166  * @returns void
167  */
168 void
169 _md5_ctx_mgr_init_avx2(ISAL_MD5_HASH_CTX_MGR *mgr);
170 
171 /**
172  * @brief  Submit a new MD5 job to the multi-buffer manager.
173  * @requires AVX2
174  *
175  * @param  mgr Structure holding context level state info
176  * @param  ctx Structure holding ctx job info
177  * @param  buffer Pointer to buffer to be processed
178  * @param  len Length of buffer (in bytes) to be processed
179  * @param  flags Input flag specifying job type (first, update, last or entire)
180  * @returns NULL if no jobs complete or pointer to jobs structure.
181  */
182 ISAL_MD5_HASH_CTX *
183 _md5_ctx_mgr_submit_avx2(ISAL_MD5_HASH_CTX_MGR *mgr, ISAL_MD5_HASH_CTX *ctx, const void *buffer,
184                          uint32_t len, ISAL_HASH_CTX_FLAG flags);
185 
186 /**
187  * @brief Finish all submitted MD5 jobs and return when complete.
188  * @requires AVX2
189  *
190  * @param mgr	Structure holding context level state info
191  * @returns NULL if no jobs to complete or pointer to jobs structure.
192  */
193 ISAL_MD5_HASH_CTX *
194 _md5_ctx_mgr_flush_avx2(ISAL_MD5_HASH_CTX_MGR *mgr);
195 
196 /**
197  * @brief Initialize the MD5 multi-buffer manager structure.
198  * @requires AVX512
199  *
200  * @param mgr	Structure holding context level state info
201  * @returns void
202  */
203 void
204 _md5_ctx_mgr_init_avx512(ISAL_MD5_HASH_CTX_MGR *mgr);
205 
206 /**
207  * @brief  Submit a new MD5 job to the multi-buffer manager.
208  * @requires AVX512
209  *
210  * @param  mgr Structure holding context level state info
211  * @param  ctx Structure holding ctx job info
212  * @param  buffer Pointer to buffer to be processed
213  * @param  len Length of buffer (in bytes) to be processed
214  * @param  flags Input flag specifying job type (first, update, last or entire)
215  * @returns NULL if no jobs complete or pointer to jobs structure.
216  */
217 ISAL_MD5_HASH_CTX *
218 _md5_ctx_mgr_submit_avx512(ISAL_MD5_HASH_CTX_MGR *mgr, ISAL_MD5_HASH_CTX *ctx, const void *buffer,
219                            uint32_t len, ISAL_HASH_CTX_FLAG flags);
220 
221 /**
222  * @brief Finish all submitted MD5 jobs and return when complete.
223  * @requires AVX512
224  *
225  * @param mgr	Structure holding context level state info
226  * @returns NULL if no jobs to complete or pointer to jobs structure.
227  */
228 ISAL_MD5_HASH_CTX *
229 _md5_ctx_mgr_flush_avx512(ISAL_MD5_HASH_CTX_MGR *mgr);
230 
231 /*******************************************************************
232  * Scheduler (internal) level out-of-order function prototypes
233  ******************************************************************/
234 
235 void
236 _md5_mb_mgr_init_sse(ISAL_MD5_MB_JOB_MGR *state);
237 ISAL_MD5_JOB *
238 _md5_mb_mgr_submit_sse(ISAL_MD5_MB_JOB_MGR *state, ISAL_MD5_JOB *job);
239 ISAL_MD5_JOB *
240 _md5_mb_mgr_flush_sse(ISAL_MD5_MB_JOB_MGR *state);
241 
242 #define _md5_mb_mgr_init_avx _md5_mb_mgr_init_sse
243 ISAL_MD5_JOB *
244 _md5_mb_mgr_submit_avx(ISAL_MD5_MB_JOB_MGR *state, ISAL_MD5_JOB *job);
245 ISAL_MD5_JOB *
246 _md5_mb_mgr_flush_avx(ISAL_MD5_MB_JOB_MGR *state);
247 
248 void
249 _md5_mb_mgr_init_avx2(ISAL_MD5_MB_JOB_MGR *state);
250 ISAL_MD5_JOB *
251 _md5_mb_mgr_submit_avx2(ISAL_MD5_MB_JOB_MGR *state, ISAL_MD5_JOB *job);
252 ISAL_MD5_JOB *
253 _md5_mb_mgr_flush_avx2(ISAL_MD5_MB_JOB_MGR *state);
254 
255 void
256 _md5_mb_mgr_init_avx512(ISAL_MD5_MB_JOB_MGR *state);
257 ISAL_MD5_JOB *
258 _md5_mb_mgr_submit_avx512(ISAL_MD5_MB_JOB_MGR *state, ISAL_MD5_JOB *job);
259 ISAL_MD5_JOB *
260 _md5_mb_mgr_flush_avx512(ISAL_MD5_MB_JOB_MGR *state);
261 
262 #ifdef __cplusplus
263 }
264 #endif
265 
266 #endif // _MD5_MB_INTERNAL_H_
267