1 /* |
|
2 * ==================================================================== |
|
3 * Copyright (c) 1998-2011 The OpenSSL Project. All rights reserved. |
|
4 * |
|
5 * Redistribution and use in source and binary forms, with or without |
|
6 * modification, are permitted provided that the following conditions |
|
7 * are met: |
|
8 * |
|
9 * 1. Redistributions of source code must retain the above copyright |
|
10 * notice, this list of conditions and the following disclaimer. |
|
11 * |
|
12 * 2. Redistributions in binary form must reproduce the above copyright |
|
13 * notice, this list of conditions and the following disclaimer in |
|
14 * the documentation and/or other materials provided with the |
|
15 * distribution. |
|
16 * |
|
17 * 3. All advertising materials mentioning features or use of this |
|
18 * software must display the following acknowledgment: |
|
19 * "This product includes software developed by the OpenSSL Project |
|
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" |
|
21 * |
|
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to |
|
23 * endorse or promote products derived from this software without |
|
24 * prior written permission. For written permission, please contact |
|
25 * [email protected]. |
|
26 * |
|
27 * 5. Products derived from this software may not be called "OpenSSL" |
|
28 * nor may "OpenSSL" appear in their names without prior written |
|
29 * permission of the OpenSSL Project. |
|
30 * |
|
31 * 6. Redistributions of any form whatsoever must retain the following |
|
32 * acknowledgment: |
|
33 * "This product includes software developed by the OpenSSL Project |
|
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)" |
|
35 * |
|
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY |
|
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR |
|
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
|
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
|
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
|
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
|
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
|
47 * OF THE POSSIBILITY OF SUCH DAMAGE. |
|
48 * ==================================================================== |
|
49 */ |
|
50 |
|
51 /* |
|
52 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. |
|
53 */ |
|
54 |
|
55 /*LINTLIBRARY*/ |
|
56 |
|
57 #if defined(lint) || defined(__lint) |
|
58 |
|
59 #include <sys/types.h> |
|
60 #include <openssl/sha.h> |
|
61 #include "../engine/eng_t4_sha2_asm.h" |
|
62 |
|
63 /*ARGSUSED*/ |
|
64 void |
|
65 t4_sha256_multiblock(T4_SHA256_CTX *c, const void *input, |
|
66 size_t num) |
|
67 { return; } |
|
68 |
|
69 /*ARGSUSED*/ |
|
70 void |
|
71 t4_sha512_multiblock(T4_SHA512_CTX *c, const void *input, |
|
72 size_t num) |
|
73 { return; } |
|
74 |
|
75 #else /* lint || __lint */ |
|
76 |
|
77 #include<sys/asm_linkage.h> |
|
78 |
|
79 ENTRY(t4_sha256_multiblock) |
|
80 |
|
81 add %o0, 0x8, %o0 !skip over first field in ctx |
|
82 |
|
83 !load result from previous digest (stored in ctx) |
|
84 ld [%o0], %f0 |
|
85 ld [%o0 + 0x4], %f1 |
|
86 ld [%o0 + 0x8], %f2 |
|
87 ld [%o0 + 0xc], %f3 |
|
88 ld [%o0 + 0x10], %f4 |
|
89 ld [%o0 + 0x14], %f5 |
|
90 ld [%o0 + 0x18], %f6 |
|
91 ld [%o0 + 0x1c], %f7 |
|
92 |
|
93 and %o1, 7, %o3 |
|
94 brnz %o3, sha256_unaligned_input |
|
95 nop |
|
96 |
|
97 sha256_loop: |
|
98 |
|
99 !load 64 bytes of data |
|
100 ldd [%o1], %f8 !load 8 bytes of data |
|
101 ldd [%o1 + 0x8], %f10 !load 8 bytes of data |
|
102 ldd [%o1 + 0x10], %f12 !load 8 bytes of data |
|
103 ldd [%o1 + 0x18], %f14 !load 8 bytes of data |
|
104 ldd [%o1 + 0x20], %f16 !load 8 bytes of data |
|
105 ldd [%o1 + 0x28], %f18 !load 8 bytes of data |
|
106 ldd [%o1 + 0x30], %f20 !load 8 bytes of data |
|
107 ldd [%o1 + 0x38], %f22 !load 8 bytes of data |
|
108 |
|
109 !perform crypto instruction here |
|
110 !sha256 |
|
111 .byte 0x81, 0xb0, 0x28, 0x40 |
|
112 |
|
113 dec %o2 |
|
114 brnz %o2, sha256_loop |
|
115 add %o1, 0x40, %o1 |
|
116 |
|
117 !copy digest back into ctx |
|
118 st %f0, [%o0] |
|
119 st %f1, [%o0 + 0x4] |
|
120 st %f2, [%o0 + 0x8] |
|
121 st %f3, [%o0 + 0xc] |
|
122 st %f4, [%o0 + 0x10] |
|
123 st %f5, [%o0 + 0x14] |
|
124 st %f6, [%o0 + 0x18] |
|
125 retl |
|
126 st %f7, [%o0 + 0x1c] |
|
127 |
|
128 sha256_unaligned_input: |
|
129 alignaddr %o1, %g0, %g0 ! generate %gsr |
|
130 andn %o1, 7, %o1 |
|
131 |
|
132 sha256_unaligned_input_loop: |
|
133 ldd [%o1], %f8 !load 8 bytes of data |
|
134 ldd [%o1 + 0x8], %f10 !load 8 bytes of data |
|
135 ldd [%o1 + 0x10], %f12 !load 8 bytes of data |
|
136 ldd [%o1 + 0x18], %f14 !load 8 bytes of data |
|
137 ldd [%o1 + 0x20], %f16 !load 8 bytes of data |
|
138 ldd [%o1 + 0x28], %f18 !load 8 bytes of data |
|
139 ldd [%o1 + 0x30], %f20 !load 8 bytes of data |
|
140 ldd [%o1 + 0x38], %f22 !load 8 bytes of data |
|
141 ldd [%o1 + 0x40], %f24 !load 8 bytes of data |
|
142 faligndata %f8, %f10, %f8 |
|
143 faligndata %f10, %f12, %f10 |
|
144 faligndata %f12, %f14, %f12 |
|
145 faligndata %f14, %f16, %f14 |
|
146 faligndata %f16, %f18, %f16 |
|
147 faligndata %f18, %f20, %f18 |
|
148 faligndata %f20, %f22, %f20 |
|
149 faligndata %f22, %f24, %f22 |
|
150 |
|
151 !perform crypto instruction here |
|
152 !sha256 |
|
153 .byte 0x81, 0xb0, 0x28, 0x40 |
|
154 |
|
155 dec %o2 |
|
156 brnz %o2, sha256_unaligned_input_loop |
|
157 add %o1, 0x40, %o1 |
|
158 |
|
159 !copy digest back into ctx |
|
160 st %f0, [%o0] |
|
161 st %f1, [%o0 + 0x4] |
|
162 st %f2, [%o0 + 0x8] |
|
163 st %f3, [%o0 + 0xc] |
|
164 st %f4, [%o0 + 0x10] |
|
165 st %f5, [%o0 + 0x14] |
|
166 st %f6, [%o0 + 0x18] |
|
167 retl |
|
168 st %f7, [%o0 + 0x1c] |
|
169 |
|
170 SET_SIZE(t4_sha256_multiblock) |
|
171 |
|
172 |
|
173 ENTRY(t4_sha512_multiblock) |
|
174 |
|
175 add %o0, 0x8, %o0 !skip over first field in ctx |
|
176 |
|
177 !load result from previous digest (stored in ctx) |
|
178 ld [%o0], %f0 |
|
179 ld [%o0 + 0x4], %f1 |
|
180 ld [%o0 + 0x8], %f2 |
|
181 ld [%o0 + 0xc], %f3 |
|
182 ld [%o0 + 0x10], %f4 |
|
183 ld [%o0 + 0x14], %f5 |
|
184 ld [%o0 + 0x18], %f6 |
|
185 ld [%o0 + 0x1c], %f7 |
|
186 ld [%o0 + 0x20], %f8 |
|
187 ld [%o0 + 0x24], %f9 |
|
188 ld [%o0 + 0x28], %f10 |
|
189 ld [%o0 + 0x2c], %f11 |
|
190 ld [%o0 + 0x30], %f12 |
|
191 ld [%o0 + 0x34], %f13 |
|
192 ld [%o0 + 0x38], %f14 |
|
193 ld [%o0 + 0x3c], %f15 |
|
194 |
|
195 and %o1, 7, %o3 |
|
196 brnz %o3, sha512_unaligned_input |
|
197 nop |
|
198 |
|
199 sha512_loop: |
|
200 |
|
201 !load 128 bytes of data |
|
202 ldd [%o1], %f16 !load 8 bytes of data |
|
203 ldd [%o1 + 0x8], %f18 !load 8 bytes of data |
|
204 ldd [%o1 + 0x10], %f20 !load 8 bytes of data |
|
205 ldd [%o1 + 0x18], %f22 !load 8 bytes of data |
|
206 ldd [%o1 + 0x20], %f24 !load 8 bytes of data |
|
207 ldd [%o1 + 0x28], %f26 !load 8 bytes of data |
|
208 ldd [%o1 + 0x30], %f28 !load 8 bytes of data |
|
209 ldd [%o1 + 0x38], %f30 !load 8 bytes of data |
|
210 ldd [%o1 + 0x40], %f32 !load 8 bytes of data |
|
211 ldd [%o1 + 0x48], %f34 !load 8 bytes of data |
|
212 ldd [%o1 + 0x50], %f36 !load 8 bytes of data |
|
213 ldd [%o1 + 0x58], %f38 !load 8 bytes of data |
|
214 ldd [%o1 + 0x60], %f40 !load 8 bytes of data |
|
215 ldd [%o1 + 0x68], %f42 !load 8 bytes of data |
|
216 ldd [%o1 + 0x70], %f44 !load 8 bytes of data |
|
217 ldd [%o1 + 0x78], %f46 !load 8 bytes of data |
|
218 |
|
219 !perform crypto instruction here |
|
220 !sha512 |
|
221 .byte 0x81, 0xb0, 0x28, 0x60 |
|
222 |
|
223 dec %o2 |
|
224 brnz %o2, sha512_loop |
|
225 add %o1, 0x80, %o1 |
|
226 |
|
227 !copy digest back into ctx |
|
228 st %f0, [%o0] |
|
229 st %f1, [%o0 + 0x4] |
|
230 st %f2, [%o0 + 0x8] |
|
231 st %f3, [%o0 + 0xc] |
|
232 st %f4, [%o0 + 0x10] |
|
233 st %f5, [%o0 + 0x14] |
|
234 st %f6, [%o0 + 0x18] |
|
235 st %f7, [%o0+ 0x1c] |
|
236 st %f8, [%o0+ 0x20] |
|
237 st %f9, [%o0+ 0x24] |
|
238 st %f10, [%o0+ 0x28] |
|
239 st %f11, [%o0+ 0x2c] |
|
240 st %f12, [%o0+ 0x30] |
|
241 st %f13, [%o0+ 0x34] |
|
242 st %f14, [%o0+ 0x38] |
|
243 retl |
|
244 st %f15, [%o0+ 0x3c] |
|
245 |
|
246 sha512_unaligned_input: |
|
247 alignaddr %o1, %g0, %g0 ! generate %gsr |
|
248 andn %o1, 7, %o1 |
|
249 |
|
250 sha512_unaligned_input_loop: |
|
251 ldd [%o1], %f16 !load 8 bytes of data |
|
252 ldd [%o1 + 0x8], %f18 !load 8 bytes of data |
|
253 ldd [%o1 + 0x10], %f20 !load 8 bytes of data |
|
254 ldd [%o1 + 0x18], %f22 !load 8 bytes of data |
|
255 ldd [%o1 + 0x20], %f24 !load 8 bytes of data |
|
256 ldd [%o1 + 0x28], %f26 !load 8 bytes of data |
|
257 ldd [%o1 + 0x30], %f28 !load 8 bytes of data |
|
258 ldd [%o1 + 0x38], %f30 !load 8 bytes of data |
|
259 ldd [%o1 + 0x40], %f32 !load 8 bytes of data |
|
260 ldd [%o1 + 0x48], %f34 !load 8 bytes of data |
|
261 ldd [%o1 + 0x50], %f36 !load 8 bytes of data |
|
262 ldd [%o1 + 0x58], %f38 !load 8 bytes of data |
|
263 ldd [%o1 + 0x60], %f40 !load 8 bytes of data |
|
264 ldd [%o1 + 0x68], %f42 !load 8 bytes of data |
|
265 ldd [%o1 + 0x70], %f44 !load 8 bytes of data |
|
266 ldd [%o1 + 0x78], %f46 !load 8 bytes of data |
|
267 ldd [%o1 + 0x80], %f48 !load 8 bytes of data |
|
268 faligndata %f16, %f18, %f16 |
|
269 faligndata %f18, %f20, %f18 |
|
270 faligndata %f20, %f22, %f20 |
|
271 faligndata %f22, %f24, %f22 |
|
272 faligndata %f24, %f26, %f24 |
|
273 faligndata %f26, %f28, %f26 |
|
274 faligndata %f28, %f30, %f28 |
|
275 faligndata %f30, %f32, %f30 |
|
276 faligndata %f32, %f34, %f32 |
|
277 faligndata %f34, %f36, %f34 |
|
278 faligndata %f36, %f38, %f36 |
|
279 faligndata %f38, %f40, %f38 |
|
280 faligndata %f40, %f42, %f40 |
|
281 faligndata %f42, %f44, %f42 |
|
282 faligndata %f44, %f46, %f44 |
|
283 faligndata %f46, %f48, %f46 |
|
284 |
|
285 !perform crypto instruction here |
|
286 !sha512 |
|
287 .byte 0x81, 0xb0, 0x28, 0x60 |
|
288 |
|
289 dec %o2 |
|
290 brnz %o2, sha512_unaligned_input_loop |
|
291 add %o1, 0x80, %o1 |
|
292 |
|
293 !copy digest back into ctx |
|
294 st %f0, [%o0] |
|
295 st %f1, [%o0 + 0x4] |
|
296 st %f2, [%o0 + 0x8] |
|
297 st %f3, [%o0 + 0xc] |
|
298 st %f4, [%o0 + 0x10] |
|
299 st %f5, [%o0 + 0x14] |
|
300 st %f6, [%o0 + 0x18] |
|
301 st %f7, [%o0+ 0x1c] |
|
302 st %f8, [%o0+ 0x20] |
|
303 st %f9, [%o0+ 0x24] |
|
304 st %f10, [%o0+ 0x28] |
|
305 st %f11, [%o0+ 0x2c] |
|
306 st %f12, [%o0+ 0x30] |
|
307 st %f13, [%o0+ 0x34] |
|
308 st %f14, [%o0+ 0x38] |
|
309 retl |
|
310 st %f15, [%o0+ 0x3c] |
|
311 |
|
312 SET_SIZE(t4_sha512_multiblock) |
|
313 |
|
314 #endif /* lint || __lint */ |
|