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