]> git.proxmox.com Git - ceph.git/blob - ceph/src/crypto/isa-l/isa-l_crypto/mh_sha1/mh_sha1_internal.h
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / crypto / isa-l / isa-l_crypto / mh_sha1 / mh_sha1_internal.h
1 /**********************************************************************
2 Copyright(c) 2011-2016 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 _MH_SHA1_INTERNAL_H_
31 #define _MH_SHA1_INTERNAL_H_
32
33 /**
34 * @file mh_sha1_internal.h
35 * @brief mh_sha1 internal function prototypes and macros
36 *
37 * Interface for mh_sha1 internal functions
38 *
39 */
40 #include <stdint.h>
41 #include "mh_sha1.h"
42 #include "endian_helper.h"
43
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47
48 #ifdef _MSC_VER
49 # define inline __inline
50 #endif
51
52 // 64byte pointer align
53 #define ALIGN_64(pointer) ( ((uint64_t)(pointer) + 0x3F)&(~0x3F) )
54
55 /*******************************************************************
56 *mh_sha1 constants and macros
57 ******************************************************************/
58 /* mh_sha1 constants */
59 #define MH_SHA1_H0 0x67452301UL
60 #define MH_SHA1_H1 0xefcdab89UL
61 #define MH_SHA1_H2 0x98badcfeUL
62 #define MH_SHA1_H3 0x10325476UL
63 #define MH_SHA1_H4 0xc3d2e1f0UL
64
65 #define K_00_19 0x5a827999UL
66 #define K_20_39 0x6ed9eba1UL
67 #define K_40_59 0x8f1bbcdcUL
68 #define K_60_79 0xca62c1d6UL
69
70 /* mh_sha1 macros */
71 #define F1(b,c,d) (d ^ (b & (c ^ d)))
72 #define F2(b,c,d) (b ^ c ^ d)
73 #define F3(b,c,d) ((b & c) | (d & (b | c)))
74 #define F4(b,c,d) (b ^ c ^ d)
75
76 #define rol32(x, r) (((x)<<(r)) ^ ((x)>>(32-(r))))
77
78 /*******************************************************************
79 * SHA1 API internal function prototypes
80 ******************************************************************/
81
82 /**
83 * @brief Performs complete SHA1 algorithm.
84 *
85 * @param input Pointer to buffer containing the input message.
86 * @param digest Pointer to digest to update.
87 * @param len Length of buffer.
88 * @returns None
89 */
90 void sha1_for_mh_sha1(const uint8_t * input_data, uint32_t * digest, const uint32_t len);
91
92 /*******************************************************************
93 * mh_sha1 API internal function prototypes
94 * Multiple versions of Update and Finalize functions are supplied which use
95 * multiple versions of block and tail process subfunctions.
96 ******************************************************************/
97
98 /**
99 * @brief Tail process for multi-hash sha1.
100 *
101 * Calculate the remainder of input data which is less than MH_SHA1_BLOCK_SIZE.
102 * It will output the final SHA1 digest based on mh_sha1_segs_digests.
103 *
104 * This function determines what instruction sets are enabled and selects the
105 * appropriate version at runtime.
106 *
107 * @param partial_buffer Pointer to the start addr of remainder
108 * @param total_len The total length of all sections of input data.
109 * @param mh_sha1_segs_digests The digests of all 16 segments .
110 * @param frame_buffer Pointer to buffer which is a temp working area
111 * @returns none
112 *
113 */
114 void mh_sha1_tail(uint8_t *partial_buffer, uint32_t total_len,
115 uint32_t (*mh_sha1_segs_digests)[HASH_SEGS],
116 uint8_t *frame_buffer, uint32_t mh_sha1_digest[SHA1_DIGEST_WORDS]);
117
118 /**
119 * @brief Tail process for multi-hash sha1.
120 *
121 * Calculate the remainder of input data which is less than MH_SHA1_BLOCK_SIZE.
122 * It will output the final SHA1 digest based on mh_sha1_segs_digests.
123 *
124 * @param partial_buffer Pointer to the start addr of remainder
125 * @param total_len The total length of all sections of input data.
126 * @param mh_sha1_segs_digests The digests of all 16 segments .
127 * @param frame_buffer Pointer to buffer which is a temp working area
128 * @param mh_sha1_digest mh_sha1 digest
129 * @returns none
130 *
131 */
132 void mh_sha1_tail_base(uint8_t *partial_buffer, uint32_t total_len,
133 uint32_t (*mh_sha1_segs_digests)[HASH_SEGS],
134 uint8_t *frame_buffer, uint32_t mh_sha1_digest[SHA1_DIGEST_WORDS]);
135
136 /**
137 * @brief Tail process for multi-hash sha1.
138 *
139 * Calculate the remainder of input data which is less than MH_SHA1_BLOCK_SIZE.
140 * It will output the final SHA1 digest based on mh_sha1_segs_digests.
141 *
142 * @requires SSE
143 *
144 * @param partial_buffer Pointer to the start addr of remainder
145 * @param total_len The total length of all sections of input data.
146 * @param mh_sha1_segs_digests The digests of all 16 segments .
147 * @param frame_buffer Pointer to buffer which is a temp working area
148 * @param mh_sha1_digest mh_sha1 digest
149 * @returns none
150 *
151 */
152 void mh_sha1_tail_sse(uint8_t *partial_buffer, uint32_t total_len,
153 uint32_t (*mh_sha1_segs_digests)[HASH_SEGS],
154 uint8_t *frame_buffer, uint32_t mh_sha1_digest[SHA1_DIGEST_WORDS]);
155
156 /**
157 * @brief Tail process for multi-hash sha1.
158 *
159 * Calculate the remainder of input data which is less than MH_SHA1_BLOCK_SIZE.
160 * It will output the final SHA1 digest based on mh_sha1_segs_digests.
161 *
162 * @requires AVX
163 *
164 * @param partial_buffer Pointer to the start addr of remainder
165 * @param total_len The total length of all sections of input data.
166 * @param mh_sha1_segs_digests The digests of all 16 segments .
167 * @param frame_buffer Pointer to buffer which is a temp working area
168 * @param mh_sha1_digest mh_sha1 digest
169 * @returns none
170 *
171 */
172 void mh_sha1_tail_avx(uint8_t *partial_buffer, uint32_t total_len,
173 uint32_t (*mh_sha1_segs_digests)[HASH_SEGS],
174 uint8_t *frame_buffer, uint32_t mh_sha1_digest[SHA1_DIGEST_WORDS]);
175
176 /**
177 * @brief Tail process for multi-hash sha1.
178 *
179 * Calculate the remainder of input data which is less than MH_SHA1_BLOCK_SIZE.
180 * It will output the final SHA1 digest based on mh_sha1_segs_digests.
181 *
182 * @requires AVX2
183 *
184 * @param partial_buffer Pointer to the start addr of remainder
185 * @param total_len The total length of all sections of input data.
186 * @param mh_sha1_segs_digests The digests of all 16 segments .
187 * @param frame_buffer Pointer to buffer which is a temp working area
188 * @param mh_sha1_digest mh_sha1 digest
189 * @returns none
190 *
191 */
192 void mh_sha1_tail_avx2(uint8_t *partial_buffer, uint32_t total_len,
193 uint32_t (*mh_sha1_segs_digests)[HASH_SEGS],
194 uint8_t *frame_buffer, uint32_t mh_sha1_digest[SHA1_DIGEST_WORDS]);
195
196 /**
197 * @brief Tail process for multi-hash sha1.
198 *
199 * Calculate the remainder of input data which is less than MH_SHA1_BLOCK_SIZE.
200 * It will output the final SHA1 digest based on mh_sha1_segs_digests.
201 *
202 * @requires AVX512
203 *
204 * @param partial_buffer Pointer to the start addr of remainder
205 * @param total_len The total length of all sections of input data.
206 * @param mh_sha1_segs_digests The digests of all 16 segments .
207 * @param frame_buffer Pointer to buffer which is a temp working area
208 * @param mh_sha1_digest mh_sha1 digest
209 * @returns none
210 *
211 */
212 void mh_sha1_tail_avx512(uint8_t *partial_buffer, uint32_t total_len,
213 uint32_t (*mh_sha1_segs_digests)[HASH_SEGS],
214 uint8_t *frame_buffer, uint32_t mh_sha1_digest[SHA1_DIGEST_WORDS]);
215
216 /**
217 * @brief Calculate mh_sha1 digest of blocks which size is MH_SHA1_BLOCK_SIZE*N.
218 *
219 * This function determines what instruction sets are enabled and selects the
220 * appropriate version at runtime.
221 *
222 * @param input_data Pointer to input data to be processed
223 * @param digests 16 segments digests
224 * @param frame_buffer Pointer to buffer which is a temp working area
225 * @param num_blocks The number of blocks.
226 * @returns none
227 *
228 */
229 void mh_sha1_block(const uint8_t * input_data, uint32_t digests[SHA1_DIGEST_WORDS][HASH_SEGS],
230 uint8_t frame_buffer[MH_SHA1_BLOCK_SIZE], uint32_t num_blocks);
231
232 /**
233 * @brief Calculate mh_sha1 digest of blocks which size is MH_SHA1_BLOCK_SIZE*N.
234 *
235 * @param input_data Pointer to input data to be processed
236 * @param digests 16 segments digests
237 * @param frame_buffer Pointer to buffer which is a temp working area
238 * @param num_blocks The number of blocks.
239 * @returns none
240 *
241 */
242 void mh_sha1_block_base(const uint8_t * input_data, uint32_t digests[SHA1_DIGEST_WORDS][HASH_SEGS],
243 uint8_t frame_buffer[MH_SHA1_BLOCK_SIZE], uint32_t num_blocks);
244
245 /**
246 * @brief Calculate mh_sha1 digest of blocks which size is MH_SHA1_BLOCK_SIZE*N.
247 *
248 * @requires SSE
249 * @param input_data Pointer to input data to be processed
250 * @param digests 16 segments digests
251 * @param frame_buffer Pointer to buffer which is a temp working area
252 * @param num_blocks The number of blocks.
253 * @returns none
254 *
255 */
256 void mh_sha1_block_sse(const uint8_t * input_data, uint32_t digests[SHA1_DIGEST_WORDS][HASH_SEGS],
257 uint8_t frame_buffer[MH_SHA1_BLOCK_SIZE], uint32_t num_blocks);
258
259 /**
260 * @brief Calculate mh_sha1 digest of blocks which size is MH_SHA1_BLOCK_SIZE*N.
261 *
262 * @requires AVX
263 *
264 * @param input_data Pointer to input data to be processed
265 * @param digests 16 segments digests
266 * @param frame_buffer Pointer to buffer which is a temp working area
267 * @param num_blocks The number of blocks.
268 * @returns none
269 *
270 */
271 void mh_sha1_block_avx(const uint8_t * input_data, uint32_t digests[SHA1_DIGEST_WORDS][HASH_SEGS],
272 uint8_t frame_buffer[MH_SHA1_BLOCK_SIZE], uint32_t num_blocks);
273
274 /**
275 * @brief Calculate mh_sha1 digest of blocks which size is MH_SHA1_BLOCK_SIZE*N.
276 *
277 * @requires AVX2
278 *
279 * @param input_data Pointer to input data to be processed
280 * @param digests 16 segments digests
281 * @param frame_buffer Pointer to buffer which is a temp working area
282 * @param num_blocks The number of blocks.
283 * @returns none
284 *
285 */
286 void mh_sha1_block_avx2(const uint8_t * input_data, uint32_t digests[SHA1_DIGEST_WORDS][HASH_SEGS],
287 uint8_t frame_buffer[MH_SHA1_BLOCK_SIZE], uint32_t num_blocks);
288
289 /**
290 * @brief Calculate mh_sha1 digest of blocks which size is MH_SHA1_BLOCK_SIZE*N.
291 *
292 * @requires AVX512
293 *
294 * @param input_data Pointer to input data to be processed
295 * @param digests 16 segments digests
296 * @param frame_buffer Pointer to buffer which is a temp working area
297 * @param num_blocks The number of blocks.
298 * @returns none
299 *
300 */
301 void mh_sha1_block_avx512(const uint8_t * input_data, uint32_t digests[SHA1_DIGEST_WORDS][HASH_SEGS],
302 uint8_t frame_buffer[MH_SHA1_BLOCK_SIZE], uint32_t num_blocks);
303
304 #ifdef __cplusplus
305 }
306 #endif
307
308 #endif