]>
git.proxmox.com Git - ceph.git/blob - 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.
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions
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
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.
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 **********************************************************************/
30 #ifndef _MH_SHA1_INTERNAL_H_
31 #define _MH_SHA1_INTERNAL_H_
34 * @file mh_sha1_internal.h
35 * @brief mh_sha1 internal function prototypes and macros
37 * Interface for mh_sha1 internal functions
48 # define inline __inline
51 // 64byte pointer align
52 #define ALIGN_64(pointer) ( ((uint64_t)(pointer) + 0x3F)&(~0x3F) )
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
64 #define K_00_19 0x5a827999UL
65 #define K_20_39 0x6ed9eba1UL
66 #define K_40_59 0x8f1bbcdcUL
67 #define K_60_79 0xca62c1d6UL
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)
75 #define rol32(x, r) (((x)<<(r)) ^ ((x)>>(32-(r))))
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))
84 /*******************************************************************
85 * SHA1 API internal function prototypes
86 ******************************************************************/
89 * @brief Performs complete SHA1 algorithm.
91 * @param input Pointer to buffer containing the input message.
92 * @param digest Pointer to digest to update.
93 * @param len Length of buffer.
96 void sha1_for_mh_sha1(const uint8_t * input_data
, uint32_t * digest
, const uint32_t len
);
99 * @brief Calculate sha1 digest of blocks which size is SHA1_BLOCK_SIZE
101 * @param data Pointer to data buffer containing the input message.
102 * @param digest Pointer to sha1 digest.
105 void sha1_single_for_mh_sha1(const uint8_t * data
, uint32_t digest
[]);
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 ******************************************************************/
114 * @brief Tail process for multi-hash sha1.
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.
119 * This function determines what instruction sets are enabled and selects the
120 * appropriate version at runtime.
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
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
]);
134 * @brief Tail process for multi-hash sha1.
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.
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
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
]);
152 * @brief Tail process for multi-hash sha1.
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.
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
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
]);
172 * @brief Tail process for multi-hash sha1.
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.
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
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
]);
192 * @brief Tail process for multi-hash sha1.
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.
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
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
]);
212 * @brief Tail process for multi-hash sha1.
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.
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
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
]);
232 * @brief Calculate mh_sha1 digest of blocks which size is MH_SHA1_BLOCK_SIZE*N.
234 * This function determines what instruction sets are enabled and selects the
235 * appropriate version at runtime.
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.
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
);
248 * @brief Calculate mh_sha1 digest of blocks which size is MH_SHA1_BLOCK_SIZE*N.
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.
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
);
261 * @brief Calculate mh_sha1 digest of blocks which size is MH_SHA1_BLOCK_SIZE*N.
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.
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
);
275 * @brief Calculate mh_sha1 digest of blocks which size is MH_SHA1_BLOCK_SIZE*N.
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.
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
);
290 * @brief Calculate mh_sha1 digest of blocks which size is MH_SHA1_BLOCK_SIZE*N.
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.
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
);
305 * @brief Calculate mh_sha1 digest of blocks which size is MH_SHA1_BLOCK_SIZE*N.
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.
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
);