| 1 |
/* sha512-avx512-amd64.c - amd64/AVX512 implementation of SHA-512 transform |
| 2 |
* Copyright (C) 2022 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 |
* Based on implementation from file "sha512-avx2-bmi2-amd64.S": |
| 21 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 22 |
; Copyright (c) 2012, Intel Corporation |
| 23 |
; |
| 24 |
; All rights reserved. |
| 25 |
; |
| 26 |
; Redistribution and use in source and binary forms, with or without |
| 27 |
; modification, are permitted provided that the following conditions are |
| 28 |
; met: |
| 29 |
; |
| 30 |
; * Redistributions of source code must retain the above copyright |
| 31 |
; notice, this list of conditions and the following disclaimer. |
| 32 |
; |
| 33 |
; * Redistributions in binary form must reproduce the above copyright |
| 34 |
; notice, this list of conditions and the following disclaimer in the |
| 35 |
; documentation and/or other materials provided with the |
| 36 |
; distribution. |
| 37 |
; |
| 38 |
; * Neither the name of the Intel Corporation nor the names of its |
| 39 |
; contributors may be used to endorse or promote products derived from |
| 40 |
; this software without specific prior written permission. |
| 41 |
; |
| 42 |
; |
| 43 |
; THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION "AS IS" AND ANY |
| 44 |
; EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 45 |
; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 46 |
; PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL CORPORATION OR |
| 47 |
; CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 48 |
; EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 49 |
; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 50 |
; PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 51 |
; LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 52 |
; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 53 |
; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 54 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 55 |
; This code schedules 1 blocks at a time, with 4 lanes per block |
| 56 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 57 |
*/ |
| 58 |
|
| 59 |
#ifdef __x86_64 |
| 60 |
#include <config.h> |
| 61 |
#if (defined(HAVE_COMPATIBLE_GCC_AMD64_PLATFORM_AS) || \ |
| 62 |
defined(HAVE_COMPATIBLE_GCC_WIN64_PLATFORM_AS)) && \ |
| 63 |
defined(HAVE_INTEL_SYNTAX_PLATFORM_AS) && \ |
| 64 |
defined(HAVE_GCC_INLINE_ASM_AVX512) && \ |
| 65 |
defined(USE_SHA512) |
| 66 |
|
| 67 |
#include "asm-common-amd64.h" |
| 68 |
|
| 69 |
.intel_syntax noprefix |
| 70 |
|
| 71 |
.text |
| 72 |
|
| 73 |
/* Virtual Registers */ |
| 74 |
#define Y_0 ymm0 |
| 75 |
#define Y_1 ymm1 |
| 76 |
#define Y_2 ymm2 |
| 77 |
#define Y_3 ymm3 |
| 78 |
|
| 79 |
#define YTMP0 ymm4 |
| 80 |
#define YTMP1 ymm5 |
| 81 |
#define YTMP2 ymm6 |
| 82 |
#define YTMP3 ymm7 |
| 83 |
#define YTMP4 ymm8 |
| 84 |
#define XFER YTMP0 |
| 85 |
|
| 86 |
#define BYTE_FLIP_MASK ymm9 |
| 87 |
#define PERM_VPALIGNR_8 ymm10 |
| 88 |
|
| 89 |
#define MASK_DC_00 k1 |
| 90 |
|
| 91 |
#define INP rdi /* 1st arg */ |
| 92 |
#define CTX rsi /* 2nd arg */ |
| 93 |
#define NUM_BLKS rdx /* 3rd arg */ |
| 94 |
#define SRND r8d |
| 95 |
#define RSP_SAVE r9 |
| 96 |
|
| 97 |
#define TBL rcx |
| 98 |
|
| 99 |
#define a xmm11 |
| 100 |
#define b xmm12 |
| 101 |
#define c xmm13 |
| 102 |
#define d xmm14 |
| 103 |
#define e xmm15 |
| 104 |
#define f xmm16 |
| 105 |
#define g xmm17 |
| 106 |
#define h xmm18 |
| 107 |
|
| 108 |
#define y0 xmm19 |
| 109 |
#define y1 xmm20 |
| 110 |
#define y2 xmm21 |
| 111 |
#define y3 xmm22 |
| 112 |
|
| 113 |
/* Local variables (stack frame) */ |
| 114 |
#define frame_XFER 0 |
| 115 |
#define frame_XFER_size (4*4*8) |
| 116 |
#define frame_size (frame_XFER + frame_XFER_size) |
| 117 |
|
| 118 |
#define clear_reg(x) vpxorq x,x,x |
| 119 |
|
| 120 |
/* addm [mem], reg */ |
| 121 |
/* Add reg to mem using reg-mem add and store */ |
| 122 |
#define addm(p1, p2) \ |
| 123 |
vmovq y0, p1; \ |
| 124 |
vpaddq p2, p2, y0; \ |
| 125 |
vmovq p1, p2; |
| 126 |
|
| 127 |
/* COPY_YMM_AND_BSWAP ymm, [mem], byte_flip_mask */ |
| 128 |
/* Load ymm with mem and byte swap each dword */ |
| 129 |
#define COPY_YMM_AND_BSWAP(p1, p2, p3) \ |
| 130 |
vmovdqu p1, p2; \ |
| 131 |
vpshufb p1, p1, p3 |
| 132 |
|
| 133 |
/* %macro MY_VPALIGNR YDST, YSRC1, YSRC2, RVAL */ |
| 134 |
/* YDST = {YSRC1, YSRC2} >> RVAL*8 */ |
| 135 |
#define MY_VPALIGNR(YDST_SRC1, YSRC2, RVAL) \ |
| 136 |
vpermt2q YDST_SRC1, PERM_VPALIGNR_##RVAL, YSRC2; |
| 137 |
|
| 138 |
#define ONE_ROUND_PART1(XFERIN, a, b, c, d, e, f, g, h) \ |
| 139 |
/* h += Sum1 (e) + Ch (e, f, g) + (k[t] + w[0]); \ |
| 140 |
* d += h; \ |
| 141 |
* h += Sum0 (a) + Maj (a, b, c); \ |
| 142 |
* \ |
| 143 |
* Ch(x, y, z) => ((x & y) + (~x & z)) \ |
| 144 |
* Maj(x, y, z) => ((x & y) + (z & (x ^ y))) \ |
| 145 |
*/ \ |
| 146 |
\ |
| 147 |
vmovq y3, [XFERIN]; \ |
| 148 |
vmovdqa64 y2, e; \ |
| 149 |
vpaddq h, h, y3; \ |
| 150 |
vprorq y0, e, 41; \ |
| 151 |
vpternlogq y2, f, g, 0xca; /* Ch (e, f, g) */ \ |
| 152 |
vprorq y1, e, 18; \ |
| 153 |
vprorq y3, e, 14; \ |
| 154 |
vpaddq h, h, y2; \ |
| 155 |
vpternlogq y0, y1, y3, 0x96; /* Sum1 (e) */ \ |
| 156 |
vpaddq h, h, y0; /* h += Sum1 (e) + Ch (e, f, g) + (k[t] + w[0]) */ \ |
| 157 |
vpaddq d, d, h; /* d += h */ |
| 158 |
|
| 159 |
#define ONE_ROUND_PART2(a, b, c, d, e, f, g, h) \ |
| 160 |
vmovdqa64 y1, a; \ |
| 161 |
vprorq y0, a, 39; \ |
| 162 |
vpternlogq y1, b, c, 0xe8; /* Maj (a, b, c) */ \ |
| 163 |
vprorq y2, a, 34; \ |
| 164 |
vprorq y3, a, 28; \ |
| 165 |
vpternlogq y0, y2, y3, 0x96; /* Sum0 (a) */ \ |
| 166 |
vpaddq h, h, y1; \ |
| 167 |
vpaddq h, h, y0; /* h += Sum0 (a) + Maj (a, b, c) */ |
| 168 |
|
| 169 |
#define FOUR_ROUNDS_AND_SCHED(X, Y_0, Y_1, Y_2, Y_3, a, b, c, d, e, f, g, h) \ |
| 170 |
/*;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; RND N + 0 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; */; \ |
| 171 |
vmovdqa YTMP0, Y_3; \ |
| 172 |
vmovdqa YTMP1, Y_1; \ |
| 173 |
/* Extract w[t-7] */; \ |
| 174 |
vpermt2q YTMP0, PERM_VPALIGNR_8, Y_2 /* YTMP0 = W[-7] */; \ |
| 175 |
/* Calculate w[t-16] + w[t-7] */; \ |
| 176 |
vpaddq YTMP0, YTMP0, Y_0 /* YTMP0 = W[-7] + W[-16] */; \ |
| 177 |
/* Extract w[t-15] */; \ |
| 178 |
vpermt2q YTMP1, PERM_VPALIGNR_8, Y_0 /* YTMP1 = W[-15] */; \ |
| 179 |
ONE_ROUND_PART1(rsp+frame_XFER+0*8+X*32, a, b, c, d, e, f, g, h); \ |
| 180 |
\ |
| 181 |
/* Calculate sigma0 */; \ |
| 182 |
\ |
| 183 |
/* Calculate w[t-15] ror 1 */; \ |
| 184 |
vprorq YTMP3, YTMP1, 1; /* YTMP3 = W[-15] ror 1 */; \ |
| 185 |
/* Calculate w[t-15] shr 7 */; \ |
| 186 |
vpsrlq YTMP4, YTMP1, 7 /* YTMP4 = W[-15] >> 7 */; \ |
| 187 |
\ |
| 188 |
ONE_ROUND_PART2(a, b, c, d, e, f, g, h); \ |
| 189 |
\ |
| 190 |
/*;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; RND N + 1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; */; \ |
| 191 |
/* Calculate w[t-15] ror 8 */; \ |
| 192 |
vprorq YTMP1, YTMP1, 8 /* YTMP1 = W[-15] ror 8 */; \ |
| 193 |
/* XOR the three components */; \ |
| 194 |
vpternlogq YTMP1, YTMP3, YTMP4, 0x96 /* YTMP1 = s0 = W[-15] ror 1 ^ W[-15] >> 7 ^ W[-15] ror 8 */; \ |
| 195 |
\ |
| 196 |
/* Add three components, w[t-16], w[t-7] and sigma0 */; \ |
| 197 |
vpaddq YTMP0, YTMP0, YTMP1 /* YTMP0 = W[-16] + W[-7] + s0 */; \ |
| 198 |
ONE_ROUND_PART1(rsp+frame_XFER+1*8+X*32, h, a, b, c, d, e, f, g); \ |
| 199 |
/* Move to appropriate lanes for calculating w[16] and w[17] */; \ |
| 200 |
vshufi64x2 Y_0, YTMP0, YTMP0, 0x0 /* Y_0 = W[-16] + W[-7] + s0 {BABA} */; \ |
| 201 |
\ |
| 202 |
/* Calculate w[16] and w[17] in both 128 bit lanes */; \ |
| 203 |
\ |
| 204 |
/* Calculate sigma1 for w[16] and w[17] on both 128 bit lanes */; \ |
| 205 |
vshufi64x2 YTMP2, Y_3, Y_3, 0b11 /* YTMP2 = W[-2] {BABA} */; \ |
| 206 |
vpsrlq YTMP4, YTMP2, 6 /* YTMP4 = W[-2] >> 6 {BABA} */; \ |
| 207 |
\ |
| 208 |
ONE_ROUND_PART2(h, a, b, c, d, e, f, g); \ |
| 209 |
\ |
| 210 |
/*;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; RND N + 2 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; */; \ |
| 211 |
vprorq YTMP3, YTMP2, 19 /* YTMP3 = W[-2] ror 19 {BABA} */; \ |
| 212 |
vprorq YTMP1, YTMP2, 61 /* YTMP3 = W[-2] ror 61 {BABA} */; \ |
| 213 |
vpternlogq YTMP4, YTMP3, YTMP1, 0x96 /* YTMP4 = s1 = (W[-2] ror 19) ^ (W[-2] ror 61) ^ (W[-2] >> 6) {BABA} */; \ |
| 214 |
\ |
| 215 |
ONE_ROUND_PART1(rsp+frame_XFER+2*8+X*32, g, h, a, b, c, d, e, f); \ |
| 216 |
/* Add sigma1 to the other compunents to get w[16] and w[17] */; \ |
| 217 |
vpaddq Y_0, Y_0, YTMP4 /* Y_0 = {W[1], W[0], W[1], W[0]} */; \ |
| 218 |
\ |
| 219 |
/* Calculate sigma1 for w[18] and w[19] for upper 128 bit lane */; \ |
| 220 |
vpsrlq YTMP4, Y_0, 6 /* YTMP4 = W[-2] >> 6 {DC--} */; \ |
| 221 |
\ |
| 222 |
ONE_ROUND_PART2(g, h, a, b, c, d, e, f); \ |
| 223 |
\ |
| 224 |
/*;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; RND N + 3 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; */; \ |
| 225 |
vprorq YTMP3, Y_0, 19 /* YTMP3 = W[-2] ror 19 {DC--} */; \ |
| 226 |
vprorq YTMP1, Y_0, 61 /* YTMP1 = W[-2] ror 61 {DC--} */; \ |
| 227 |
vpternlogq YTMP4, YTMP3, YTMP1, 0x96 /* YTMP4 = s1 = (W[-2] ror 19) ^ (W[-2] ror 61) ^ (W[-2] >> 6) {DC--} */; \ |
| 228 |
\ |
| 229 |
ONE_ROUND_PART1(rsp+frame_XFER+3*8+X*32, f, g, h, a, b, c, d, e); \ |
| 230 |
/* Add the sigma0 + w[t-7] + w[t-16] for w[18] and w[19] to newly calculated sigma1 to get w[18] and w[19] */; \ |
| 231 |
/* Form w[19, w[18], w17], w[16] */; \ |
| 232 |
vpaddq Y_0{MASK_DC_00}, YTMP0, YTMP4 /* YTMP2 = {W[3], W[2], W[1], W[0]} */; \ |
| 233 |
\ |
| 234 |
vpaddq XFER, Y_0, [TBL + (4+X)*32]; \ |
| 235 |
vmovdqa [rsp + frame_XFER + X*32], XFER; \ |
| 236 |
ONE_ROUND_PART2(f, g, h, a, b, c, d, e) |
| 237 |
|
| 238 |
#define ONE_ROUND(XFERIN, a, b, c, d, e, f, g, h) \ |
| 239 |
ONE_ROUND_PART1(XFERIN, a, b, c, d, e, f, g, h); \ |
| 240 |
ONE_ROUND_PART2(a, b, c, d, e, f, g, h) |
| 241 |
|
| 242 |
#define DO_4ROUNDS(X, a, b, c, d, e, f, g, h) \ |
| 243 |
ONE_ROUND(rsp+frame_XFER+0*8+X*32, a, b, c, d, e, f, g, h); \ |
| 244 |
ONE_ROUND(rsp+frame_XFER+1*8+X*32, h, a, b, c, d, e, f, g); \ |
| 245 |
ONE_ROUND(rsp+frame_XFER+2*8+X*32, g, h, a, b, c, d, e, f); \ |
| 246 |
ONE_ROUND(rsp+frame_XFER+3*8+X*32, f, g, h, a, b, c, d, e) |
| 247 |
|
| 248 |
/* |
| 249 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 250 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 251 |
; void sha512_avx512(const void* M, void* D, uint64_t L); |
| 252 |
; Purpose: Updates the SHA512 digest stored at D with the message stored in M. |
| 253 |
; The size of the message pointed to by M must be an integer multiple of SHA512 |
| 254 |
; message blocks. |
| 255 |
; L is the message length in SHA512 blocks |
| 256 |
*/ |
| 257 |
.globl _gcry_sha512_transform_amd64_avx512 |
| 258 |
ELF(.type _gcry_sha512_transform_amd64_avx512,@function;) |
| 259 |
.align 16 |
| 260 |
_gcry_sha512_transform_amd64_avx512: |
| 261 |
CFI_STARTPROC() |
| 262 |
xor eax, eax |
| 263 |
|
| 264 |
cmp rdx, 0 |
| 265 |
je .Lnowork |
| 266 |
|
| 267 |
spec_stop_avx512_intel_syntax; |
| 268 |
|
| 269 |
/* Setup mask register for DC:BA merging. */ |
| 270 |
mov eax, 0b1100 |
| 271 |
kmovd MASK_DC_00, eax |
| 272 |
|
| 273 |
/* Allocate Stack Space */ |
| 274 |
mov RSP_SAVE, rsp |
| 275 |
CFI_DEF_CFA_REGISTER(RSP_SAVE); |
| 276 |
sub rsp, frame_size |
| 277 |
and rsp, ~(0x40 - 1) |
| 278 |
|
| 279 |
/*; load initial digest */ |
| 280 |
vmovq a,[8*0 + CTX] |
| 281 |
vmovq b,[8*1 + CTX] |
| 282 |
vmovq c,[8*2 + CTX] |
| 283 |
vmovq d,[8*3 + CTX] |
| 284 |
vmovq e,[8*4 + CTX] |
| 285 |
vmovq f,[8*5 + CTX] |
| 286 |
vmovq g,[8*6 + CTX] |
| 287 |
vmovq h,[8*7 + CTX] |
| 288 |
|
| 289 |
vmovdqa BYTE_FLIP_MASK, [.LPSHUFFLE_BYTE_FLIP_MASK ADD_RIP] |
| 290 |
vpmovzxbq PERM_VPALIGNR_8, [.LPERM_VPALIGNR_8 ADD_RIP] |
| 291 |
|
| 292 |
lea TBL,[.LK512 ADD_RIP] |
| 293 |
|
| 294 |
/*; byte swap first 16 dwords */ |
| 295 |
COPY_YMM_AND_BSWAP(Y_0, [INP + 0*32], BYTE_FLIP_MASK) |
| 296 |
COPY_YMM_AND_BSWAP(Y_1, [INP + 1*32], BYTE_FLIP_MASK) |
| 297 |
COPY_YMM_AND_BSWAP(Y_2, [INP + 2*32], BYTE_FLIP_MASK) |
| 298 |
COPY_YMM_AND_BSWAP(Y_3, [INP + 3*32], BYTE_FLIP_MASK) |
| 299 |
|
| 300 |
lea INP, [INP + 128] |
| 301 |
|
| 302 |
vpaddq XFER, Y_0, [TBL + 0*32] |
| 303 |
vmovdqa [rsp + frame_XFER + 0*32], XFER |
| 304 |
vpaddq XFER, Y_1, [TBL + 1*32] |
| 305 |
vmovdqa [rsp + frame_XFER + 1*32], XFER |
| 306 |
vpaddq XFER, Y_2, [TBL + 2*32] |
| 307 |
vmovdqa [rsp + frame_XFER + 2*32], XFER |
| 308 |
vpaddq XFER, Y_3, [TBL + 3*32] |
| 309 |
vmovdqa [rsp + frame_XFER + 3*32], XFER |
| 310 |
|
| 311 |
/*; schedule 64 input dwords, by doing 12 rounds of 4 each */ |
| 312 |
mov SRND, 4 |
| 313 |
|
| 314 |
.align 16 |
| 315 |
.Loop0: |
| 316 |
FOUR_ROUNDS_AND_SCHED(0, Y_0, Y_1, Y_2, Y_3, a, b, c, d, e, f, g, h) |
| 317 |
FOUR_ROUNDS_AND_SCHED(1, Y_1, Y_2, Y_3, Y_0, e, f, g, h, a, b, c, d) |
| 318 |
FOUR_ROUNDS_AND_SCHED(2, Y_2, Y_3, Y_0, Y_1, a, b, c, d, e, f, g, h) |
| 319 |
FOUR_ROUNDS_AND_SCHED(3, Y_3, Y_0, Y_1, Y_2, e, f, g, h, a, b, c, d) |
| 320 |
lea TBL, [TBL + 4*32] |
| 321 |
|
| 322 |
sub SRND, 1 |
| 323 |
jne .Loop0 |
| 324 |
|
| 325 |
sub NUM_BLKS, 1 |
| 326 |
je .Ldone_hash |
| 327 |
|
| 328 |
lea TBL, [.LK512 ADD_RIP] |
| 329 |
|
| 330 |
/* load next block and byte swap */ |
| 331 |
COPY_YMM_AND_BSWAP(Y_0, [INP + 0*32], BYTE_FLIP_MASK) |
| 332 |
COPY_YMM_AND_BSWAP(Y_1, [INP + 1*32], BYTE_FLIP_MASK) |
| 333 |
COPY_YMM_AND_BSWAP(Y_2, [INP + 2*32], BYTE_FLIP_MASK) |
| 334 |
COPY_YMM_AND_BSWAP(Y_3, [INP + 3*32], BYTE_FLIP_MASK) |
| 335 |
|
| 336 |
lea INP, [INP + 128] |
| 337 |
|
| 338 |
DO_4ROUNDS(0, a, b, c, d, e, f, g, h) |
| 339 |
vpaddq XFER, Y_0, [TBL + 0*32] |
| 340 |
vmovdqa [rsp + frame_XFER + 0*32], XFER |
| 341 |
DO_4ROUNDS(1, e, f, g, h, a, b, c, d) |
| 342 |
vpaddq XFER, Y_1, [TBL + 1*32] |
| 343 |
vmovdqa [rsp + frame_XFER + 1*32], XFER |
| 344 |
DO_4ROUNDS(2, a, b, c, d, e, f, g, h) |
| 345 |
vpaddq XFER, Y_2, [TBL + 2*32] |
| 346 |
vmovdqa [rsp + frame_XFER + 2*32], XFER |
| 347 |
DO_4ROUNDS(3, e, f, g, h, a, b, c, d) |
| 348 |
vpaddq XFER, Y_3, [TBL + 3*32] |
| 349 |
vmovdqa [rsp + frame_XFER + 3*32], XFER |
| 350 |
|
| 351 |
addm([8*0 + CTX],a) |
| 352 |
addm([8*1 + CTX],b) |
| 353 |
addm([8*2 + CTX],c) |
| 354 |
addm([8*3 + CTX],d) |
| 355 |
addm([8*4 + CTX],e) |
| 356 |
addm([8*5 + CTX],f) |
| 357 |
addm([8*6 + CTX],g) |
| 358 |
addm([8*7 + CTX],h) |
| 359 |
|
| 360 |
/*; schedule 64 input dwords, by doing 12 rounds of 4 each */ |
| 361 |
mov SRND, 4 |
| 362 |
|
| 363 |
jmp .Loop0 |
| 364 |
|
| 365 |
.Ldone_hash: |
| 366 |
DO_4ROUNDS(0, a, b, c, d, e, f, g, h) |
| 367 |
DO_4ROUNDS(1, e, f, g, h, a, b, c, d) |
| 368 |
DO_4ROUNDS(2, a, b, c, d, e, f, g, h) |
| 369 |
DO_4ROUNDS(3, e, f, g, h, a, b, c, d) |
| 370 |
|
| 371 |
addm([8*0 + CTX],a) |
| 372 |
xor eax, eax /* burn stack */ |
| 373 |
addm([8*1 + CTX],b) |
| 374 |
addm([8*2 + CTX],c) |
| 375 |
addm([8*3 + CTX],d) |
| 376 |
addm([8*4 + CTX],e) |
| 377 |
addm([8*5 + CTX],f) |
| 378 |
addm([8*6 + CTX],g) |
| 379 |
addm([8*7 + CTX],h) |
| 380 |
kxord MASK_DC_00, MASK_DC_00, MASK_DC_00 |
| 381 |
|
| 382 |
vzeroall |
| 383 |
vmovdqa [rsp + frame_XFER + 0*32], ymm0 /* burn stack */ |
| 384 |
vmovdqa [rsp + frame_XFER + 1*32], ymm0 /* burn stack */ |
| 385 |
vmovdqa [rsp + frame_XFER + 2*32], ymm0 /* burn stack */ |
| 386 |
vmovdqa [rsp + frame_XFER + 3*32], ymm0 /* burn stack */ |
| 387 |
clear_reg(ymm16); |
| 388 |
clear_reg(ymm17); |
| 389 |
clear_reg(ymm18); |
| 390 |
clear_reg(ymm19); |
| 391 |
clear_reg(ymm20); |
| 392 |
clear_reg(ymm21); |
| 393 |
clear_reg(ymm22); |
| 394 |
|
| 395 |
/* Restore Stack Pointer */ |
| 396 |
mov rsp, RSP_SAVE |
| 397 |
CFI_DEF_CFA_REGISTER(rsp) |
| 398 |
|
| 399 |
.Lnowork: |
| 400 |
ret_spec_stop |
| 401 |
CFI_ENDPROC() |
| 402 |
ELF(.size _gcry_sha512_transform_amd64_avx512,.-_gcry_sha512_transform_amd64_avx512) |
| 403 |
|
| 404 |
/*;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; */ |
| 405 |
/*;; Binary Data */ |
| 406 |
|
| 407 |
SECTION_RODATA |
| 408 |
|
| 409 |
ELF(.type _gcry_sha512_avx512_consts,@object) |
| 410 |
_gcry_sha512_avx512_consts: |
| 411 |
.align 64 |
| 412 |
/* K[t] used in SHA512 hashing */ |
| 413 |
.LK512: |
| 414 |
.quad 0x428a2f98d728ae22,0x7137449123ef65cd |
| 415 |
.quad 0xb5c0fbcfec4d3b2f,0xe9b5dba58189dbbc |
| 416 |
.quad 0x3956c25bf348b538,0x59f111f1b605d019 |
| 417 |
.quad 0x923f82a4af194f9b,0xab1c5ed5da6d8118 |
| 418 |
.quad 0xd807aa98a3030242,0x12835b0145706fbe |
| 419 |
.quad 0x243185be4ee4b28c,0x550c7dc3d5ffb4e2 |
| 420 |
.quad 0x72be5d74f27b896f,0x80deb1fe3b1696b1 |
| 421 |
.quad 0x9bdc06a725c71235,0xc19bf174cf692694 |
| 422 |
.quad 0xe49b69c19ef14ad2,0xefbe4786384f25e3 |
| 423 |
.quad 0x0fc19dc68b8cd5b5,0x240ca1cc77ac9c65 |
| 424 |
.quad 0x2de92c6f592b0275,0x4a7484aa6ea6e483 |
| 425 |
.quad 0x5cb0a9dcbd41fbd4,0x76f988da831153b5 |
| 426 |
.quad 0x983e5152ee66dfab,0xa831c66d2db43210 |
| 427 |
.quad 0xb00327c898fb213f,0xbf597fc7beef0ee4 |
| 428 |
.quad 0xc6e00bf33da88fc2,0xd5a79147930aa725 |
| 429 |
.quad 0x06ca6351e003826f,0x142929670a0e6e70 |
| 430 |
.quad 0x27b70a8546d22ffc,0x2e1b21385c26c926 |
| 431 |
.quad 0x4d2c6dfc5ac42aed,0x53380d139d95b3df |
| 432 |
.quad 0x650a73548baf63de,0x766a0abb3c77b2a8 |
| 433 |
.quad 0x81c2c92e47edaee6,0x92722c851482353b |
| 434 |
.quad 0xa2bfe8a14cf10364,0xa81a664bbc423001 |
| 435 |
.quad 0xc24b8b70d0f89791,0xc76c51a30654be30 |
| 436 |
.quad 0xd192e819d6ef5218,0xd69906245565a910 |
| 437 |
.quad 0xf40e35855771202a,0x106aa07032bbd1b8 |
| 438 |
.quad 0x19a4c116b8d2d0c8,0x1e376c085141ab53 |
| 439 |
.quad 0x2748774cdf8eeb99,0x34b0bcb5e19b48a8 |
| 440 |
.quad 0x391c0cb3c5c95a63,0x4ed8aa4ae3418acb |
| 441 |
.quad 0x5b9cca4f7763e373,0x682e6ff3d6b2b8a3 |
| 442 |
.quad 0x748f82ee5defb2fc,0x78a5636f43172f60 |
| 443 |
.quad 0x84c87814a1f0ab72,0x8cc702081a6439ec |
| 444 |
.quad 0x90befffa23631e28,0xa4506cebde82bde9 |
| 445 |
.quad 0xbef9a3f7b2c67915,0xc67178f2e372532b |
| 446 |
.quad 0xca273eceea26619c,0xd186b8c721c0c207 |
| 447 |
.quad 0xeada7dd6cde0eb1e,0xf57d4f7fee6ed178 |
| 448 |
.quad 0x06f067aa72176fba,0x0a637dc5a2c898a6 |
| 449 |
.quad 0x113f9804bef90dae,0x1b710b35131c471b |
| 450 |
.quad 0x28db77f523047d84,0x32caab7b40c72493 |
| 451 |
.quad 0x3c9ebe0a15c9bebc,0x431d67c49c100d4c |
| 452 |
.quad 0x4cc5d4becb3e42b6,0x597f299cfc657e2a |
| 453 |
.quad 0x5fcb6fab3ad6faec,0x6c44198c4a475817 |
| 454 |
|
| 455 |
/* Mask for byte-swapping a couple of qwords in an XMM register using (v)pshufb. */ |
| 456 |
.align 32 |
| 457 |
.LPSHUFFLE_BYTE_FLIP_MASK: .octa 0x08090a0b0c0d0e0f0001020304050607 |
| 458 |
.octa 0x18191a1b1c1d1e1f1011121314151617 |
| 459 |
|
| 460 |
.align 4 |
| 461 |
.LPERM_VPALIGNR_8: .byte 5, 6, 7, 0 |
| 462 |
ELF(.size _gcry_sha512_avx512_consts,.-_gcry_sha512_avx512_consts) |
| 463 |
|
| 464 |
#endif |
| 465 |
#endif |