| 1 |
/* sha1-avx2-bmi2-amd64.S - Intel AVX2/BMI2 accelerated SHA-1 transform function |
| 2 |
* Copyright (C) 2019 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_BMI2) && defined(HAVE_GCC_INLINE_ASM_AVX) && \ |
| 35 |
defined(HAVE_GCC_INLINE_ASM_AVX2) && defined(USE_SHA1) |
| 36 |
|
| 37 |
#include "asm-common-amd64.h" |
| 38 |
|
| 39 |
|
| 40 |
/* Context structure */ |
| 41 |
|
| 42 |
#define state_h0 0 |
| 43 |
#define state_h1 4 |
| 44 |
#define state_h2 8 |
| 45 |
#define state_h3 12 |
| 46 |
#define state_h4 16 |
| 47 |
|
| 48 |
|
| 49 |
/* Constants */ |
| 50 |
|
| 51 |
SECTION_RODATA |
| 52 |
|
| 53 |
#define WK_STACK_WORDS (80 * 2) |
| 54 |
|
| 55 |
ELF(.type _sha1_avx2_bmi2_consts,@object) |
| 56 |
_sha1_avx2_bmi2_consts: |
| 57 |
|
| 58 |
.align 16 |
| 59 |
.Lbswap_shufb_ctl: |
| 60 |
.long 0x00010203, 0x04050607, 0x08090a0b, 0x0c0d0e0f |
| 61 |
|
| 62 |
.LK1: .long 0x5A827999 |
| 63 |
.LK2: .long 0x6ED9EBA1 |
| 64 |
.LK3: .long 0x8F1BBCDC |
| 65 |
.LK4: .long 0xCA62C1D6 |
| 66 |
|
| 67 |
|
| 68 |
/* Register macros */ |
| 69 |
|
| 70 |
#define RSTATE %r8 |
| 71 |
#define RDATA %r9 |
| 72 |
#define ROLDSTACK %r10 |
| 73 |
#define RNBLKS %r11 |
| 74 |
|
| 75 |
#define a %eax |
| 76 |
#define b %ebx |
| 77 |
#define c %ecx |
| 78 |
#define d %edx |
| 79 |
#define e %edi |
| 80 |
#define ne %r12d |
| 81 |
|
| 82 |
#define RT0 %esi |
| 83 |
#define RT1 %ebp |
| 84 |
|
| 85 |
#define Wtmp0 %ymm0 |
| 86 |
#define Wtmp1 %ymm1 |
| 87 |
#define Wtmp0x %xmm0 |
| 88 |
#define Wtmp1x %xmm1 |
| 89 |
|
| 90 |
#define W0 %ymm2 |
| 91 |
#define W1 %ymm3 |
| 92 |
#define W2 %ymm4 |
| 93 |
#define W3 %ymm5 |
| 94 |
#define W4 %ymm6 |
| 95 |
#define W5 %ymm7 |
| 96 |
#define W6 %ymm8 |
| 97 |
#define W7 %ymm9 |
| 98 |
|
| 99 |
#define BSWAP_REG %ymm10 |
| 100 |
|
| 101 |
#define K1 %ymm11 |
| 102 |
#define K2 %ymm12 |
| 103 |
#define K3 %ymm13 |
| 104 |
#define K4 %ymm14 |
| 105 |
|
| 106 |
|
| 107 |
/* Round function macros. */ |
| 108 |
|
| 109 |
#define WK(i,block) ((block) * 16 + ((i) / 4) * 32 + ((i) % 4) * 4)(%rsp) |
| 110 |
#define PRE_WK(i) ((i) * 4 * 2)(%rsp) |
| 111 |
|
| 112 |
#define R_F1(a,b,c,d,e,i,block) \ |
| 113 |
movl c, RT0; \ |
| 114 |
andn d, b, RT1; \ |
| 115 |
addl WK(i,block), e; \ |
| 116 |
andl b, RT0; \ |
| 117 |
leal (a,ne), a; \ |
| 118 |
rorxl $2, b, b; \ |
| 119 |
addl RT1, e; \ |
| 120 |
rorxl $27, a, ne; \ |
| 121 |
addl RT0, e; |
| 122 |
|
| 123 |
#define R_F2(a,b,c,d,e,i,block) \ |
| 124 |
addl WK(i,block), e; \ |
| 125 |
movl c, RT0; \ |
| 126 |
xorl b, RT0; \ |
| 127 |
leal (a,ne), a; \ |
| 128 |
rorxl $2, b, b; \ |
| 129 |
xorl d, RT0; \ |
| 130 |
addl RT0, e; \ |
| 131 |
rorxl $27, a, ne; |
| 132 |
|
| 133 |
#define R_F3(a,b,c,d,e,i,block) \ |
| 134 |
movl c, RT0; \ |
| 135 |
addl WK(i,block), e; \ |
| 136 |
movl b, RT1; \ |
| 137 |
xorl b, RT0; \ |
| 138 |
leal (a,ne), a; \ |
| 139 |
rorxl $2, b, b; \ |
| 140 |
andl c, RT1; \ |
| 141 |
addl RT1, e; \ |
| 142 |
andl d, RT0; \ |
| 143 |
rorxl $27, a, ne; \ |
| 144 |
addl RT0, e; |
| 145 |
|
| 146 |
#define R_F4(a,b,c,d,e,i,block) R_F2(a,b,c,d,e,i,block) |
| 147 |
|
| 148 |
#define R(a,b,c,d,e,f,i,block) \ |
| 149 |
R_##f(a,b,c,d,e,i,block) |
| 150 |
|
| 151 |
|
| 152 |
/* Input expansion macros. */ |
| 153 |
|
| 154 |
#define W_PRECALC_00_15_0(i, W, tmp0) \ |
| 155 |
vmovdqu (4*(i))(RDATA), tmp0##x; \ |
| 156 |
vinserti128 $1, (4*(i) + 64)(RDATA), tmp0, tmp0; |
| 157 |
|
| 158 |
#define W_PRECALC_00_15_1(i, W, tmp0) \ |
| 159 |
vpshufb BSWAP_REG, tmp0, W; |
| 160 |
|
| 161 |
#define W_PRECALC_00_15_2(i, W, tmp0, K) \ |
| 162 |
vpaddd K, W, tmp0; |
| 163 |
|
| 164 |
#define W_PRECALC_00_15_3(i, W, tmp0) \ |
| 165 |
vmovdqa tmp0, PRE_WK((i)&~3); |
| 166 |
|
| 167 |
#define W_PRECALC_16_31_0(i, W, W_m04, W_m08, W_m12, W_m16, tmp0, tmp1) \ |
| 168 |
vpalignr $8, W_m16, W_m12, W; \ |
| 169 |
vpsrldq $4, W_m04, tmp0; \ |
| 170 |
vpxor W_m08, W, W; |
| 171 |
|
| 172 |
#define W_PRECALC_16_31_1(i, W, W_m04, W_m08, W_m12, W_m16, tmp0, tmp1) \ |
| 173 |
vpxor W_m16, tmp0, tmp0; \ |
| 174 |
vpxor tmp0, W, W; \ |
| 175 |
vpslld $1, W, tmp0; \ |
| 176 |
vpslldq $12, W, tmp1; \ |
| 177 |
vpsrld $31, W, W; |
| 178 |
|
| 179 |
#define W_PRECALC_16_31_2(i, W, W_m04, W_m08, W_m12, W_m16, tmp0, tmp1) \ |
| 180 |
vpor W, tmp0, tmp0; \ |
| 181 |
vpsrld $30, tmp1, W; \ |
| 182 |
vpslld $2, tmp1, tmp1; |
| 183 |
|
| 184 |
#define W_PRECALC_16_31_3(i, W, W_m04, W_m08, W_m12, W_m16, tmp0, tmp1, K) \ |
| 185 |
vpxor W, tmp0, tmp0; \ |
| 186 |
vpxor tmp1, tmp0, W; \ |
| 187 |
vpaddd K, W, tmp0; \ |
| 188 |
vmovdqa tmp0, PRE_WK((i)&~3); |
| 189 |
|
| 190 |
#define W_PRECALC_32_79_0(i, W, W_m04, W_m08, W_m12, W_m16, W_m20, W_m24, W_m28, tmp0) \ |
| 191 |
vpxor W_m28, W, W; \ |
| 192 |
vpalignr $8, W_m08, W_m04, tmp0; |
| 193 |
|
| 194 |
#define W_PRECALC_32_79_1(i, W, W_m04, W_m08, W_m12, W_m16, W_m20, W_m24, W_m28, tmp0) \ |
| 195 |
vpxor W_m16, W, W; \ |
| 196 |
vpxor tmp0, W, W; |
| 197 |
|
| 198 |
#define W_PRECALC_32_79_2(i, W, W_m04, W_m08, W_m12, W_m16, W_m20, W_m24, W_m28, tmp0) \ |
| 199 |
vpsrld $30, W, tmp0; \ |
| 200 |
vpslld $2, W, W; |
| 201 |
|
| 202 |
#define W_PRECALC_32_79_3(i, W, W_m04, W_m08, W_m12, W_m16, W_m20, W_m24, W_m28, tmp0, K) \ |
| 203 |
vpor W, tmp0, W; \ |
| 204 |
vpaddd K, W, tmp0; \ |
| 205 |
vmovdqa tmp0, PRE_WK((i)&~3); |
| 206 |
|
| 207 |
.text |
| 208 |
|
| 209 |
/* |
| 210 |
* Transform 2*nblks*64 bytes (2*nblks*16 32-bit words) at DATA. |
| 211 |
* |
| 212 |
* unsigned int |
| 213 |
* _gcry_sha1_transform_amd64_avx2_bmi2 (void *ctx, const unsigned char *data, |
| 214 |
* size_t nblks) |
| 215 |
*/ |
| 216 |
.globl _gcry_sha1_transform_amd64_avx2_bmi2 |
| 217 |
ELF(.type _gcry_sha1_transform_amd64_avx2_bmi2,@function) |
| 218 |
.align 16 |
| 219 |
_gcry_sha1_transform_amd64_avx2_bmi2: |
| 220 |
/* input: |
| 221 |
* %rdi: ctx, CTX |
| 222 |
* %rsi: data (64*nblks bytes) |
| 223 |
* %rdx: nblks (multiple of 2, larger than 0) |
| 224 |
*/ |
| 225 |
CFI_STARTPROC(); |
| 226 |
|
| 227 |
vzeroupper; |
| 228 |
|
| 229 |
movq %rdx, RNBLKS; |
| 230 |
movq %rdi, RSTATE; |
| 231 |
movq %rsi, RDATA; |
| 232 |
pushq %rbx; |
| 233 |
CFI_PUSH(%rbx); |
| 234 |
pushq %rbp; |
| 235 |
CFI_PUSH(%rbp); |
| 236 |
pushq %r12; |
| 237 |
CFI_PUSH(%r12); |
| 238 |
|
| 239 |
movq %rsp, ROLDSTACK; |
| 240 |
CFI_DEF_CFA_REGISTER(ROLDSTACK); |
| 241 |
|
| 242 |
subq $(WK_STACK_WORDS*4), %rsp; |
| 243 |
andq $(~63), %rsp; |
| 244 |
|
| 245 |
/* Get the values of the chaining variables. */ |
| 246 |
movl state_h0(RSTATE), a; |
| 247 |
movl state_h1(RSTATE), b; |
| 248 |
movl state_h2(RSTATE), c; |
| 249 |
movl state_h3(RSTATE), d; |
| 250 |
movl state_h4(RSTATE), e; |
| 251 |
xorl ne, ne; |
| 252 |
|
| 253 |
vbroadcasti128 .Lbswap_shufb_ctl rRIP, BSWAP_REG; |
| 254 |
vpbroadcastd .LK1 rRIP, K1; |
| 255 |
vpbroadcastd .LK2 rRIP, K2; |
| 256 |
vpbroadcastd .LK3 rRIP, K3; |
| 257 |
vpbroadcastd .LK4 rRIP, K4; |
| 258 |
|
| 259 |
/* Precalc 0-31 for block 1 & 2. */ |
| 260 |
W_PRECALC_00_15_0(0, W0, Wtmp0); |
| 261 |
W_PRECALC_00_15_1(1, W0, Wtmp0); |
| 262 |
W_PRECALC_00_15_2(2, W0, Wtmp0, K1); |
| 263 |
W_PRECALC_00_15_3(3, W0, Wtmp0); |
| 264 |
W_PRECALC_00_15_0(4, W7, Wtmp0); |
| 265 |
W_PRECALC_00_15_1(5, W7, Wtmp0); |
| 266 |
W_PRECALC_00_15_2(6, W7, Wtmp0, K1); |
| 267 |
W_PRECALC_00_15_3(7, W7, Wtmp0); |
| 268 |
W_PRECALC_00_15_0(8, W6, Wtmp0); |
| 269 |
W_PRECALC_00_15_1(9, W6, Wtmp0); |
| 270 |
W_PRECALC_00_15_2(10, W6, Wtmp0, K1); |
| 271 |
W_PRECALC_00_15_3(11, W6, Wtmp0); |
| 272 |
W_PRECALC_00_15_0(12, W5, Wtmp0); |
| 273 |
W_PRECALC_00_15_1(13, W5, Wtmp0); |
| 274 |
W_PRECALC_00_15_2(14, W5, Wtmp0, K1); |
| 275 |
W_PRECALC_00_15_3(15, W5, Wtmp0); |
| 276 |
W_PRECALC_16_31_0(16, W4, W5, W6, W7, W0, Wtmp0, Wtmp1); |
| 277 |
W_PRECALC_16_31_1(17, W4, W5, W6, W7, W0, Wtmp0, Wtmp1); |
| 278 |
W_PRECALC_16_31_2(18, W4, W5, W6, W7, W0, Wtmp0, Wtmp1); |
| 279 |
W_PRECALC_16_31_3(19, W4, W5, W6, W7, W0, Wtmp0, Wtmp1, K1); |
| 280 |
W_PRECALC_16_31_0(20, W3, W4, W5, W6, W7, Wtmp0, Wtmp1); |
| 281 |
W_PRECALC_16_31_1(21, W3, W4, W5, W6, W7, Wtmp0, Wtmp1); |
| 282 |
W_PRECALC_16_31_2(22, W3, W4, W5, W6, W7, Wtmp0, Wtmp1); |
| 283 |
W_PRECALC_16_31_3(23, W3, W4, W5, W6, W7, Wtmp0, Wtmp1, K2); |
| 284 |
W_PRECALC_16_31_0(24, W2, W3, W4, W5, W6, Wtmp0, Wtmp1); |
| 285 |
W_PRECALC_16_31_1(25, W2, W3, W4, W5, W6, Wtmp0, Wtmp1); |
| 286 |
W_PRECALC_16_31_2(26, W2, W3, W4, W5, W6, Wtmp0, Wtmp1); |
| 287 |
W_PRECALC_16_31_3(27, W2, W3, W4, W5, W6, Wtmp0, Wtmp1, K2); |
| 288 |
W_PRECALC_16_31_0(28, W1, W2, W3, W4, W5, Wtmp0, Wtmp1); |
| 289 |
W_PRECALC_16_31_1(29, W1, W2, W3, W4, W5, Wtmp0, Wtmp1); |
| 290 |
W_PRECALC_16_31_2(30, W1, W2, W3, W4, W5, Wtmp0, Wtmp1); |
| 291 |
W_PRECALC_16_31_3(31, W1, W2, W3, W4, W5, Wtmp0, Wtmp1, K2); |
| 292 |
|
| 293 |
.align 8 |
| 294 |
.Loop: |
| 295 |
addq $(2 * 64), RDATA; |
| 296 |
|
| 297 |
/* Transform 0-15 for block 1 + Precalc 32-47 for block 1 & 2. */ |
| 298 |
R( a, b, c, d, e, F1, 0, 0 ); W_PRECALC_32_79_0(32, W0, W1, W2, W3, W4, W5, W6, W7, Wtmp0); |
| 299 |
R( e, a, b, c, d, F1, 1, 0 ); W_PRECALC_32_79_1(33, W0, W1, W2, W3, W4, W5, W6, W7, Wtmp0); |
| 300 |
R( d, e, a, b, c, F1, 2, 0 ); W_PRECALC_32_79_2(34, W0, W1, W2, W3, W4, W5, W6, W7, Wtmp0); |
| 301 |
R( c, d, e, a, b, F1, 3, 0 ); W_PRECALC_32_79_3(35, W0, W1, W2, W3, W4, W5, W6, W7, Wtmp0, K2); |
| 302 |
R( b, c, d, e, a, F1, 4, 0 ); W_PRECALC_32_79_0(36, W7, W0, W1, W2, W3, W4, W5, W6, Wtmp0); |
| 303 |
R( a, b, c, d, e, F1, 5, 0 ); W_PRECALC_32_79_1(37, W7, W0, W1, W2, W3, W4, W5, W6, Wtmp0); |
| 304 |
R( e, a, b, c, d, F1, 6, 0 ); W_PRECALC_32_79_2(38, W7, W0, W1, W2, W3, W4, W5, W6, Wtmp0); |
| 305 |
R( d, e, a, b, c, F1, 7, 0 ); W_PRECALC_32_79_3(39, W7, W0, W1, W2, W3, W4, W5, W6, Wtmp0, K2); |
| 306 |
R( c, d, e, a, b, F1, 8, 0 ); W_PRECALC_32_79_0(40, W6, W7, W0, W1, W2, W3, W4, W5, Wtmp0); |
| 307 |
R( b, c, d, e, a, F1, 9, 0 ); W_PRECALC_32_79_1(41, W6, W7, W0, W1, W2, W3, W4, W5, Wtmp0); |
| 308 |
R( a, b, c, d, e, F1, 10, 0 ); W_PRECALC_32_79_2(42, W6, W7, W0, W1, W2, W3, W4, W5, Wtmp0); |
| 309 |
R( e, a, b, c, d, F1, 11, 0 ); W_PRECALC_32_79_3(43, W6, W7, W0, W1, W2, W3, W4, W5, Wtmp0, K3); |
| 310 |
R( d, e, a, b, c, F1, 12, 0 ); W_PRECALC_32_79_0(44, W5, W6, W7, W0, W1, W2, W3, W4, Wtmp0); |
| 311 |
R( c, d, e, a, b, F1, 13, 0 ); W_PRECALC_32_79_1(45, W5, W6, W7, W0, W1, W2, W3, W4, Wtmp0); |
| 312 |
R( b, c, d, e, a, F1, 14, 0 ); W_PRECALC_32_79_2(46, W5, W6, W7, W0, W1, W2, W3, W4, Wtmp0); |
| 313 |
R( a, b, c, d, e, F1, 15, 0 ); W_PRECALC_32_79_3(47, W5, W6, W7, W0, W1, W2, W3, W4, Wtmp0, K3); |
| 314 |
|
| 315 |
/* Transform 16-47 for block 1 + Precalc 48-79 for block 1 & 2. */ |
| 316 |
R( e, a, b, c, d, F1, 16, 0 ); W_PRECALC_32_79_0(48, W4, W5, W6, W7, W0, W1, W2, W3, Wtmp0); |
| 317 |
R( d, e, a, b, c, F1, 17, 0 ); W_PRECALC_32_79_1(49, W4, W5, W6, W7, W0, W1, W2, W3, Wtmp0); |
| 318 |
R( c, d, e, a, b, F1, 18, 0 ); W_PRECALC_32_79_2(50, W4, W5, W6, W7, W0, W1, W2, W3, Wtmp0); |
| 319 |
R( b, c, d, e, a, F1, 19, 0 ); W_PRECALC_32_79_3(51, W4, W5, W6, W7, W0, W1, W2, W3, Wtmp0, K3); |
| 320 |
R( a, b, c, d, e, F2, 20, 0 ); W_PRECALC_32_79_0(52, W3, W4, W5, W6, W7, W0, W1, W2, Wtmp0); |
| 321 |
R( e, a, b, c, d, F2, 21, 0 ); W_PRECALC_32_79_1(53, W3, W4, W5, W6, W7, W0, W1, W2, Wtmp0); |
| 322 |
R( d, e, a, b, c, F2, 22, 0 ); W_PRECALC_32_79_2(54, W3, W4, W5, W6, W7, W0, W1, W2, Wtmp0); |
| 323 |
R( c, d, e, a, b, F2, 23, 0 ); W_PRECALC_32_79_3(55, W3, W4, W5, W6, W7, W0, W1, W2, Wtmp0, K3); |
| 324 |
R( b, c, d, e, a, F2, 24, 0 ); W_PRECALC_32_79_0(56, W2, W3, W4, W5, W6, W7, W0, W1, Wtmp0); |
| 325 |
R( a, b, c, d, e, F2, 25, 0 ); W_PRECALC_32_79_1(57, W2, W3, W4, W5, W6, W7, W0, W1, Wtmp0); |
| 326 |
R( e, a, b, c, d, F2, 26, 0 ); W_PRECALC_32_79_2(58, W2, W3, W4, W5, W6, W7, W0, W1, Wtmp0); |
| 327 |
R( d, e, a, b, c, F2, 27, 0 ); W_PRECALC_32_79_3(59, W2, W3, W4, W5, W6, W7, W0, W1, Wtmp0, K3); |
| 328 |
R( c, d, e, a, b, F2, 28, 0 ); W_PRECALC_32_79_0(60, W1, W2, W3, W4, W5, W6, W7, W0, Wtmp0); |
| 329 |
R( b, c, d, e, a, F2, 29, 0 ); W_PRECALC_32_79_1(61, W1, W2, W3, W4, W5, W6, W7, W0, Wtmp0); |
| 330 |
R( a, b, c, d, e, F2, 30, 0 ); W_PRECALC_32_79_2(62, W1, W2, W3, W4, W5, W6, W7, W0, Wtmp0); |
| 331 |
R( e, a, b, c, d, F2, 31, 0 ); W_PRECALC_32_79_3(63, W1, W2, W3, W4, W5, W6, W7, W0, Wtmp0, K4); |
| 332 |
R( d, e, a, b, c, F2, 32, 0 ); W_PRECALC_32_79_0(64, W0, W1, W2, W3, W4, W5, W6, W7, Wtmp0); |
| 333 |
R( c, d, e, a, b, F2, 33, 0 ); W_PRECALC_32_79_1(65, W0, W1, W2, W3, W4, W5, W6, W7, Wtmp0); |
| 334 |
R( b, c, d, e, a, F2, 34, 0 ); W_PRECALC_32_79_2(66, W0, W1, W2, W3, W4, W5, W6, W7, Wtmp0); |
| 335 |
R( a, b, c, d, e, F2, 35, 0 ); W_PRECALC_32_79_3(67, W0, W1, W2, W3, W4, W5, W6, W7, Wtmp0, K4); |
| 336 |
R( e, a, b, c, d, F2, 36, 0 ); W_PRECALC_32_79_0(68, W7, W0, W1, W2, W3, W4, W5, W6, Wtmp0); |
| 337 |
R( d, e, a, b, c, F2, 37, 0 ); W_PRECALC_32_79_1(69, W7, W0, W1, W2, W3, W4, W5, W6, Wtmp0); |
| 338 |
R( c, d, e, a, b, F2, 38, 0 ); W_PRECALC_32_79_2(70, W7, W0, W1, W2, W3, W4, W5, W6, Wtmp0); |
| 339 |
R( b, c, d, e, a, F2, 39, 0 ); W_PRECALC_32_79_3(71, W7, W0, W1, W2, W3, W4, W5, W6, Wtmp0, K4); |
| 340 |
R( a, b, c, d, e, F3, 40, 0 ); W_PRECALC_32_79_0(72, W6, W7, W0, W1, W2, W3, W4, W5, Wtmp0); |
| 341 |
R( e, a, b, c, d, F3, 41, 0 ); W_PRECALC_32_79_1(73, W6, W7, W0, W1, W2, W3, W4, W5, Wtmp0); |
| 342 |
R( d, e, a, b, c, F3, 42, 0 ); W_PRECALC_32_79_2(74, W6, W7, W0, W1, W2, W3, W4, W5, Wtmp0); |
| 343 |
R( c, d, e, a, b, F3, 43, 0 ); W_PRECALC_32_79_3(75, W6, W7, W0, W1, W2, W3, W4, W5, Wtmp0, K4); |
| 344 |
R( b, c, d, e, a, F3, 44, 0 ); W_PRECALC_32_79_0(76, W5, W6, W7, W0, W1, W2, W3, W4, Wtmp0); |
| 345 |
R( a, b, c, d, e, F3, 45, 0 ); W_PRECALC_32_79_1(77, W5, W6, W7, W0, W1, W2, W3, W4, Wtmp0); |
| 346 |
R( e, a, b, c, d, F3, 46, 0 ); W_PRECALC_32_79_2(78, W5, W6, W7, W0, W1, W2, W3, W4, Wtmp0); |
| 347 |
R( d, e, a, b, c, F3, 47, 0 ); W_PRECALC_32_79_3(79, W5, W6, W7, W0, W1, W2, W3, W4, Wtmp0, K4); |
| 348 |
|
| 349 |
/* Transform 48-79 for block 1. */ |
| 350 |
R( c, d, e, a, b, F3, 48, 0 ); |
| 351 |
R( b, c, d, e, a, F3, 49, 0 ); |
| 352 |
R( a, b, c, d, e, F3, 50, 0 ); |
| 353 |
R( e, a, b, c, d, F3, 51, 0 ); |
| 354 |
R( d, e, a, b, c, F3, 52, 0 ); |
| 355 |
R( c, d, e, a, b, F3, 53, 0 ); |
| 356 |
R( b, c, d, e, a, F3, 54, 0 ); |
| 357 |
R( a, b, c, d, e, F3, 55, 0 ); |
| 358 |
R( e, a, b, c, d, F3, 56, 0 ); |
| 359 |
R( d, e, a, b, c, F3, 57, 0 ); |
| 360 |
R( c, d, e, a, b, F3, 58, 0 ); |
| 361 |
R( b, c, d, e, a, F3, 59, 0 ); |
| 362 |
R( a, b, c, d, e, F4, 60, 0 ); |
| 363 |
R( e, a, b, c, d, F4, 61, 0 ); |
| 364 |
R( d, e, a, b, c, F4, 62, 0 ); |
| 365 |
R( c, d, e, a, b, F4, 63, 0 ); |
| 366 |
R( b, c, d, e, a, F4, 64, 0 ); |
| 367 |
R( a, b, c, d, e, F4, 65, 0 ); |
| 368 |
R( e, a, b, c, d, F4, 66, 0 ); |
| 369 |
R( d, e, a, b, c, F4, 67, 0 ); |
| 370 |
R( c, d, e, a, b, F4, 68, 0 ); |
| 371 |
R( b, c, d, e, a, F4, 69, 0 ); |
| 372 |
R( a, b, c, d, e, F4, 70, 0 ); |
| 373 |
R( e, a, b, c, d, F4, 71, 0 ); |
| 374 |
R( d, e, a, b, c, F4, 72, 0 ); |
| 375 |
R( c, d, e, a, b, F4, 73, 0 ); |
| 376 |
R( b, c, d, e, a, F4, 74, 0 ); |
| 377 |
R( a, b, c, d, e, F4, 75, 0 ); |
| 378 |
R( e, a, b, c, d, F4, 76, 0 ); |
| 379 |
R( d, e, a, b, c, F4, 77, 0 ); |
| 380 |
R( c, d, e, a, b, F4, 78, 0 ); |
| 381 |
addl state_h0(RSTATE), a; |
| 382 |
R( b, c, d, e, a, F4, 79, 0 ); |
| 383 |
addl ne, a; |
| 384 |
xorl ne, ne; |
| 385 |
|
| 386 |
/* Update the chaining variables. */ |
| 387 |
addl state_h3(RSTATE), d; |
| 388 |
addl state_h2(RSTATE), c; |
| 389 |
addl state_h1(RSTATE), b; |
| 390 |
addl state_h4(RSTATE), e; |
| 391 |
|
| 392 |
movl d, state_h3(RSTATE); |
| 393 |
movl c, state_h2(RSTATE); |
| 394 |
movl b, state_h1(RSTATE); |
| 395 |
movl a, state_h0(RSTATE); |
| 396 |
movl e, state_h4(RSTATE); |
| 397 |
|
| 398 |
/* Transform 0-47 for block 2. */ |
| 399 |
R( a, b, c, d, e, F1, 0, 1 ); |
| 400 |
R( e, a, b, c, d, F1, 1, 1 ); |
| 401 |
R( d, e, a, b, c, F1, 2, 1 ); |
| 402 |
R( c, d, e, a, b, F1, 3, 1 ); |
| 403 |
R( b, c, d, e, a, F1, 4, 1 ); |
| 404 |
R( a, b, c, d, e, F1, 5, 1 ); |
| 405 |
R( e, a, b, c, d, F1, 6, 1 ); |
| 406 |
R( d, e, a, b, c, F1, 7, 1 ); |
| 407 |
R( c, d, e, a, b, F1, 8, 1 ); |
| 408 |
R( b, c, d, e, a, F1, 9, 1 ); |
| 409 |
R( a, b, c, d, e, F1, 10, 1 ); |
| 410 |
R( e, a, b, c, d, F1, 11, 1 ); |
| 411 |
R( d, e, a, b, c, F1, 12, 1 ); |
| 412 |
R( c, d, e, a, b, F1, 13, 1 ); |
| 413 |
R( b, c, d, e, a, F1, 14, 1 ); |
| 414 |
R( a, b, c, d, e, F1, 15, 1 ); |
| 415 |
R( e, a, b, c, d, F1, 16, 1 ); |
| 416 |
R( d, e, a, b, c, F1, 17, 1 ); |
| 417 |
R( c, d, e, a, b, F1, 18, 1 ); |
| 418 |
R( b, c, d, e, a, F1, 19, 1 ); |
| 419 |
R( a, b, c, d, e, F2, 20, 1 ); |
| 420 |
R( e, a, b, c, d, F2, 21, 1 ); |
| 421 |
R( d, e, a, b, c, F2, 22, 1 ); |
| 422 |
R( c, d, e, a, b, F2, 23, 1 ); |
| 423 |
R( b, c, d, e, a, F2, 24, 1 ); |
| 424 |
R( a, b, c, d, e, F2, 25, 1 ); |
| 425 |
R( e, a, b, c, d, F2, 26, 1 ); |
| 426 |
R( d, e, a, b, c, F2, 27, 1 ); |
| 427 |
R( c, d, e, a, b, F2, 28, 1 ); |
| 428 |
R( b, c, d, e, a, F2, 29, 1 ); |
| 429 |
R( a, b, c, d, e, F2, 30, 1 ); |
| 430 |
R( e, a, b, c, d, F2, 31, 1 ); |
| 431 |
R( d, e, a, b, c, F2, 32, 1 ); |
| 432 |
R( c, d, e, a, b, F2, 33, 1 ); |
| 433 |
R( b, c, d, e, a, F2, 34, 1 ); |
| 434 |
R( a, b, c, d, e, F2, 35, 1 ); |
| 435 |
R( e, a, b, c, d, F2, 36, 1 ); |
| 436 |
R( d, e, a, b, c, F2, 37, 1 ); |
| 437 |
R( c, d, e, a, b, F2, 38, 1 ); |
| 438 |
R( b, c, d, e, a, F2, 39, 1 ); |
| 439 |
R( a, b, c, d, e, F3, 40, 1 ); |
| 440 |
R( e, a, b, c, d, F3, 41, 1 ); |
| 441 |
R( d, e, a, b, c, F3, 42, 1 ); |
| 442 |
R( c, d, e, a, b, F3, 43, 1 ); |
| 443 |
R( b, c, d, e, a, F3, 44, 1 ); |
| 444 |
R( a, b, c, d, e, F3, 45, 1 ); |
| 445 |
R( e, a, b, c, d, F3, 46, 1 ); |
| 446 |
R( d, e, a, b, c, F3, 47, 1 ); |
| 447 |
|
| 448 |
addq $-2, RNBLKS; |
| 449 |
jz .Lend; |
| 450 |
|
| 451 |
/* Transform 48-79 for block 2 + Precalc 0-31 for next two blocks. */ |
| 452 |
R( c, d, e, a, b, F3, 48, 1 ); W_PRECALC_00_15_0(0, W0, Wtmp0); |
| 453 |
R( b, c, d, e, a, F3, 49, 1 ); W_PRECALC_00_15_1(1, W0, Wtmp0); |
| 454 |
R( a, b, c, d, e, F3, 50, 1 ); W_PRECALC_00_15_2(2, W0, Wtmp0, K1); |
| 455 |
R( e, a, b, c, d, F3, 51, 1 ); W_PRECALC_00_15_3(3, W0, Wtmp0); |
| 456 |
R( d, e, a, b, c, F3, 52, 1 ); W_PRECALC_00_15_0(4, W7, Wtmp0); |
| 457 |
R( c, d, e, a, b, F3, 53, 1 ); W_PRECALC_00_15_1(5, W7, Wtmp0); |
| 458 |
R( b, c, d, e, a, F3, 54, 1 ); W_PRECALC_00_15_2(6, W7, Wtmp0, K1); |
| 459 |
R( a, b, c, d, e, F3, 55, 1 ); W_PRECALC_00_15_3(7, W7, Wtmp0); |
| 460 |
R( e, a, b, c, d, F3, 56, 1 ); W_PRECALC_00_15_0(8, W6, Wtmp0); |
| 461 |
R( d, e, a, b, c, F3, 57, 1 ); W_PRECALC_00_15_1(9, W6, Wtmp0); |
| 462 |
R( c, d, e, a, b, F3, 58, 1 ); W_PRECALC_00_15_2(10, W6, Wtmp0, K1); |
| 463 |
R( b, c, d, e, a, F3, 59, 1 ); W_PRECALC_00_15_3(11, W6, Wtmp0); |
| 464 |
R( a, b, c, d, e, F4, 60, 1 ); W_PRECALC_00_15_0(12, W5, Wtmp0); |
| 465 |
R( e, a, b, c, d, F4, 61, 1 ); W_PRECALC_00_15_1(13, W5, Wtmp0); |
| 466 |
R( d, e, a, b, c, F4, 62, 1 ); W_PRECALC_00_15_2(14, W5, Wtmp0, K1); |
| 467 |
R( c, d, e, a, b, F4, 63, 1 ); W_PRECALC_00_15_3(15, W5, Wtmp0); |
| 468 |
R( b, c, d, e, a, F4, 64, 1 ); W_PRECALC_16_31_0(16, W4, W5, W6, W7, W0, Wtmp0, Wtmp1); |
| 469 |
R( a, b, c, d, e, F4, 65, 1 ); W_PRECALC_16_31_1(17, W4, W5, W6, W7, W0, Wtmp0, Wtmp1); |
| 470 |
R( e, a, b, c, d, F4, 66, 1 ); W_PRECALC_16_31_2(18, W4, W5, W6, W7, W0, Wtmp0, Wtmp1); |
| 471 |
R( d, e, a, b, c, F4, 67, 1 ); W_PRECALC_16_31_3(19, W4, W5, W6, W7, W0, Wtmp0, Wtmp1, K1); |
| 472 |
R( c, d, e, a, b, F4, 68, 1 ); W_PRECALC_16_31_0(20, W3, W4, W5, W6, W7, Wtmp0, Wtmp1); |
| 473 |
R( b, c, d, e, a, F4, 69, 1 ); W_PRECALC_16_31_1(21, W3, W4, W5, W6, W7, Wtmp0, Wtmp1); |
| 474 |
R( a, b, c, d, e, F4, 70, 1 ); W_PRECALC_16_31_2(22, W3, W4, W5, W6, W7, Wtmp0, Wtmp1); |
| 475 |
R( e, a, b, c, d, F4, 71, 1 ); W_PRECALC_16_31_3(23, W3, W4, W5, W6, W7, Wtmp0, Wtmp1, K2); |
| 476 |
R( d, e, a, b, c, F4, 72, 1 ); W_PRECALC_16_31_0(24, W2, W3, W4, W5, W6, Wtmp0, Wtmp1); |
| 477 |
R( c, d, e, a, b, F4, 73, 1 ); W_PRECALC_16_31_1(25, W2, W3, W4, W5, W6, Wtmp0, Wtmp1); |
| 478 |
R( b, c, d, e, a, F4, 74, 1 ); W_PRECALC_16_31_2(26, W2, W3, W4, W5, W6, Wtmp0, Wtmp1); |
| 479 |
R( a, b, c, d, e, F4, 75, 1 ); W_PRECALC_16_31_3(27, W2, W3, W4, W5, W6, Wtmp0, Wtmp1, K2); |
| 480 |
R( e, a, b, c, d, F4, 76, 1 ); W_PRECALC_16_31_0(28, W1, W2, W3, W4, W5, Wtmp0, Wtmp1); |
| 481 |
R( d, e, a, b, c, F4, 77, 1 ); W_PRECALC_16_31_1(29, W1, W2, W3, W4, W5, Wtmp0, Wtmp1); |
| 482 |
R( c, d, e, a, b, F4, 78, 1 ); W_PRECALC_16_31_2(30, W1, W2, W3, W4, W5, Wtmp0, Wtmp1); |
| 483 |
addl state_h0(RSTATE), a; W_PRECALC_16_31_3(31, W1, W2, W3, W4, W5, Wtmp0, Wtmp1, K2); |
| 484 |
R( b, c, d, e, a, F4, 79, 1 ); |
| 485 |
addl ne, a; |
| 486 |
xorl ne, ne; |
| 487 |
|
| 488 |
/* Update the chaining variables. */ |
| 489 |
addl state_h3(RSTATE), d; |
| 490 |
addl state_h2(RSTATE), c; |
| 491 |
addl state_h1(RSTATE), b; |
| 492 |
addl state_h4(RSTATE), e; |
| 493 |
|
| 494 |
movl d, state_h3(RSTATE); |
| 495 |
movl c, state_h2(RSTATE); |
| 496 |
movl b, state_h1(RSTATE); |
| 497 |
movl a, state_h0(RSTATE); |
| 498 |
movl e, state_h4(RSTATE); |
| 499 |
|
| 500 |
jmp .Loop; |
| 501 |
|
| 502 |
.align 16 |
| 503 |
.Lend: |
| 504 |
vzeroall; |
| 505 |
|
| 506 |
/* Transform 48-79 for block 2 + burn stack */ |
| 507 |
R( c, d, e, a, b, F3, 48, 1 ); |
| 508 |
R( b, c, d, e, a, F3, 49, 1 ); |
| 509 |
R( a, b, c, d, e, F3, 50, 1 ); |
| 510 |
R( e, a, b, c, d, F3, 51, 1 ); |
| 511 |
R( d, e, a, b, c, F3, 52, 1 ); |
| 512 |
R( c, d, e, a, b, F3, 53, 1 ); |
| 513 |
R( b, c, d, e, a, F3, 54, 1 ); |
| 514 |
R( a, b, c, d, e, F3, 55, 1 ); |
| 515 |
R( e, a, b, c, d, F3, 56, 1 ); |
| 516 |
R( d, e, a, b, c, F3, 57, 1 ); |
| 517 |
R( c, d, e, a, b, F3, 58, 1 ); |
| 518 |
R( b, c, d, e, a, F3, 59, 1 ); |
| 519 |
R( a, b, c, d, e, F4, 60, 1 ); vmovdqa %ymm0, (0*32)(%rsp); |
| 520 |
R( e, a, b, c, d, F4, 61, 1 ); vmovdqa %ymm0, (1*32)(%rsp); |
| 521 |
R( d, e, a, b, c, F4, 62, 1 ); vmovdqa %ymm0, (2*32)(%rsp); |
| 522 |
R( c, d, e, a, b, F4, 63, 1 ); vmovdqa %ymm0, (3*32)(%rsp); |
| 523 |
R( b, c, d, e, a, F4, 64, 1 ); vmovdqa %ymm0, (4*32)(%rsp); |
| 524 |
R( a, b, c, d, e, F4, 65, 1 ); vmovdqa %ymm0, (5*32)(%rsp); |
| 525 |
R( e, a, b, c, d, F4, 66, 1 ); vmovdqa %ymm0, (6*32)(%rsp); |
| 526 |
R( d, e, a, b, c, F4, 67, 1 ); vmovdqa %ymm0, (7*32)(%rsp); |
| 527 |
R( c, d, e, a, b, F4, 68, 1 ); vmovdqa %ymm0, (8*32)(%rsp); |
| 528 |
R( b, c, d, e, a, F4, 69, 1 ); vmovdqa %ymm0, (9*32)(%rsp); |
| 529 |
R( a, b, c, d, e, F4, 70, 1 ); vmovdqa %ymm0, (10*32)(%rsp); |
| 530 |
R( e, a, b, c, d, F4, 71, 1 ); vmovdqa %ymm0, (11*32)(%rsp); |
| 531 |
R( d, e, a, b, c, F4, 72, 1 ); vmovdqa %ymm0, (12*32)(%rsp); |
| 532 |
R( c, d, e, a, b, F4, 73, 1 ); vmovdqa %ymm0, (13*32)(%rsp); |
| 533 |
R( b, c, d, e, a, F4, 74, 1 ); vmovdqa %ymm0, (14*32)(%rsp); |
| 534 |
R( a, b, c, d, e, F4, 75, 1 ); vmovdqa %ymm0, (15*32)(%rsp); |
| 535 |
R( e, a, b, c, d, F4, 76, 1 ); vmovdqa %ymm0, (16*32)(%rsp); |
| 536 |
R( d, e, a, b, c, F4, 77, 1 ); vmovdqa %ymm0, (17*32)(%rsp); |
| 537 |
R( c, d, e, a, b, F4, 78, 1 ); vmovdqa %ymm0, (18*32)(%rsp); |
| 538 |
addl state_h0(RSTATE), a; |
| 539 |
R( b, c, d, e, a, F4, 79, 1 ); |
| 540 |
addl ne, a; |
| 541 |
xorl ne, ne; |
| 542 |
|
| 543 |
/* WK_STACK_WORDS*4/32-1 = 19 */ |
| 544 |
vmovdqa %ymm0, (19*32)(%rsp); |
| 545 |
|
| 546 |
/* Update the chaining variables. */ |
| 547 |
addl state_h3(RSTATE), d; |
| 548 |
addl state_h2(RSTATE), c; |
| 549 |
addl state_h1(RSTATE), b; |
| 550 |
addl state_h4(RSTATE), e; |
| 551 |
|
| 552 |
movl d, state_h3(RSTATE); |
| 553 |
movl c, state_h2(RSTATE); |
| 554 |
movl b, state_h1(RSTATE); |
| 555 |
movl a, state_h0(RSTATE); |
| 556 |
movl e, state_h4(RSTATE); |
| 557 |
|
| 558 |
movq ROLDSTACK, %rsp; |
| 559 |
CFI_REGISTER(ROLDSTACK, %rsp); |
| 560 |
CFI_DEF_CFA_REGISTER(%rsp); |
| 561 |
|
| 562 |
popq %r12; |
| 563 |
CFI_POP(%r12); |
| 564 |
popq %rbp; |
| 565 |
CFI_POP(%rbp); |
| 566 |
popq %rbx; |
| 567 |
CFI_POP(%rbx); |
| 568 |
|
| 569 |
/* stack already burned */ |
| 570 |
xorl %eax, %eax; |
| 571 |
|
| 572 |
ret_spec_stop; |
| 573 |
CFI_ENDPROC(); |
| 574 |
ELF(.size _gcry_sha1_transform_amd64_avx2_bmi2, |
| 575 |
.-_gcry_sha1_transform_amd64_avx2_bmi2;) |
| 576 |
|
| 577 |
#endif |
| 578 |
#endif |