]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /********************************************************************** |
2 | Copyright(c) 2011-2016 Intel Corporation All rights reserved. | |
3 | ||
4 | Redistribution and use in source and binary forms, with or without | |
1e59de90 | 5 | modification, are permitted provided that the following conditions |
7c673cae FG |
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 | #include <string.h> | |
31 | #include "mh_sha1_internal.h" | |
32 | ||
33 | int mh_sha1_init(struct mh_sha1_ctx *ctx) | |
34 | { | |
35 | uint32_t(*mh_sha1_segs_digests)[HASH_SEGS]; | |
36 | uint32_t i; | |
37 | ||
38 | if (ctx == NULL) | |
39 | return MH_SHA1_CTX_ERROR_NULL; | |
40 | ||
41 | memset(ctx, 0, sizeof(*ctx)); | |
42 | ||
43 | mh_sha1_segs_digests = (uint32_t(*)[HASH_SEGS]) ctx->mh_sha1_interim_digests; | |
44 | for (i = 0; i < HASH_SEGS; i++) { | |
45 | mh_sha1_segs_digests[0][i] = MH_SHA1_H0; | |
46 | mh_sha1_segs_digests[1][i] = MH_SHA1_H1; | |
47 | mh_sha1_segs_digests[2][i] = MH_SHA1_H2; | |
48 | mh_sha1_segs_digests[3][i] = MH_SHA1_H3; | |
49 | mh_sha1_segs_digests[4][i] = MH_SHA1_H4; | |
50 | } | |
51 | ||
52 | return MH_SHA1_CTX_ERROR_NONE; | |
53 | } | |
54 | ||
1e59de90 TL |
55 | #if (!defined(NOARCH)) && (defined(__i386__) || defined(__x86_64__) \ |
56 | || defined( _M_X64) || defined(_M_IX86)) | |
7c673cae FG |
57 | /***************mh_sha1_update***********/ |
58 | // mh_sha1_update_sse.c | |
59 | #define MH_SHA1_UPDATE_FUNCTION mh_sha1_update_sse | |
60 | #define MH_SHA1_BLOCK_FUNCTION mh_sha1_block_sse | |
61 | #include "mh_sha1_update_base.c" | |
62 | #undef MH_SHA1_UPDATE_FUNCTION | |
63 | #undef MH_SHA1_BLOCK_FUNCTION | |
64 | ||
65 | // mh_sha1_update_avx.c | |
66 | #define MH_SHA1_UPDATE_FUNCTION mh_sha1_update_avx | |
67 | #define MH_SHA1_BLOCK_FUNCTION mh_sha1_block_avx | |
68 | #include "mh_sha1_update_base.c" | |
69 | #undef MH_SHA1_UPDATE_FUNCTION | |
70 | #undef MH_SHA1_BLOCK_FUNCTION | |
71 | ||
72 | // mh_sha1_update_avx2.c | |
73 | #define MH_SHA1_UPDATE_FUNCTION mh_sha1_update_avx2 | |
74 | #define MH_SHA1_BLOCK_FUNCTION mh_sha1_block_avx2 | |
75 | #include "mh_sha1_update_base.c" | |
76 | #undef MH_SHA1_UPDATE_FUNCTION | |
77 | #undef MH_SHA1_BLOCK_FUNCTION | |
78 | ||
79 | /***************mh_sha1_finalize AND mh_sha1_tail***********/ | |
80 | // mh_sha1_tail is used to calculate the last incomplete src data block | |
81 | // mh_sha1_finalize is a mh_sha1_ctx wrapper of mh_sha1_tail | |
82 | ||
83 | // mh_sha1_finalize_sse.c and mh_sha1_tail_sse.c | |
84 | #define MH_SHA1_FINALIZE_FUNCTION mh_sha1_finalize_sse | |
85 | #define MH_SHA1_TAIL_FUNCTION mh_sha1_tail_sse | |
86 | #define MH_SHA1_BLOCK_FUNCTION mh_sha1_block_sse | |
87 | #include "mh_sha1_finalize_base.c" | |
88 | #undef MH_SHA1_FINALIZE_FUNCTION | |
89 | #undef MH_SHA1_TAIL_FUNCTION | |
90 | #undef MH_SHA1_BLOCK_FUNCTION | |
91 | ||
92 | // mh_sha1_finalize_avx.c and mh_sha1_tail_avx.c | |
93 | #define MH_SHA1_FINALIZE_FUNCTION mh_sha1_finalize_avx | |
94 | #define MH_SHA1_TAIL_FUNCTION mh_sha1_tail_avx | |
95 | #define MH_SHA1_BLOCK_FUNCTION mh_sha1_block_avx | |
96 | #include "mh_sha1_finalize_base.c" | |
97 | #undef MH_SHA1_FINALIZE_FUNCTION | |
98 | #undef MH_SHA1_TAIL_FUNCTION | |
99 | #undef MH_SHA1_BLOCK_FUNCTION | |
100 | ||
101 | // mh_sha1_finalize_avx2.c and mh_sha1_tail_avx2.c | |
102 | #define MH_SHA1_FINALIZE_FUNCTION mh_sha1_finalize_avx2 | |
103 | #define MH_SHA1_TAIL_FUNCTION mh_sha1_tail_avx2 | |
104 | #define MH_SHA1_BLOCK_FUNCTION mh_sha1_block_avx2 | |
105 | #include "mh_sha1_finalize_base.c" | |
106 | #undef MH_SHA1_FINALIZE_FUNCTION | |
107 | #undef MH_SHA1_TAIL_FUNCTION | |
108 | #undef MH_SHA1_BLOCK_FUNCTION | |
109 | ||
110 | /***************version info***********/ | |
111 | ||
112 | struct slver { | |
113 | uint16_t snum; | |
114 | uint8_t ver; | |
115 | uint8_t core; | |
116 | }; | |
117 | // Version info | |
118 | struct slver mh_sha1_init_slver_00000271; | |
119 | struct slver mh_sha1_init_slver = { 0x0271, 0x00, 0x00 }; | |
120 | ||
121 | // mh_sha1_update version info | |
122 | struct slver mh_sha1_update_sse_slver_00000274; | |
123 | struct slver mh_sha1_update_sse_slver = { 0x0274, 0x00, 0x00 }; | |
124 | ||
125 | struct slver mh_sha1_update_avx_slver_02000276; | |
126 | struct slver mh_sha1_update_avx_slver = { 0x0276, 0x00, 0x02 }; | |
127 | ||
128 | struct slver mh_sha1_update_avx2_slver_04000278; | |
129 | struct slver mh_sha1_update_avx2_slver = { 0x0278, 0x00, 0x04 }; | |
130 | ||
131 | // mh_sha1_finalize version info | |
132 | struct slver mh_sha1_finalize_sse_slver_00000275; | |
133 | struct slver mh_sha1_finalize_sse_slver = { 0x0275, 0x00, 0x00 }; | |
134 | ||
135 | struct slver mh_sha1_finalize_avx_slver_02000277; | |
136 | struct slver mh_sha1_finalize_avx_slver = { 0x0277, 0x00, 0x02 }; | |
137 | ||
138 | struct slver mh_sha1_finalize_avx2_slver_04000279; | |
139 | struct slver mh_sha1_finalize_avx2_slver = { 0x0279, 0x00, 0x04 }; | |
1e59de90 TL |
140 | |
141 | #endif |