Debian Codegraph @

cipher/sha256-ppc.c

raw
1 /* sha256-ppc.c - PowerPC vcrypto implementation of SHA-256 transform
2 * Copyright (C) 2019,2023 Jussi Kivilinna <[email protected]>
3 *
4 * This file is part of Libgcrypt.
5 *
6 * Libgcrypt is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as
8 * published by the Free Software Foundation; either version 2.1 of
9 * the License, or (at your option) any later version.
10 *
11 * Libgcrypt is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this program; if not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include <config.h>
21
22 #if defined(ENABLE_PPC_CRYPTO_SUPPORT) && \
23 defined(HAVE_COMPATIBLE_CC_PPC_ALTIVEC) && \
24 defined(HAVE_GCC_INLINE_ASM_PPC_ALTIVEC) && \
25 defined(USE_SHA256) && \
26 __GNUC__ >= 4
27
28 #include "simd-common-ppc.h"
29 #include <altivec.h>
30 #include "bufhelp.h"
31
32
33 typedef vector unsigned char vector16x_u8;
34 typedef vector unsigned int vector4x_u32;
35 typedef vector unsigned long long vector2x_u64;
36
37
38 #define ALWAYS_INLINE inline __attribute__((always_inline))
39 #define NO_INLINE __attribute__((noinline))
40 #define NO_INSTRUMENT_FUNCTION __attribute__((no_instrument_function))
41
42 #define ASM_FUNC_ATTR NO_INSTRUMENT_FUNCTION
43 #define ASM_FUNC_ATTR_INLINE ASM_FUNC_ATTR ALWAYS_INLINE
44 #define ASM_FUNC_ATTR_NOINLINE ASM_FUNC_ATTR NO_INLINE
45
46 #ifdef HAVE_GCC_ATTRIBUTE_OPTIMIZE
47 # define FUNC_ATTR_OPT_O2 __attribute__((optimize("-O2")))
48 #else
49 # define FUNC_ATTR_OPT_O2
50 #endif
51
52 #if defined(__clang__) && defined(HAVE_CLANG_ATTRIBUTE_PPC_TARGET)
53 # define FUNC_ATTR_TARGET_P8 __attribute__((target("arch=pwr8")))
54 # define FUNC_ATTR_TARGET_P9 __attribute__((target("arch=pwr9")))
55 #elif defined(HAVE_GCC_ATTRIBUTE_PPC_TARGET)
56 # define FUNC_ATTR_TARGET_P8 __attribute__((target("cpu=power8")))
57 # define FUNC_ATTR_TARGET_P9 __attribute__((target("cpu=power9")))
58 #else
59 # define FUNC_ATTR_TARGET_P8
60 # define FUNC_ATTR_TARGET_P9
61 #endif
62
63
64 static const vector4x_u32 K[64 / 4] =
65 {
66 #define TBL(v) v
67 { TBL(0x428a2f98), TBL(0x71374491), TBL(0xb5c0fbcf), TBL(0xe9b5dba5) },
68 { TBL(0x3956c25b), TBL(0x59f111f1), TBL(0x923f82a4), TBL(0xab1c5ed5) },
69 { TBL(0xd807aa98), TBL(0x12835b01), TBL(0x243185be), TBL(0x550c7dc3) },
70 { TBL(0x72be5d74), TBL(0x80deb1fe), TBL(0x9bdc06a7), TBL(0xc19bf174) },
71 { TBL(0xe49b69c1), TBL(0xefbe4786), TBL(0x0fc19dc6), TBL(0x240ca1cc) },
72 { TBL(0x2de92c6f), TBL(0x4a7484aa), TBL(0x5cb0a9dc), TBL(0x76f988da) },
73 { TBL(0x983e5152), TBL(0xa831c66d), TBL(0xb00327c8), TBL(0xbf597fc7) },
74 { TBL(0xc6e00bf3), TBL(0xd5a79147), TBL(0x06ca6351), TBL(0x14292967) },
75 { TBL(0x27b70a85), TBL(0x2e1b2138), TBL(0x4d2c6dfc), TBL(0x53380d13) },
76 { TBL(0x650a7354), TBL(0x766a0abb), TBL(0x81c2c92e), TBL(0x92722c85) },
77 { TBL(0xa2bfe8a1), TBL(0xa81a664b), TBL(0xc24b8b70), TBL(0xc76c51a3) },
78 { TBL(0xd192e819), TBL(0xd6990624), TBL(0xf40e3585), TBL(0x106aa070) },
79 { TBL(0x19a4c116), TBL(0x1e376c08), TBL(0x2748774c), TBL(0x34b0bcb5) },
80 { TBL(0x391c0cb3), TBL(0x4ed8aa4a), TBL(0x5b9cca4f), TBL(0x682e6ff3) },
81 { TBL(0x748f82ee), TBL(0x78a5636f), TBL(0x84c87814), TBL(0x8cc70208) },
82 { TBL(0x90befffa), TBL(0xa4506ceb), TBL(0xbef9a3f7), TBL(0xc67178f2) }
83 #undef TBL
84 };
85
86
87 static ASM_FUNC_ATTR_INLINE vector4x_u32
88 vec_rol_elems(vector4x_u32 v, unsigned int idx)
89 {
90 #ifndef WORDS_BIGENDIAN
91 return vec_sld (v, v, (16 - (4 * idx)) & 15);
92 #else
93 return vec_sld (v, v, (4 * idx) & 15);
94 #endif
95 }
96
97
98 static ASM_FUNC_ATTR_INLINE vector4x_u32
99 vec_merge_idx0_elems(vector4x_u32 v0, vector4x_u32 v1,
100 vector4x_u32 v2, vector4x_u32 v3)
101 {
102 return (vector4x_u32)vec_mergeh ((vector2x_u64) vec_mergeh(v0, v1),
103 (vector2x_u64) vec_mergeh(v2, v3));
104 }
105
106
107 static ASM_FUNC_ATTR_INLINE vector4x_u32
108 vec_vshasigma_u32(vector4x_u32 v, unsigned int a, unsigned int b)
109 {
110 asm ("vshasigmaw %0,%1,%2,%3"
111 : "=v" (v)
112 : "v" (v), "g" (a), "g" (b)
113 : "memory");
114 return v;
115 }
116
117
118 static ASM_FUNC_ATTR_INLINE vector4x_u32
119 vec_add_u32(vector4x_u32 v, vector4x_u32 w)
120 {
121 __asm__ ("vadduwm %0,%1,%2"
122 : "=v" (v)
123 : "v" (v), "v" (w)
124 : "memory");
125 return v;
126 }
127
128
129 static ASM_FUNC_ATTR_INLINE vector4x_u32
130 vec_u32_load_be(unsigned long offset, const void *ptr)
131 {
132 vector4x_u32 vecu32;
133 #if __GNUC__ >= 4
134 if (__builtin_constant_p (offset) && offset == 0)
135 __asm__ volatile ("lxvw4x %x0,0,%1\n\t"
136 : "=wa" (vecu32)
137 : "r" ((uintptr_t)ptr)
138 : "memory");
139 else
140 #endif
141 __asm__ volatile ("lxvw4x %x0,%1,%2\n\t"
142 : "=wa" (vecu32)
143 : "r" (offset), "r" ((uintptr_t)ptr)
144 : "memory", "r0");
145 #ifndef WORDS_BIGENDIAN
146 return (vector4x_u32)vec_reve((vector16x_u8)vecu32);
147 #else
148 return vecu32;
149 #endif
150 }
151
152
153 /* SHA2 round in vector registers */
154 #define R(a,b,c,d,e,f,g,h,ki,w) do \
155 { \
156 t1 = vec_add_u32((h), (w)); \
157 t2 = Cho((e),(f),(g)); \
158 t1 = vec_add_u32(t1, GETK(ki)); \
159 t1 = vec_add_u32(t1, t2); \
160 t1 = Sum1add(t1, e); \
161 t2 = Maj((a),(b),(c)); \
162 t2 = Sum0add(t2, a); \
163 h = vec_add_u32(t1, t2); \
164 d += t1; \
165 } while (0)
166
167 #define GETK(kidx) \
168 ({ \
169 vector4x_u32 rk; \
170 if (((kidx) % 4) == 0) \
171 { \
172 rk = ktmp = *(kptr++); \
173 if ((kidx) < 63) \
174 asm volatile("" : "+r" (kptr) :: "memory"); \
175 } \
176 else if (((kidx) % 4) == 1) \
177 { \
178 rk = vec_mergeo(ktmp, ktmp); \
179 } \
180 else \
181 { \
182 rk = vec_rol_elems(ktmp, ((kidx) % 4)); \
183 } \
184 rk; \
185 })
186
187 #define Cho(b, c, d) (vec_sel(d, c, b))
188
189 #define Maj(c, d, b) (vec_sel(c, b, c ^ d))
190
191 #define Sum0(x) (vec_vshasigma_u32(x, 1, 0))
192
193 #define Sum1(x) (vec_vshasigma_u32(x, 1, 15))
194
195 #define S0(x) (vec_vshasigma_u32(x, 0, 0))
196
197 #define S1(x) (vec_vshasigma_u32(x, 0, 15))
198
199 #define Xadd(X, d, x) vec_add_u32(d, X(x))
200
201 #define Sum0add(d, x) Xadd(Sum0, d, x)
202
203 #define Sum1add(d, x) Xadd(Sum1, d, x)
204
205 #define S0add(d, x) Xadd(S0, d, x)
206
207 #define S1add(d, x) Xadd(S1, d, x)
208
209 #define I(i) \
210 ({ \
211 if (((i) % 4) == 0) \
212 { \
213 w[i] = vec_u32_load_be(0, data); \
214 data += 4 * 4; \
215 if ((i) / 4 < 3) \
216 asm volatile("" : "+r"(data) :: "memory"); \
217 } \
218 else if (((i) % 4) == 1) \
219 { \
220 w[i] = vec_mergeo(w[(i) - 1], w[(i) - 1]); \
221 } \
222 else \
223 { \
224 w[i] = vec_rol_elems(w[(i) - (i) % 4], (i)); \
225 } \
226 })
227
228 #define WN(i) ({ w[(i)&0x0f] += w[((i)-7) &0x0f]; \
229 w[(i)&0x0f] = S0add(w[(i)&0x0f], w[((i)-15)&0x0f]); \
230 w[(i)&0x0f] = S1add(w[(i)&0x0f], w[((i)-2) &0x0f]); })
231
232 #define W(i) ({ vector4x_u32 r = w[(i)&0x0f]; WN(i); r; })
233
234 #define L(i) w[(i)&0x0f]
235
236 #define I2(i) \
237 ({ \
238 if ((i) % 4 == 0) \
239 { \
240 vector4x_u32 iw = vec_u32_load_be(0, data); \
241 vector4x_u32 iw2 = vec_u32_load_be(64, data); \
242 if ((i) / 4 < 3) \
243 { \
244 data += 4 * 4; \
245 asm volatile("" : "+r"(data) :: "memory"); \
246 } \
247 else \
248 { \
249 data += 4 * 4 + 64; \
250 asm volatile("" : "+r"(data) :: "memory"); \
251 } \
252 w[(i) + 0] = vec_mergeh(iw, iw2); \
253 w[(i) + 1] = vec_rol_elems(w[(i) + 0], 2); \
254 w[(i) + 2] = vec_mergel(iw, iw2); \
255 w[(i) + 3] = vec_rol_elems(w[(i) + 2], 2); \
256 } \
257 })
258
259 #define W2(i) \
260 ({ \
261 vector4x_u32 wt1 = w[(i)&0x0f]; \
262 WN(i); \
263 w2[(i) / 2] = (((i) % 2) == 0) ? wt1 : vec_mergeo(w2[(i) / 2], wt1); \
264 wt1; \
265 })
266
267 #define L2(i) \
268 ({ \
269 vector4x_u32 lt1 = w[(i)&0x0f]; \
270 w2[(i) / 2] = (((i) % 2) == 0) ? lt1 : vec_mergeo(w2[(i) / 2], lt1); \
271 lt1; \
272 })
273
274 #define WL(i) \
275 ({ \
276 vector4x_u32 wlt1 = w2[(i) / 2]; \
277 if (((i) % 2) == 0 && (i) < 63) \
278 w2[(i) / 2] = vec_mergeo(wlt1, wlt1); \
279 wlt1; \
280 })
281
282 static ASM_FUNC_ATTR_INLINE FUNC_ATTR_OPT_O2 unsigned int
283 sha256_transform_ppc(u32 state[8], const unsigned char *data, size_t nblks)
284 {
285 vector4x_u32 h0, h1, h2, h3, h4, h5, h6, h7;
286 vector4x_u32 h0_h3, h4_h7;
287 vector4x_u32 a, b, c, d, e, f, g, h, t1, t2;
288 vector4x_u32 w[16];
289 vector4x_u32 w2[64 / 2];
290
291 h0_h3 = vec_vsx_ld (4 * 0, state);
292 h4_h7 = vec_vsx_ld (4 * 4, state);
293
294 h0 = h0_h3;
295 h1 = vec_mergeo (h0_h3, h0_h3);
296 h2 = vec_rol_elems (h0_h3, 2);
297 h3 = vec_rol_elems (h0_h3, 3);
298 h4 = h4_h7;
299 h5 = vec_mergeo (h4_h7, h4_h7);
300 h6 = vec_rol_elems (h4_h7, 2);
301 h7 = vec_rol_elems (h4_h7, 3);
302
303 while (nblks >= 2)
304 {
305 const vector4x_u32 *kptr = K;
306 vector4x_u32 ktmp;
307
308 a = h0;
309 b = h1;
310 c = h2;
311 d = h3;
312 e = h4;
313 f = h5;
314 g = h6;
315 h = h7;
316
317 I2(0); I2(1); I2(2); I2(3);
318 I2(4); I2(5); I2(6); I2(7);
319 I2(8); I2(9); I2(10); I2(11);
320 I2(12); I2(13); I2(14); I2(15);
321
322 R(a, b, c, d, e, f, g, h, 0, W2(0));
323 R(h, a, b, c, d, e, f, g, 1, W2(1));
324 R(g, h, a, b, c, d, e, f, 2, W2(2));
325 R(f, g, h, a, b, c, d, e, 3, W2(3));
326 R(e, f, g, h, a, b, c, d, 4, W2(4));
327 R(d, e, f, g, h, a, b, c, 5, W2(5));
328 R(c, d, e, f, g, h, a, b, 6, W2(6));
329 R(b, c, d, e, f, g, h, a, 7, W2(7));
330 R(a, b, c, d, e, f, g, h, 8, W2(8));
331 R(h, a, b, c, d, e, f, g, 9, W2(9));
332 R(g, h, a, b, c, d, e, f, 10, W2(10));
333 R(f, g, h, a, b, c, d, e, 11, W2(11));
334 R(e, f, g, h, a, b, c, d, 12, W2(12));
335 R(d, e, f, g, h, a, b, c, 13, W2(13));
336 R(c, d, e, f, g, h, a, b, 14, W2(14));
337 R(b, c, d, e, f, g, h, a, 15, W2(15));
338
339 R(a, b, c, d, e, f, g, h, 16, W2(16));
340 R(h, a, b, c, d, e, f, g, 17, W2(17));
341 R(g, h, a, b, c, d, e, f, 18, W2(18));
342 R(f, g, h, a, b, c, d, e, 19, W2(19));
343 R(e, f, g, h, a, b, c, d, 20, W2(20));
344 R(d, e, f, g, h, a, b, c, 21, W2(21));
345 R(c, d, e, f, g, h, a, b, 22, W2(22));
346 R(b, c, d, e, f, g, h, a, 23, W2(23));
347 R(a, b, c, d, e, f, g, h, 24, W2(24));
348 R(h, a, b, c, d, e, f, g, 25, W2(25));
349 R(g, h, a, b, c, d, e, f, 26, W2(26));
350 R(f, g, h, a, b, c, d, e, 27, W2(27));
351 R(e, f, g, h, a, b, c, d, 28, W2(28));
352 R(d, e, f, g, h, a, b, c, 29, W2(29));
353 R(c, d, e, f, g, h, a, b, 30, W2(30));
354 R(b, c, d, e, f, g, h, a, 31, W2(31));
355
356 R(a, b, c, d, e, f, g, h, 32, W2(32));
357 R(h, a, b, c, d, e, f, g, 33, W2(33));
358 R(g, h, a, b, c, d, e, f, 34, W2(34));
359 R(f, g, h, a, b, c, d, e, 35, W2(35));
360 R(e, f, g, h, a, b, c, d, 36, W2(36));
361 R(d, e, f, g, h, a, b, c, 37, W2(37));
362 R(c, d, e, f, g, h, a, b, 38, W2(38));
363 R(b, c, d, e, f, g, h, a, 39, W2(39));
364 R(a, b, c, d, e, f, g, h, 40, W2(40));
365 R(h, a, b, c, d, e, f, g, 41, W2(41));
366 R(g, h, a, b, c, d, e, f, 42, W2(42));
367 R(f, g, h, a, b, c, d, e, 43, W2(43));
368 R(e, f, g, h, a, b, c, d, 44, W2(44));
369 R(d, e, f, g, h, a, b, c, 45, W2(45));
370 R(c, d, e, f, g, h, a, b, 46, W2(46));
371 R(b, c, d, e, f, g, h, a, 47, W2(47));
372
373 R(a, b, c, d, e, f, g, h, 48, L2(48));
374 R(h, a, b, c, d, e, f, g, 49, L2(49));
375 R(g, h, a, b, c, d, e, f, 50, L2(50));
376 R(f, g, h, a, b, c, d, e, 51, L2(51));
377 R(e, f, g, h, a, b, c, d, 52, L2(52));
378 R(d, e, f, g, h, a, b, c, 53, L2(53));
379 R(c, d, e, f, g, h, a, b, 54, L2(54));
380 R(b, c, d, e, f, g, h, a, 55, L2(55));
381 R(a, b, c, d, e, f, g, h, 56, L2(56));
382 R(h, a, b, c, d, e, f, g, 57, L2(57));
383 R(g, h, a, b, c, d, e, f, 58, L2(58));
384 R(f, g, h, a, b, c, d, e, 59, L2(59));
385 R(e, f, g, h, a, b, c, d, 60, L2(60));
386 R(d, e, f, g, h, a, b, c, 61, L2(61));
387 R(c, d, e, f, g, h, a, b, 62, L2(62));
388 R(b, c, d, e, f, g, h, a, 63, L2(63));
389
390 h0 += a;
391 h1 += b;
392 h2 += c;
393 h3 += d;
394 h4 += e;
395 h5 += f;
396 h6 += g;
397 h7 += h;
398
399 kptr = K;
400
401 a = h0;
402 b = h1;
403 c = h2;
404 d = h3;
405 e = h4;
406 f = h5;
407 g = h6;
408 h = h7;
409
410 R(a, b, c, d, e, f, g, h, 0, WL(0));
411 R(h, a, b, c, d, e, f, g, 1, WL(1));
412 R(g, h, a, b, c, d, e, f, 2, WL(2));
413 R(f, g, h, a, b, c, d, e, 3, WL(3));
414 R(e, f, g, h, a, b, c, d, 4, WL(4));
415 R(d, e, f, g, h, a, b, c, 5, WL(5));
416 R(c, d, e, f, g, h, a, b, 6, WL(6));
417 R(b, c, d, e, f, g, h, a, 7, WL(7));
418 R(a, b, c, d, e, f, g, h, 8, WL(8));
419 R(h, a, b, c, d, e, f, g, 9, WL(9));
420 R(g, h, a, b, c, d, e, f, 10, WL(10));
421 R(f, g, h, a, b, c, d, e, 11, WL(11));
422 R(e, f, g, h, a, b, c, d, 12, WL(12));
423 R(d, e, f, g, h, a, b, c, 13, WL(13));
424 R(c, d, e, f, g, h, a, b, 14, WL(14));
425 R(b, c, d, e, f, g, h, a, 15, WL(15));
426
427 R(a, b, c, d, e, f, g, h, 16, WL(16));
428 R(h, a, b, c, d, e, f, g, 17, WL(17));
429 R(g, h, a, b, c, d, e, f, 18, WL(18));
430 R(f, g, h, a, b, c, d, e, 19, WL(19));
431 R(e, f, g, h, a, b, c, d, 20, WL(20));
432 R(d, e, f, g, h, a, b, c, 21, WL(21));
433 R(c, d, e, f, g, h, a, b, 22, WL(22));
434 R(b, c, d, e, f, g, h, a, 23, WL(23));
435 R(a, b, c, d, e, f, g, h, 24, WL(24));
436 R(h, a, b, c, d, e, f, g, 25, WL(25));
437 R(g, h, a, b, c, d, e, f, 26, WL(26));
438 R(f, g, h, a, b, c, d, e, 27, WL(27));
439 R(e, f, g, h, a, b, c, d, 28, WL(28));
440 R(d, e, f, g, h, a, b, c, 29, WL(29));
441 R(c, d, e, f, g, h, a, b, 30, WL(30));
442 R(b, c, d, e, f, g, h, a, 31, WL(31));
443
444 R(a, b, c, d, e, f, g, h, 32, WL(32));
445 R(h, a, b, c, d, e, f, g, 33, WL(33));
446 R(g, h, a, b, c, d, e, f, 34, WL(34));
447 R(f, g, h, a, b, c, d, e, 35, WL(35));
448 R(e, f, g, h, a, b, c, d, 36, WL(36));
449 R(d, e, f, g, h, a, b, c, 37, WL(37));
450 R(c, d, e, f, g, h, a, b, 38, WL(38));
451 R(b, c, d, e, f, g, h, a, 39, WL(39));
452 R(a, b, c, d, e, f, g, h, 40, WL(40));
453 R(h, a, b, c, d, e, f, g, 41, WL(41));
454 R(g, h, a, b, c, d, e, f, 42, WL(42));
455 R(f, g, h, a, b, c, d, e, 43, WL(43));
456 R(e, f, g, h, a, b, c, d, 44, WL(44));
457 R(d, e, f, g, h, a, b, c, 45, WL(45));
458 R(c, d, e, f, g, h, a, b, 46, WL(46));
459 R(b, c, d, e, f, g, h, a, 47, WL(47));
460
461 R(a, b, c, d, e, f, g, h, 48, WL(48));
462 R(h, a, b, c, d, e, f, g, 49, WL(49));
463 R(g, h, a, b, c, d, e, f, 50, WL(50));
464 R(f, g, h, a, b, c, d, e, 51, WL(51));
465 R(e, f, g, h, a, b, c, d, 52, WL(52));
466 R(d, e, f, g, h, a, b, c, 53, WL(53));
467 R(c, d, e, f, g, h, a, b, 54, WL(54));
468 R(b, c, d, e, f, g, h, a, 55, WL(55));
469 R(a, b, c, d, e, f, g, h, 56, WL(56));
470 R(h, a, b, c, d, e, f, g, 57, WL(57));
471 R(g, h, a, b, c, d, e, f, 58, WL(58));
472 R(f, g, h, a, b, c, d, e, 59, WL(59));
473 R(e, f, g, h, a, b, c, d, 60, WL(60));
474 R(d, e, f, g, h, a, b, c, 61, WL(61));
475 R(c, d, e, f, g, h, a, b, 62, WL(62));
476 R(b, c, d, e, f, g, h, a, 63, WL(63));
477
478 h0 += a;
479 h1 += b;
480 h2 += c;
481 h3 += d;
482 h4 += e;
483 h5 += f;
484 h6 += g;
485 h7 += h;
486
487 nblks -= 2;
488 }
489
490 if (nblks)
491 {
492 const vector4x_u32 *kptr = K;
493 vector4x_u32 ktmp;
494
495 a = h0;
496 b = h1;
497 c = h2;
498 d = h3;
499 e = h4;
500 f = h5;
501 g = h6;
502 h = h7;
503
504 I(0); I(1); I(2); I(3);
505 I(4); I(5); I(6); I(7);
506 I(8); I(9); I(10); I(11);
507 I(12); I(13); I(14); I(15);
508
509 R(a, b, c, d, e, f, g, h, 0, W(0));
510 R(h, a, b, c, d, e, f, g, 1, W(1));
511 R(g, h, a, b, c, d, e, f, 2, W(2));
512 R(f, g, h, a, b, c, d, e, 3, W(3));
513 R(e, f, g, h, a, b, c, d, 4, W(4));
514 R(d, e, f, g, h, a, b, c, 5, W(5));
515 R(c, d, e, f, g, h, a, b, 6, W(6));
516 R(b, c, d, e, f, g, h, a, 7, W(7));
517 R(a, b, c, d, e, f, g, h, 8, W(8));
518 R(h, a, b, c, d, e, f, g, 9, W(9));
519 R(g, h, a, b, c, d, e, f, 10, W(10));
520 R(f, g, h, a, b, c, d, e, 11, W(11));
521 R(e, f, g, h, a, b, c, d, 12, W(12));
522 R(d, e, f, g, h, a, b, c, 13, W(13));
523 R(c, d, e, f, g, h, a, b, 14, W(14));
524 R(b, c, d, e, f, g, h, a, 15, W(15));
525
526 R(a, b, c, d, e, f, g, h, 16, W(16));
527 R(h, a, b, c, d, e, f, g, 17, W(17));
528 R(g, h, a, b, c, d, e, f, 18, W(18));
529 R(f, g, h, a, b, c, d, e, 19, W(19));
530 R(e, f, g, h, a, b, c, d, 20, W(20));
531 R(d, e, f, g, h, a, b, c, 21, W(21));
532 R(c, d, e, f, g, h, a, b, 22, W(22));
533 R(b, c, d, e, f, g, h, a, 23, W(23));
534 R(a, b, c, d, e, f, g, h, 24, W(24));
535 R(h, a, b, c, d, e, f, g, 25, W(25));
536 R(g, h, a, b, c, d, e, f, 26, W(26));
537 R(f, g, h, a, b, c, d, e, 27, W(27));
538 R(e, f, g, h, a, b, c, d, 28, W(28));
539 R(d, e, f, g, h, a, b, c, 29, W(29));
540 R(c, d, e, f, g, h, a, b, 30, W(30));
541 R(b, c, d, e, f, g, h, a, 31, W(31));
542
543 R(a, b, c, d, e, f, g, h, 32, W(32));
544 R(h, a, b, c, d, e, f, g, 33, W(33));
545 R(g, h, a, b, c, d, e, f, 34, W(34));
546 R(f, g, h, a, b, c, d, e, 35, W(35));
547 R(e, f, g, h, a, b, c, d, 36, W(36));
548 R(d, e, f, g, h, a, b, c, 37, W(37));
549 R(c, d, e, f, g, h, a, b, 38, W(38));
550 R(b, c, d, e, f, g, h, a, 39, W(39));
551 R(a, b, c, d, e, f, g, h, 40, W(40));
552 R(h, a, b, c, d, e, f, g, 41, W(41));
553 R(g, h, a, b, c, d, e, f, 42, W(42));
554 R(f, g, h, a, b, c, d, e, 43, W(43));
555 R(e, f, g, h, a, b, c, d, 44, W(44));
556 R(d, e, f, g, h, a, b, c, 45, W(45));
557 R(c, d, e, f, g, h, a, b, 46, W(46));
558 R(b, c, d, e, f, g, h, a, 47, W(47));
559
560 R(a, b, c, d, e, f, g, h, 48, L(48));
561 R(h, a, b, c, d, e, f, g, 49, L(49));
562 R(g, h, a, b, c, d, e, f, 50, L(50));
563 R(f, g, h, a, b, c, d, e, 51, L(51));
564 R(e, f, g, h, a, b, c, d, 52, L(52));
565 R(d, e, f, g, h, a, b, c, 53, L(53));
566 R(c, d, e, f, g, h, a, b, 54, L(54));
567 R(b, c, d, e, f, g, h, a, 55, L(55));
568 R(a, b, c, d, e, f, g, h, 56, L(56));
569 R(h, a, b, c, d, e, f, g, 57, L(57));
570 R(g, h, a, b, c, d, e, f, 58, L(58));
571 R(f, g, h, a, b, c, d, e, 59, L(59));
572 R(e, f, g, h, a, b, c, d, 60, L(60));
573 R(d, e, f, g, h, a, b, c, 61, L(61));
574 R(c, d, e, f, g, h, a, b, 62, L(62));
575 R(b, c, d, e, f, g, h, a, 63, L(63));
576
577 h0 += a;
578 h1 += b;
579 h2 += c;
580 h3 += d;
581 h4 += e;
582 h5 += f;
583 h6 += g;
584 h7 += h;
585
586 nblks--;
587 }
588
589 h0_h3 = vec_merge_idx0_elems (h0, h1, h2, h3);
590 h4_h7 = vec_merge_idx0_elems (h4, h5, h6, h7);
591 vec_vsx_st (h0_h3, 4 * 0, state);
592 vec_vsx_st (h4_h7, 4 * 4, state);
593
594 clear_vec_regs();
595
596 return sizeof(w2) + sizeof(w);
597 }
598
599 unsigned int ASM_FUNC_ATTR FUNC_ATTR_TARGET_P8 FUNC_ATTR_OPT_O2
600 _gcry_sha256_transform_ppc8(u32 state[8], const unsigned char *data,
601 size_t nblks)
602 {
603 return sha256_transform_ppc(state, data, nblks);
604 }
605
606 unsigned int ASM_FUNC_ATTR FUNC_ATTR_TARGET_P9 FUNC_ATTR_OPT_O2
607 _gcry_sha256_transform_ppc9(u32 state[8], const unsigned char *data,
608 size_t nblks)
609 {
610 return sha256_transform_ppc(state, data, nblks);
611 }
612
613 #endif /* ENABLE_PPC_CRYPTO_SUPPORT */