| 1 |
/* sha1-avx-amd64.S - Intel AVX accelerated SHA-1 transform function |
| 2 |
* Copyright (C) 2013 Jussi Kivilinna <[email protected]> |
| 3 |
* |
| 4 |
* Based on sha1.c: |
| 5 |
* Copyright (C) 1998, 2001, 2002, 2003, 2008 Free Software Foundation, Inc. |
| 6 |
* |
| 7 |
* This file is part of Libgcrypt. |
| 8 |
* |
| 9 |
* Libgcrypt is free software; you can redistribute it and/or modify |
| 10 |
* it under the terms of the GNU Lesser General Public License as |
| 11 |
* published by the Free Software Foundation; either version 2.1 of |
| 12 |
* the License, or (at your option) any later version. |
| 13 |
* |
| 14 |
* Libgcrypt is distributed in the hope that it will be useful, |
| 15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 |
* GNU Lesser General Public License for more details. |
| 18 |
* |
| 19 |
* You should have received a copy of the GNU Lesser General Public |
| 20 |
* License along with this program; if not, see <http://www.gnu.org/licenses/>. |
| 21 |
*/ |
| 22 |
|
| 23 |
/* |
| 24 |
* Intel SSSE3 accelerated SHA-1 implementation based on white paper: |
| 25 |
* "Improving the Performance of the Secure Hash Algorithm (SHA-1)" |
| 26 |
* http://software.intel.com/en-us/articles/improving-the-performance-of-the-secure-hash-algorithm-1 |
| 27 |
*/ |
| 28 |
|
| 29 |
#ifdef __x86_64__ |
| 30 |
#include <config.h> |
| 31 |
|
| 32 |
#if (defined(HAVE_COMPATIBLE_GCC_AMD64_PLATFORM_AS) || \ |
| 33 |
defined(HAVE_COMPATIBLE_GCC_WIN64_PLATFORM_AS)) && \ |
| 34 |
defined(HAVE_GCC_INLINE_ASM_AVX) && defined(USE_SHA1) |
| 35 |
|
| 36 |
#include "asm-common-amd64.h" |
| 37 |
|
| 38 |
|
| 39 |
/* Context structure */ |
| 40 |
|
| 41 |
#define state_h0 0 |
| 42 |
#define state_h1 4 |
| 43 |
#define state_h2 8 |
| 44 |
#define state_h3 12 |
| 45 |
#define state_h4 16 |
| 46 |
|
| 47 |
|
| 48 |
/* Constants */ |
| 49 |
|
| 50 |
SECTION_RODATA |
| 51 |
|
| 52 |
ELF(.type _sha1_avx_consts,@object) |
| 53 |
_sha1_avx_consts: |
| 54 |
#define K1 0x5A827999 |
| 55 |
#define K2 0x6ED9EBA1 |
| 56 |
#define K3 0x8F1BBCDC |
| 57 |
#define K4 0xCA62C1D6 |
| 58 |
.align 16 |
| 59 |
.LK_XMM: |
| 60 |
.LK1: .long K1, K1, K1, K1 |
| 61 |
.LK2: .long K2, K2, K2, K2 |
| 62 |
.LK3: .long K3, K3, K3, K3 |
| 63 |
.LK4: .long K4, K4, K4, K4 |
| 64 |
|
| 65 |
.Lbswap_shufb_ctl: |
| 66 |
.long 0x00010203, 0x04050607, 0x08090a0b, 0x0c0d0e0f |
| 67 |
|
| 68 |
|
| 69 |
/* Register macros */ |
| 70 |
|
| 71 |
#define RSTATE %r8 |
| 72 |
#define RDATA %r9 |
| 73 |
#define ROLDSTACK %r10 |
| 74 |
#define RNBLKS %r11 |
| 75 |
|
| 76 |
#define a %eax |
| 77 |
#define b %ebx |
| 78 |
#define c %ecx |
| 79 |
#define d %edx |
| 80 |
#define e %edi |
| 81 |
|
| 82 |
#define RT0 %esi |
| 83 |
#define RT1 %ebp |
| 84 |
|
| 85 |
#define Wtmp0 %xmm0 |
| 86 |
#define Wtmp1 %xmm1 |
| 87 |
|
| 88 |
#define W0 %xmm2 |
| 89 |
#define W1 %xmm3 |
| 90 |
#define W2 %xmm4 |
| 91 |
#define W3 %xmm5 |
| 92 |
#define W4 %xmm6 |
| 93 |
#define W5 %xmm7 |
| 94 |
#define W6 %xmm8 |
| 95 |
#define W7 %xmm9 |
| 96 |
|
| 97 |
#define BSWAP_REG %xmm10 |
| 98 |
|
| 99 |
|
| 100 |
/* Round function macros. */ |
| 101 |
|
| 102 |
#define WK(i) (((i) & 15) * 4)(%rsp) |
| 103 |
|
| 104 |
#define R_F1(a,b,c,d,e,i) \ |
| 105 |
movl c, RT0; \ |
| 106 |
addl WK(i), e; \ |
| 107 |
xorl d, RT0; \ |
| 108 |
movl a, RT1; \ |
| 109 |
andl b, RT0; \ |
| 110 |
shldl $30, b, b; \ |
| 111 |
xorl d, RT0; \ |
| 112 |
leal (RT0,e), e; \ |
| 113 |
shldl $5, RT1, RT1; \ |
| 114 |
addl RT1, e; |
| 115 |
|
| 116 |
#define R_F2(a,b,c,d,e,i) \ |
| 117 |
movl c, RT0; \ |
| 118 |
addl WK(i), e; \ |
| 119 |
xorl b, RT0; \ |
| 120 |
shldl $30, b, b; \ |
| 121 |
xorl d, RT0; \ |
| 122 |
movl a, RT1; \ |
| 123 |
leal (RT0,e), e; \ |
| 124 |
shldl $5, RT1, RT1; \ |
| 125 |
addl RT1, e; |
| 126 |
|
| 127 |
#define R_F3(a,b,c,d,e,i) \ |
| 128 |
movl c, RT0; \ |
| 129 |
movl b, RT1; \ |
| 130 |
xorl b, RT0; \ |
| 131 |
andl c, RT1; \ |
| 132 |
andl d, RT0; \ |
| 133 |
addl RT1, e; \ |
| 134 |
addl WK(i), e; \ |
| 135 |
shldl $30, b, b; \ |
| 136 |
movl a, RT1; \ |
| 137 |
leal (RT0,e), e; \ |
| 138 |
shldl $5, RT1, RT1; \ |
| 139 |
addl RT1, e; |
| 140 |
|
| 141 |
#define R_F4(a,b,c,d,e,i) R_F2(a,b,c,d,e,i) |
| 142 |
|
| 143 |
#define R(a,b,c,d,e,f,i) \ |
| 144 |
R_##f(a,b,c,d,e,i) |
| 145 |
|
| 146 |
|
| 147 |
/* Input expansion macros. */ |
| 148 |
|
| 149 |
#define W_PRECALC_00_15_0(i, W, tmp0) \ |
| 150 |
vmovdqu (4*(i))(RDATA), tmp0; |
| 151 |
|
| 152 |
#define W_PRECALC_00_15_1(i, W, tmp0) \ |
| 153 |
vpshufb BSWAP_REG, tmp0, W; |
| 154 |
|
| 155 |
#define W_PRECALC_00_15_2(i, W, tmp0) \ |
| 156 |
vpaddd (.LK_XMM + ((i)/20)*16) rRIP, W, tmp0; |
| 157 |
|
| 158 |
#define W_PRECALC_00_15_3(i, W, tmp0) \ |
| 159 |
vmovdqa tmp0, WK(i&~3); |
| 160 |
|
| 161 |
#define W_PRECALC_16_31_0(i, W, W_m04, W_m08, W_m12, W_m16, tmp0, tmp1) \ |
| 162 |
vpalignr $8, W_m16, W_m12, W; \ |
| 163 |
vpsrldq $4, W_m04, tmp0; \ |
| 164 |
vpxor W_m08, W, W; |
| 165 |
|
| 166 |
#define W_PRECALC_16_31_1(i, W, W_m04, W_m08, W_m12, W_m16, tmp0, tmp1) \ |
| 167 |
vpxor W_m16, tmp0, tmp0; \ |
| 168 |
vpxor tmp0, W, W; \ |
| 169 |
vpslld $1, W, tmp0; \ |
| 170 |
vpslldq $12, W, tmp1; \ |
| 171 |
vpsrld $31, W, W; |
| 172 |
|
| 173 |
#define W_PRECALC_16_31_2(i, W, W_m04, W_m08, W_m12, W_m16, tmp0, tmp1) \ |
| 174 |
vpor W, tmp0, tmp0; \ |
| 175 |
vpsrld $30, tmp1, W; \ |
| 176 |
vpslld $2, tmp1, tmp1; |
| 177 |
|
| 178 |
#define W_PRECALC_16_31_3(i, W, W_m04, W_m08, W_m12, W_m16, tmp0, tmp1) \ |
| 179 |
vpxor W, tmp0, tmp0; \ |
| 180 |
vpxor tmp1, tmp0, W; \ |
| 181 |
vpaddd (.LK_XMM + ((i)/20)*16) rRIP, W, tmp0; \ |
| 182 |
vmovdqa tmp0, WK((i)&~3); |
| 183 |
|
| 184 |
#define W_PRECALC_32_79_0(i, W, W_m04, W_m08, W_m12, W_m16, W_m20, W_m24, W_m28, tmp0) \ |
| 185 |
vpxor W_m28, W, W; \ |
| 186 |
vpalignr $8, W_m08, W_m04, tmp0; |
| 187 |
|
| 188 |
#define W_PRECALC_32_79_1(i, W, W_m04, W_m08, W_m12, W_m16, W_m20, W_m24, W_m28, tmp0) \ |
| 189 |
vpxor W_m16, W, W; \ |
| 190 |
vpxor tmp0, W, W; |
| 191 |
|
| 192 |
#define W_PRECALC_32_79_2(i, W, W_m04, W_m08, W_m12, W_m16, W_m20, W_m24, W_m28, tmp0) \ |
| 193 |
vpsrld $30, W, tmp0; \ |
| 194 |
vpslld $2, W, W; |
| 195 |
|
| 196 |
#define W_PRECALC_32_79_3(i, W, W_m04, W_m08, W_m12, W_m16, W_m20, W_m24, W_m28, tmp0) \ |
| 197 |
vpor W, tmp0, W; \ |
| 198 |
vpaddd (.LK_XMM + ((i)/20)*16) rRIP, W, tmp0; \ |
| 199 |
vmovdqa tmp0, WK((i)&~3); |
| 200 |
|
| 201 |
.text |
| 202 |
|
| 203 |
/* |
| 204 |
* Transform nblks*64 bytes (nblks*16 32-bit words) at DATA. |
| 205 |
* |
| 206 |
* unsigned int |
| 207 |
* _gcry_sha1_transform_amd64_avx (void *ctx, const unsigned char *data, |
| 208 |
* size_t nblks) |
| 209 |
*/ |
| 210 |
.globl _gcry_sha1_transform_amd64_avx |
| 211 |
ELF(.type _gcry_sha1_transform_amd64_avx,@function) |
| 212 |
.align 16 |
| 213 |
_gcry_sha1_transform_amd64_avx: |
| 214 |
/* input: |
| 215 |
* %rdi: ctx, CTX |
| 216 |
* %rsi: data (64*nblks bytes) |
| 217 |
* %rdx: nblks |
| 218 |
*/ |
| 219 |
CFI_STARTPROC(); |
| 220 |
|
| 221 |
xorl %eax, %eax; |
| 222 |
cmpq $0, %rdx; |
| 223 |
jz .Lret; |
| 224 |
|
| 225 |
vzeroupper; |
| 226 |
|
| 227 |
movq %rdx, RNBLKS; |
| 228 |
movq %rdi, RSTATE; |
| 229 |
movq %rsi, RDATA; |
| 230 |
pushq %rbx; |
| 231 |
CFI_PUSH(%rbx); |
| 232 |
pushq %rbp; |
| 233 |
CFI_PUSH(%rbp); |
| 234 |
|
| 235 |
movq %rsp, ROLDSTACK; |
| 236 |
CFI_DEF_CFA_REGISTER(ROLDSTACK); |
| 237 |
|
| 238 |
subq $(16*4), %rsp; |
| 239 |
andq $(~31), %rsp; |
| 240 |
|
| 241 |
/* Get the values of the chaining variables. */ |
| 242 |
movl state_h0(RSTATE), a; |
| 243 |
movl state_h1(RSTATE), b; |
| 244 |
movl state_h2(RSTATE), c; |
| 245 |
movl state_h3(RSTATE), d; |
| 246 |
movl state_h4(RSTATE), e; |
| 247 |
|
| 248 |
vmovdqa .Lbswap_shufb_ctl rRIP, BSWAP_REG; |
| 249 |
|
| 250 |
/* Precalc 0-15. */ |
| 251 |
W_PRECALC_00_15_0(0, W0, Wtmp0); |
| 252 |
W_PRECALC_00_15_1(1, W0, Wtmp0); |
| 253 |
W_PRECALC_00_15_2(2, W0, Wtmp0); |
| 254 |
W_PRECALC_00_15_3(3, W0, Wtmp0); |
| 255 |
W_PRECALC_00_15_0(4, W7, Wtmp0); |
| 256 |
W_PRECALC_00_15_1(5, W7, Wtmp0); |
| 257 |
W_PRECALC_00_15_2(6, W7, Wtmp0); |
| 258 |
W_PRECALC_00_15_3(7, W7, Wtmp0); |
| 259 |
W_PRECALC_00_15_0(8, W6, Wtmp0); |
| 260 |
W_PRECALC_00_15_1(9, W6, Wtmp0); |
| 261 |
W_PRECALC_00_15_2(10, W6, Wtmp0); |
| 262 |
W_PRECALC_00_15_3(11, W6, Wtmp0); |
| 263 |
W_PRECALC_00_15_0(12, W5, Wtmp0); |
| 264 |
W_PRECALC_00_15_1(13, W5, Wtmp0); |
| 265 |
W_PRECALC_00_15_2(14, W5, Wtmp0); |
| 266 |
W_PRECALC_00_15_3(15, W5, Wtmp0); |
| 267 |
|
| 268 |
.align 8 |
| 269 |
.Loop: |
| 270 |
addq $64, RDATA; |
| 271 |
|
| 272 |
/* Transform 0-15 + Precalc 16-31. */ |
| 273 |
R( a, b, c, d, e, F1, 0 ); W_PRECALC_16_31_0(16, W4, W5, W6, W7, W0, Wtmp0, Wtmp1); |
| 274 |
R( e, a, b, c, d, F1, 1 ); W_PRECALC_16_31_1(17, W4, W5, W6, W7, W0, Wtmp0, Wtmp1); |
| 275 |
R( d, e, a, b, c, F1, 2 ); W_PRECALC_16_31_2(18, W4, W5, W6, W7, W0, Wtmp0, Wtmp1); |
| 276 |
R( c, d, e, a, b, F1, 3 ); W_PRECALC_16_31_3(19, W4, W5, W6, W7, W0, Wtmp0, Wtmp1); |
| 277 |
R( b, c, d, e, a, F1, 4 ); W_PRECALC_16_31_0(20, W3, W4, W5, W6, W7, Wtmp0, Wtmp1); |
| 278 |
R( a, b, c, d, e, F1, 5 ); W_PRECALC_16_31_1(21, W3, W4, W5, W6, W7, Wtmp0, Wtmp1); |
| 279 |
R( e, a, b, c, d, F1, 6 ); W_PRECALC_16_31_2(22, W3, W4, W5, W6, W7, Wtmp0, Wtmp1); |
| 280 |
R( d, e, a, b, c, F1, 7 ); W_PRECALC_16_31_3(23, W3, W4, W5, W6, W7, Wtmp0, Wtmp1); |
| 281 |
R( c, d, e, a, b, F1, 8 ); W_PRECALC_16_31_0(24, W2, W3, W4, W5, W6, Wtmp0, Wtmp1); |
| 282 |
R( b, c, d, e, a, F1, 9 ); W_PRECALC_16_31_1(25, W2, W3, W4, W5, W6, Wtmp0, Wtmp1); |
| 283 |
R( a, b, c, d, e, F1, 10 ); W_PRECALC_16_31_2(26, W2, W3, W4, W5, W6, Wtmp0, Wtmp1); |
| 284 |
R( e, a, b, c, d, F1, 11 ); W_PRECALC_16_31_3(27, W2, W3, W4, W5, W6, Wtmp0, Wtmp1); |
| 285 |
R( d, e, a, b, c, F1, 12 ); W_PRECALC_16_31_0(28, W1, W2, W3, W4, W5, Wtmp0, Wtmp1); |
| 286 |
R( c, d, e, a, b, F1, 13 ); W_PRECALC_16_31_1(29, W1, W2, W3, W4, W5, Wtmp0, Wtmp1); |
| 287 |
R( b, c, d, e, a, F1, 14 ); W_PRECALC_16_31_2(30, W1, W2, W3, W4, W5, Wtmp0, Wtmp1); |
| 288 |
R( a, b, c, d, e, F1, 15 ); W_PRECALC_16_31_3(31, W1, W2, W3, W4, W5, Wtmp0, Wtmp1); |
| 289 |
|
| 290 |
/* Transform 16-63 + Precalc 32-79. */ |
| 291 |
R( e, a, b, c, d, F1, 16 ); W_PRECALC_32_79_0(32, W0, W1, W2, W3, W4, W5, W6, W7, Wtmp0); |
| 292 |
R( d, e, a, b, c, F1, 17 ); W_PRECALC_32_79_1(33, W0, W1, W2, W3, W4, W5, W6, W7, Wtmp0); |
| 293 |
R( c, d, e, a, b, F1, 18 ); W_PRECALC_32_79_2(34, W0, W1, W2, W3, W4, W5, W6, W7, Wtmp0); |
| 294 |
R( b, c, d, e, a, F1, 19 ); W_PRECALC_32_79_3(35, W0, W1, W2, W3, W4, W5, W6, W7, Wtmp0); |
| 295 |
R( a, b, c, d, e, F2, 20 ); W_PRECALC_32_79_0(36, W7, W0, W1, W2, W3, W4, W5, W6, Wtmp0); |
| 296 |
R( e, a, b, c, d, F2, 21 ); W_PRECALC_32_79_1(37, W7, W0, W1, W2, W3, W4, W5, W6, Wtmp0); |
| 297 |
R( d, e, a, b, c, F2, 22 ); W_PRECALC_32_79_2(38, W7, W0, W1, W2, W3, W4, W5, W6, Wtmp0); |
| 298 |
R( c, d, e, a, b, F2, 23 ); W_PRECALC_32_79_3(39, W7, W0, W1, W2, W3, W4, W5, W6, Wtmp0); |
| 299 |
R( b, c, d, e, a, F2, 24 ); W_PRECALC_32_79_0(40, W6, W7, W0, W1, W2, W3, W4, W5, Wtmp0); |
| 300 |
R( a, b, c, d, e, F2, 25 ); W_PRECALC_32_79_1(41, W6, W7, W0, W1, W2, W3, W4, W5, Wtmp0); |
| 301 |
R( e, a, b, c, d, F2, 26 ); W_PRECALC_32_79_2(42, W6, W7, W0, W1, W2, W3, W4, W5, Wtmp0); |
| 302 |
R( d, e, a, b, c, F2, 27 ); W_PRECALC_32_79_3(43, W6, W7, W0, W1, W2, W3, W4, W5, Wtmp0); |
| 303 |
R( c, d, e, a, b, F2, 28 ); W_PRECALC_32_79_0(44, W5, W6, W7, W0, W1, W2, W3, W4, Wtmp0); |
| 304 |
R( b, c, d, e, a, F2, 29 ); W_PRECALC_32_79_1(45, W5, W6, W7, W0, W1, W2, W3, W4, Wtmp0); |
| 305 |
R( a, b, c, d, e, F2, 30 ); W_PRECALC_32_79_2(46, W5, W6, W7, W0, W1, W2, W3, W4, Wtmp0); |
| 306 |
R( e, a, b, c, d, F2, 31 ); W_PRECALC_32_79_3(47, W5, W6, W7, W0, W1, W2, W3, W4, Wtmp0); |
| 307 |
R( d, e, a, b, c, F2, 32 ); W_PRECALC_32_79_0(48, W4, W5, W6, W7, W0, W1, W2, W3, Wtmp0); |
| 308 |
R( c, d, e, a, b, F2, 33 ); W_PRECALC_32_79_1(49, W4, W5, W6, W7, W0, W1, W2, W3, Wtmp0); |
| 309 |
R( b, c, d, e, a, F2, 34 ); W_PRECALC_32_79_2(50, W4, W5, W6, W7, W0, W1, W2, W3, Wtmp0); |
| 310 |
R( a, b, c, d, e, F2, 35 ); W_PRECALC_32_79_3(51, W4, W5, W6, W7, W0, W1, W2, W3, Wtmp0); |
| 311 |
R( e, a, b, c, d, F2, 36 ); W_PRECALC_32_79_0(52, W3, W4, W5, W6, W7, W0, W1, W2, Wtmp0); |
| 312 |
R( d, e, a, b, c, F2, 37 ); W_PRECALC_32_79_1(53, W3, W4, W5, W6, W7, W0, W1, W2, Wtmp0); |
| 313 |
R( c, d, e, a, b, F2, 38 ); W_PRECALC_32_79_2(54, W3, W4, W5, W6, W7, W0, W1, W2, Wtmp0); |
| 314 |
R( b, c, d, e, a, F2, 39 ); W_PRECALC_32_79_3(55, W3, W4, W5, W6, W7, W0, W1, W2, Wtmp0); |
| 315 |
R( a, b, c, d, e, F3, 40 ); W_PRECALC_32_79_0(56, W2, W3, W4, W5, W6, W7, W0, W1, Wtmp0); |
| 316 |
R( e, a, b, c, d, F3, 41 ); W_PRECALC_32_79_1(57, W2, W3, W4, W5, W6, W7, W0, W1, Wtmp0); |
| 317 |
R( d, e, a, b, c, F3, 42 ); W_PRECALC_32_79_2(58, W2, W3, W4, W5, W6, W7, W0, W1, Wtmp0); |
| 318 |
R( c, d, e, a, b, F3, 43 ); W_PRECALC_32_79_3(59, W2, W3, W4, W5, W6, W7, W0, W1, Wtmp0); |
| 319 |
R( b, c, d, e, a, F3, 44 ); W_PRECALC_32_79_0(60, W1, W2, W3, W4, W5, W6, W7, W0, Wtmp0); |
| 320 |
R( a, b, c, d, e, F3, 45 ); W_PRECALC_32_79_1(61, W1, W2, W3, W4, W5, W6, W7, W0, Wtmp0); |
| 321 |
R( e, a, b, c, d, F3, 46 ); W_PRECALC_32_79_2(62, W1, W2, W3, W4, W5, W6, W7, W0, Wtmp0); |
| 322 |
R( d, e, a, b, c, F3, 47 ); W_PRECALC_32_79_3(63, W1, W2, W3, W4, W5, W6, W7, W0, Wtmp0); |
| 323 |
R( c, d, e, a, b, F3, 48 ); W_PRECALC_32_79_0(64, W0, W1, W2, W3, W4, W5, W6, W7, Wtmp0); |
| 324 |
R( b, c, d, e, a, F3, 49 ); W_PRECALC_32_79_1(65, W0, W1, W2, W3, W4, W5, W6, W7, Wtmp0); |
| 325 |
R( a, b, c, d, e, F3, 50 ); W_PRECALC_32_79_2(66, W0, W1, W2, W3, W4, W5, W6, W7, Wtmp0); |
| 326 |
R( e, a, b, c, d, F3, 51 ); W_PRECALC_32_79_3(67, W0, W1, W2, W3, W4, W5, W6, W7, Wtmp0); |
| 327 |
R( d, e, a, b, c, F3, 52 ); W_PRECALC_32_79_0(68, W7, W0, W1, W2, W3, W4, W5, W6, Wtmp0); |
| 328 |
R( c, d, e, a, b, F3, 53 ); W_PRECALC_32_79_1(69, W7, W0, W1, W2, W3, W4, W5, W6, Wtmp0); |
| 329 |
R( b, c, d, e, a, F3, 54 ); W_PRECALC_32_79_2(70, W7, W0, W1, W2, W3, W4, W5, W6, Wtmp0); |
| 330 |
R( a, b, c, d, e, F3, 55 ); W_PRECALC_32_79_3(71, W7, W0, W1, W2, W3, W4, W5, W6, Wtmp0); |
| 331 |
R( e, a, b, c, d, F3, 56 ); W_PRECALC_32_79_0(72, W6, W7, W0, W1, W2, W3, W4, W5, Wtmp0); |
| 332 |
R( d, e, a, b, c, F3, 57 ); W_PRECALC_32_79_1(73, W6, W7, W0, W1, W2, W3, W4, W5, Wtmp0); |
| 333 |
R( c, d, e, a, b, F3, 58 ); W_PRECALC_32_79_2(74, W6, W7, W0, W1, W2, W3, W4, W5, Wtmp0); |
| 334 |
R( b, c, d, e, a, F3, 59 ); W_PRECALC_32_79_3(75, W6, W7, W0, W1, W2, W3, W4, W5, Wtmp0); |
| 335 |
R( a, b, c, d, e, F4, 60 ); W_PRECALC_32_79_0(76, W5, W6, W7, W0, W1, W2, W3, W4, Wtmp0); |
| 336 |
R( e, a, b, c, d, F4, 61 ); W_PRECALC_32_79_1(77, W5, W6, W7, W0, W1, W2, W3, W4, Wtmp0); |
| 337 |
R( d, e, a, b, c, F4, 62 ); W_PRECALC_32_79_2(78, W5, W6, W7, W0, W1, W2, W3, W4, Wtmp0); |
| 338 |
R( c, d, e, a, b, F4, 63 ); W_PRECALC_32_79_3(79, W5, W6, W7, W0, W1, W2, W3, W4, Wtmp0); |
| 339 |
|
| 340 |
decq RNBLKS; |
| 341 |
jz .Lend; |
| 342 |
|
| 343 |
/* Transform 64-79 + Precalc 0-15 of next block. */ |
| 344 |
R( b, c, d, e, a, F4, 64 ); W_PRECALC_00_15_0(0, W0, Wtmp0); |
| 345 |
R( a, b, c, d, e, F4, 65 ); W_PRECALC_00_15_1(1, W0, Wtmp0); |
| 346 |
R( e, a, b, c, d, F4, 66 ); W_PRECALC_00_15_2(2, W0, Wtmp0); |
| 347 |
R( d, e, a, b, c, F4, 67 ); W_PRECALC_00_15_3(3, W0, Wtmp0); |
| 348 |
R( c, d, e, a, b, F4, 68 ); W_PRECALC_00_15_0(4, W7, Wtmp0); |
| 349 |
R( b, c, d, e, a, F4, 69 ); W_PRECALC_00_15_1(5, W7, Wtmp0); |
| 350 |
R( a, b, c, d, e, F4, 70 ); W_PRECALC_00_15_2(6, W7, Wtmp0); |
| 351 |
R( e, a, b, c, d, F4, 71 ); W_PRECALC_00_15_3(7, W7, Wtmp0); |
| 352 |
R( d, e, a, b, c, F4, 72 ); W_PRECALC_00_15_0(8, W6, Wtmp0); |
| 353 |
R( c, d, e, a, b, F4, 73 ); W_PRECALC_00_15_1(9, W6, Wtmp0); |
| 354 |
R( b, c, d, e, a, F4, 74 ); W_PRECALC_00_15_2(10, W6, Wtmp0); |
| 355 |
R( a, b, c, d, e, F4, 75 ); W_PRECALC_00_15_3(11, W6, Wtmp0); |
| 356 |
R( e, a, b, c, d, F4, 76 ); W_PRECALC_00_15_0(12, W5, Wtmp0); |
| 357 |
R( d, e, a, b, c, F4, 77 ); W_PRECALC_00_15_1(13, W5, Wtmp0); |
| 358 |
R( c, d, e, a, b, F4, 78 ); |
| 359 |
addl state_h0(RSTATE), a; W_PRECALC_00_15_2(14, W5, Wtmp0); |
| 360 |
R( b, c, d, e, a, F4, 79 ); W_PRECALC_00_15_3(15, W5, Wtmp0); |
| 361 |
|
| 362 |
/* Update the chaining variables. */ |
| 363 |
addl state_h3(RSTATE), d; |
| 364 |
addl state_h2(RSTATE), c; |
| 365 |
addl state_h1(RSTATE), b; |
| 366 |
addl state_h4(RSTATE), e; |
| 367 |
|
| 368 |
movl d, state_h3(RSTATE); |
| 369 |
movl c, state_h2(RSTATE); |
| 370 |
movl b, state_h1(RSTATE); |
| 371 |
movl a, state_h0(RSTATE); |
| 372 |
movl e, state_h4(RSTATE); |
| 373 |
|
| 374 |
jmp .Loop; |
| 375 |
|
| 376 |
.align 16 |
| 377 |
.Lend: |
| 378 |
vzeroall; |
| 379 |
|
| 380 |
/* Transform 64-79 + burn stack */ |
| 381 |
R( b, c, d, e, a, F4, 64 ); |
| 382 |
R( a, b, c, d, e, F4, 65 ); |
| 383 |
R( e, a, b, c, d, F4, 66 ); |
| 384 |
R( d, e, a, b, c, F4, 67 ); |
| 385 |
R( c, d, e, a, b, F4, 68 ); |
| 386 |
R( b, c, d, e, a, F4, 69 ); |
| 387 |
R( a, b, c, d, e, F4, 70 ); |
| 388 |
R( e, a, b, c, d, F4, 71 ); |
| 389 |
R( d, e, a, b, c, F4, 72 ); |
| 390 |
R( c, d, e, a, b, F4, 73 ); |
| 391 |
R( b, c, d, e, a, F4, 74 ); |
| 392 |
R( a, b, c, d, e, F4, 75 ); |
| 393 |
R( e, a, b, c, d, F4, 76 ); vmovdqa %xmm0, (0*16)(%rsp); |
| 394 |
R( d, e, a, b, c, F4, 77 ); vmovdqa %xmm0, (1*16)(%rsp); |
| 395 |
R( c, d, e, a, b, F4, 78 ); vmovdqa %xmm0, (2*16)(%rsp); |
| 396 |
addl state_h0(RSTATE), a; |
| 397 |
R( b, c, d, e, a, F4, 79 ); |
| 398 |
|
| 399 |
/* 16*4/16-1 = 3 */ |
| 400 |
vmovdqa %xmm0, (3*16)(%rsp); |
| 401 |
|
| 402 |
/* Update the chaining variables. */ |
| 403 |
addl state_h3(RSTATE), d; |
| 404 |
addl state_h2(RSTATE), c; |
| 405 |
addl state_h1(RSTATE), b; |
| 406 |
addl state_h4(RSTATE), e; |
| 407 |
|
| 408 |
movl d, state_h3(RSTATE); |
| 409 |
movl c, state_h2(RSTATE); |
| 410 |
movl b, state_h1(RSTATE); |
| 411 |
movl a, state_h0(RSTATE); |
| 412 |
movl e, state_h4(RSTATE); |
| 413 |
|
| 414 |
movq ROLDSTACK, %rsp; |
| 415 |
CFI_REGISTER(ROLDSTACK, %rsp); |
| 416 |
CFI_DEF_CFA_REGISTER(%rsp); |
| 417 |
|
| 418 |
popq %rbp; |
| 419 |
CFI_POP(%rbp); |
| 420 |
popq %rbx; |
| 421 |
CFI_POP(%rbx); |
| 422 |
|
| 423 |
/* stack already burned */ |
| 424 |
xorl %eax, %eax; |
| 425 |
|
| 426 |
.Lret: |
| 427 |
ret_spec_stop; |
| 428 |
CFI_ENDPROC(); |
| 429 |
ELF(.size _gcry_sha1_transform_amd64_avx, |
| 430 |
.-_gcry_sha1_transform_amd64_avx;) |
| 431 |
|
| 432 |
#endif |
| 433 |
#endif |