Denys Vlasenko | 6472ac9 | 2022-02-03 14:15:20 +0100 | [diff] [blame] | 1 | #if ENABLE_SHA256_HWACCEL && defined(__GNUC__) && defined(__x86_64__) |
| 2 | /* The code is adapted from Linux kernel's source */ |
| 3 | |
| 4 | // We use shorter insns, even though they are for "wrong" |
| 5 | // data type (fp, not int). |
| 6 | // For Intel, there is no penalty for doing it at all |
Denys Vlasenko | 6f56fa1 | 2022-02-10 15:38:10 +0100 | [diff] [blame] | 7 | // (CPUs which do have such penalty do not support SHA insns). |
Denys Vlasenko | 6472ac9 | 2022-02-03 14:15:20 +0100 | [diff] [blame] | 8 | // For AMD, the penalty is one extra cycle |
| 9 | // (allegedly: I failed to find measurable difference). |
| 10 | |
| 11 | //#define mova128 movdqa |
| 12 | #define mova128 movaps |
| 13 | //#define movu128 movdqu |
| 14 | #define movu128 movups |
| 15 | //#define shuf128_32 pshufd |
| 16 | #define shuf128_32 shufps |
| 17 | |
Denys Vlasenko | dda77e8 | 2022-02-11 14:53:26 +0100 | [diff] [blame] | 18 | // pshufb and palignr are SSSE3 insns. |
| 19 | // We do not check SSSE3 in cpuid, |
| 20 | // all SHA-capable CPUs support it as well. |
| 21 | |
Ludwig Nussel | 526625b | 2022-08-25 12:48:07 +0200 | [diff] [blame] | 22 | #ifdef __linux__ |
| 23 | .section .note.GNU-stack, "", @progbits |
| 24 | #endif |
Denys Vlasenko | 6472ac9 | 2022-02-03 14:15:20 +0100 | [diff] [blame] | 25 | .section .text.sha256_process_block64_shaNI, "ax", @progbits |
| 26 | .globl sha256_process_block64_shaNI |
| 27 | .hidden sha256_process_block64_shaNI |
| 28 | .type sha256_process_block64_shaNI, @function |
| 29 | |
| 30 | #define DATA_PTR %rdi |
| 31 | |
| 32 | #define SHA256CONSTANTS %rax |
| 33 | |
| 34 | #define MSG %xmm0 |
| 35 | #define STATE0 %xmm1 |
| 36 | #define STATE1 %xmm2 |
| 37 | #define MSGTMP0 %xmm3 |
| 38 | #define MSGTMP1 %xmm4 |
| 39 | #define MSGTMP2 %xmm5 |
| 40 | #define MSGTMP3 %xmm6 |
Denys Vlasenko | c0ff0d4 | 2022-02-09 00:33:39 +0100 | [diff] [blame] | 41 | |
| 42 | #define XMMTMP %xmm7 |
Denys Vlasenko | 6472ac9 | 2022-02-03 14:15:20 +0100 | [diff] [blame] | 43 | |
Denys Vlasenko | c2e7780 | 2022-02-12 00:52:12 +0100 | [diff] [blame] | 44 | #define SAVE0 %xmm8 |
| 45 | #define SAVE1 %xmm9 |
Denys Vlasenko | 6472ac9 | 2022-02-03 14:15:20 +0100 | [diff] [blame] | 46 | |
Denys Vlasenko | 11bcea7 | 2022-02-09 01:42:49 +0100 | [diff] [blame] | 47 | #define SHUF(a,b,c,d) $(a+(b<<2)+(c<<4)+(d<<6)) |
| 48 | |
Denys Vlasenko | 6472ac9 | 2022-02-03 14:15:20 +0100 | [diff] [blame] | 49 | .balign 8 # allow decoders to fetch at least 2 first insns |
| 50 | sha256_process_block64_shaNI: |
Denys Vlasenko | 6472ac9 | 2022-02-03 14:15:20 +0100 | [diff] [blame] | 51 | |
Denys Vlasenko | 6f56fa1 | 2022-02-10 15:38:10 +0100 | [diff] [blame] | 52 | movu128 80+0*16(%rdi), XMMTMP /* ABCD (little-endian dword order) */ |
| 53 | movu128 80+1*16(%rdi), STATE1 /* EFGH */ |
Denys Vlasenko | 11bcea7 | 2022-02-09 01:42:49 +0100 | [diff] [blame] | 54 | /* shufps takes dwords 0,1 from *2nd* operand, and dwords 2,3 from 1st one */ |
Denys Vlasenko | caa9c4f | 2022-02-09 01:50:22 +0100 | [diff] [blame] | 55 | mova128 STATE1, STATE0 |
Denys Vlasenko | 6f56fa1 | 2022-02-10 15:38:10 +0100 | [diff] [blame] | 56 | /* --- -------------- ABCD -- EFGH */ |
| 57 | shufps SHUF(1,0,1,0), XMMTMP, STATE0 /* FEBA */ |
| 58 | shufps SHUF(3,2,3,2), XMMTMP, STATE1 /* HGDC */ |
Denys Vlasenko | 6472ac9 | 2022-02-03 14:15:20 +0100 | [diff] [blame] | 59 | |
Denys Vlasenko | c0ff0d4 | 2022-02-09 00:33:39 +0100 | [diff] [blame] | 60 | /* XMMTMP holds flip mask from here... */ |
| 61 | mova128 PSHUFFLE_BSWAP32_FLIP_MASK(%rip), XMMTMP |
Denys Vlasenko | a1429fb | 2022-02-03 15:17:42 +0100 | [diff] [blame] | 62 | leaq K256+8*16(%rip), SHA256CONSTANTS |
Denys Vlasenko | 6472ac9 | 2022-02-03 14:15:20 +0100 | [diff] [blame] | 63 | |
| 64 | /* Save hash values for addition after rounds */ |
Denys Vlasenko | c2e7780 | 2022-02-12 00:52:12 +0100 | [diff] [blame] | 65 | mova128 STATE0, SAVE0 |
| 66 | mova128 STATE1, SAVE1 |
Denys Vlasenko | 6472ac9 | 2022-02-03 14:15:20 +0100 | [diff] [blame] | 67 | |
| 68 | /* Rounds 0-3 */ |
| 69 | movu128 0*16(DATA_PTR), MSG |
Denys Vlasenko | c0ff0d4 | 2022-02-09 00:33:39 +0100 | [diff] [blame] | 70 | pshufb XMMTMP, MSG |
Denys Vlasenko | 6472ac9 | 2022-02-03 14:15:20 +0100 | [diff] [blame] | 71 | mova128 MSG, MSGTMP0 |
Denys Vlasenko | a1429fb | 2022-02-03 15:17:42 +0100 | [diff] [blame] | 72 | paddd 0*16-8*16(SHA256CONSTANTS), MSG |
Denys Vlasenko | c2e7780 | 2022-02-12 00:52:12 +0100 | [diff] [blame] | 73 | sha256rnds2 MSG, STATE0, STATE1 |
Denys Vlasenko | 6472ac9 | 2022-02-03 14:15:20 +0100 | [diff] [blame] | 74 | shuf128_32 $0x0E, MSG, MSG |
Denys Vlasenko | c2e7780 | 2022-02-12 00:52:12 +0100 | [diff] [blame] | 75 | sha256rnds2 MSG, STATE1, STATE0 |
Denys Vlasenko | 6472ac9 | 2022-02-03 14:15:20 +0100 | [diff] [blame] | 76 | |
| 77 | /* Rounds 4-7 */ |
| 78 | movu128 1*16(DATA_PTR), MSG |
Denys Vlasenko | c0ff0d4 | 2022-02-09 00:33:39 +0100 | [diff] [blame] | 79 | pshufb XMMTMP, MSG |
Denys Vlasenko | 6472ac9 | 2022-02-03 14:15:20 +0100 | [diff] [blame] | 80 | mova128 MSG, MSGTMP1 |
Denys Vlasenko | a1429fb | 2022-02-03 15:17:42 +0100 | [diff] [blame] | 81 | paddd 1*16-8*16(SHA256CONSTANTS), MSG |
Denys Vlasenko | c2e7780 | 2022-02-12 00:52:12 +0100 | [diff] [blame] | 82 | sha256rnds2 MSG, STATE0, STATE1 |
Denys Vlasenko | 6472ac9 | 2022-02-03 14:15:20 +0100 | [diff] [blame] | 83 | shuf128_32 $0x0E, MSG, MSG |
Denys Vlasenko | c2e7780 | 2022-02-12 00:52:12 +0100 | [diff] [blame] | 84 | sha256rnds2 MSG, STATE1, STATE0 |
Denys Vlasenko | 6472ac9 | 2022-02-03 14:15:20 +0100 | [diff] [blame] | 85 | sha256msg1 MSGTMP1, MSGTMP0 |
| 86 | |
| 87 | /* Rounds 8-11 */ |
| 88 | movu128 2*16(DATA_PTR), MSG |
Denys Vlasenko | c0ff0d4 | 2022-02-09 00:33:39 +0100 | [diff] [blame] | 89 | pshufb XMMTMP, MSG |
Denys Vlasenko | 6472ac9 | 2022-02-03 14:15:20 +0100 | [diff] [blame] | 90 | mova128 MSG, MSGTMP2 |
Denys Vlasenko | a1429fb | 2022-02-03 15:17:42 +0100 | [diff] [blame] | 91 | paddd 2*16-8*16(SHA256CONSTANTS), MSG |
Denys Vlasenko | c2e7780 | 2022-02-12 00:52:12 +0100 | [diff] [blame] | 92 | sha256rnds2 MSG, STATE0, STATE1 |
Denys Vlasenko | 6472ac9 | 2022-02-03 14:15:20 +0100 | [diff] [blame] | 93 | shuf128_32 $0x0E, MSG, MSG |
Denys Vlasenko | c2e7780 | 2022-02-12 00:52:12 +0100 | [diff] [blame] | 94 | sha256rnds2 MSG, STATE1, STATE0 |
Denys Vlasenko | 6472ac9 | 2022-02-03 14:15:20 +0100 | [diff] [blame] | 95 | sha256msg1 MSGTMP2, MSGTMP1 |
| 96 | |
| 97 | /* Rounds 12-15 */ |
| 98 | movu128 3*16(DATA_PTR), MSG |
Denys Vlasenko | c0ff0d4 | 2022-02-09 00:33:39 +0100 | [diff] [blame] | 99 | pshufb XMMTMP, MSG |
Denys Vlasenko | 31c1c31 | 2022-02-06 00:30:03 +0100 | [diff] [blame] | 100 | /* ...to here */ |
Denys Vlasenko | 6472ac9 | 2022-02-03 14:15:20 +0100 | [diff] [blame] | 101 | mova128 MSG, MSGTMP3 |
Denys Vlasenko | a1429fb | 2022-02-03 15:17:42 +0100 | [diff] [blame] | 102 | paddd 3*16-8*16(SHA256CONSTANTS), MSG |
Denys Vlasenko | c2e7780 | 2022-02-12 00:52:12 +0100 | [diff] [blame] | 103 | sha256rnds2 MSG, STATE0, STATE1 |
Denys Vlasenko | c0ff0d4 | 2022-02-09 00:33:39 +0100 | [diff] [blame] | 104 | mova128 MSGTMP3, XMMTMP |
| 105 | palignr $4, MSGTMP2, XMMTMP |
| 106 | paddd XMMTMP, MSGTMP0 |
Denys Vlasenko | 6472ac9 | 2022-02-03 14:15:20 +0100 | [diff] [blame] | 107 | sha256msg2 MSGTMP3, MSGTMP0 |
| 108 | shuf128_32 $0x0E, MSG, MSG |
Denys Vlasenko | c2e7780 | 2022-02-12 00:52:12 +0100 | [diff] [blame] | 109 | sha256rnds2 MSG, STATE1, STATE0 |
Denys Vlasenko | 6472ac9 | 2022-02-03 14:15:20 +0100 | [diff] [blame] | 110 | sha256msg1 MSGTMP3, MSGTMP2 |
| 111 | |
| 112 | /* Rounds 16-19 */ |
| 113 | mova128 MSGTMP0, MSG |
Denys Vlasenko | a1429fb | 2022-02-03 15:17:42 +0100 | [diff] [blame] | 114 | paddd 4*16-8*16(SHA256CONSTANTS), MSG |
Denys Vlasenko | c2e7780 | 2022-02-12 00:52:12 +0100 | [diff] [blame] | 115 | sha256rnds2 MSG, STATE0, STATE1 |
Denys Vlasenko | c0ff0d4 | 2022-02-09 00:33:39 +0100 | [diff] [blame] | 116 | mova128 MSGTMP0, XMMTMP |
| 117 | palignr $4, MSGTMP3, XMMTMP |
| 118 | paddd XMMTMP, MSGTMP1 |
Denys Vlasenko | 6472ac9 | 2022-02-03 14:15:20 +0100 | [diff] [blame] | 119 | sha256msg2 MSGTMP0, MSGTMP1 |
| 120 | shuf128_32 $0x0E, MSG, MSG |
Denys Vlasenko | c2e7780 | 2022-02-12 00:52:12 +0100 | [diff] [blame] | 121 | sha256rnds2 MSG, STATE1, STATE0 |
Denys Vlasenko | 6472ac9 | 2022-02-03 14:15:20 +0100 | [diff] [blame] | 122 | sha256msg1 MSGTMP0, MSGTMP3 |
| 123 | |
| 124 | /* Rounds 20-23 */ |
| 125 | mova128 MSGTMP1, MSG |
Denys Vlasenko | a1429fb | 2022-02-03 15:17:42 +0100 | [diff] [blame] | 126 | paddd 5*16-8*16(SHA256CONSTANTS), MSG |
Denys Vlasenko | c2e7780 | 2022-02-12 00:52:12 +0100 | [diff] [blame] | 127 | sha256rnds2 MSG, STATE0, STATE1 |
Denys Vlasenko | c0ff0d4 | 2022-02-09 00:33:39 +0100 | [diff] [blame] | 128 | mova128 MSGTMP1, XMMTMP |
| 129 | palignr $4, MSGTMP0, XMMTMP |
| 130 | paddd XMMTMP, MSGTMP2 |
Denys Vlasenko | 6472ac9 | 2022-02-03 14:15:20 +0100 | [diff] [blame] | 131 | sha256msg2 MSGTMP1, MSGTMP2 |
| 132 | shuf128_32 $0x0E, MSG, MSG |
Denys Vlasenko | c2e7780 | 2022-02-12 00:52:12 +0100 | [diff] [blame] | 133 | sha256rnds2 MSG, STATE1, STATE0 |
Denys Vlasenko | 6472ac9 | 2022-02-03 14:15:20 +0100 | [diff] [blame] | 134 | sha256msg1 MSGTMP1, MSGTMP0 |
| 135 | |
| 136 | /* Rounds 24-27 */ |
| 137 | mova128 MSGTMP2, MSG |
Denys Vlasenko | a1429fb | 2022-02-03 15:17:42 +0100 | [diff] [blame] | 138 | paddd 6*16-8*16(SHA256CONSTANTS), MSG |
Denys Vlasenko | c2e7780 | 2022-02-12 00:52:12 +0100 | [diff] [blame] | 139 | sha256rnds2 MSG, STATE0, STATE1 |
Denys Vlasenko | c0ff0d4 | 2022-02-09 00:33:39 +0100 | [diff] [blame] | 140 | mova128 MSGTMP2, XMMTMP |
| 141 | palignr $4, MSGTMP1, XMMTMP |
| 142 | paddd XMMTMP, MSGTMP3 |
Denys Vlasenko | 6472ac9 | 2022-02-03 14:15:20 +0100 | [diff] [blame] | 143 | sha256msg2 MSGTMP2, MSGTMP3 |
| 144 | shuf128_32 $0x0E, MSG, MSG |
Denys Vlasenko | c2e7780 | 2022-02-12 00:52:12 +0100 | [diff] [blame] | 145 | sha256rnds2 MSG, STATE1, STATE0 |
Denys Vlasenko | 6472ac9 | 2022-02-03 14:15:20 +0100 | [diff] [blame] | 146 | sha256msg1 MSGTMP2, MSGTMP1 |
| 147 | |
| 148 | /* Rounds 28-31 */ |
| 149 | mova128 MSGTMP3, MSG |
Denys Vlasenko | a1429fb | 2022-02-03 15:17:42 +0100 | [diff] [blame] | 150 | paddd 7*16-8*16(SHA256CONSTANTS), MSG |
Denys Vlasenko | c2e7780 | 2022-02-12 00:52:12 +0100 | [diff] [blame] | 151 | sha256rnds2 MSG, STATE0, STATE1 |
Denys Vlasenko | c0ff0d4 | 2022-02-09 00:33:39 +0100 | [diff] [blame] | 152 | mova128 MSGTMP3, XMMTMP |
| 153 | palignr $4, MSGTMP2, XMMTMP |
| 154 | paddd XMMTMP, MSGTMP0 |
Denys Vlasenko | 6472ac9 | 2022-02-03 14:15:20 +0100 | [diff] [blame] | 155 | sha256msg2 MSGTMP3, MSGTMP0 |
| 156 | shuf128_32 $0x0E, MSG, MSG |
Denys Vlasenko | c2e7780 | 2022-02-12 00:52:12 +0100 | [diff] [blame] | 157 | sha256rnds2 MSG, STATE1, STATE0 |
Denys Vlasenko | 6472ac9 | 2022-02-03 14:15:20 +0100 | [diff] [blame] | 158 | sha256msg1 MSGTMP3, MSGTMP2 |
| 159 | |
| 160 | /* Rounds 32-35 */ |
| 161 | mova128 MSGTMP0, MSG |
Denys Vlasenko | a1429fb | 2022-02-03 15:17:42 +0100 | [diff] [blame] | 162 | paddd 8*16-8*16(SHA256CONSTANTS), MSG |
Denys Vlasenko | c2e7780 | 2022-02-12 00:52:12 +0100 | [diff] [blame] | 163 | sha256rnds2 MSG, STATE0, STATE1 |
Denys Vlasenko | c0ff0d4 | 2022-02-09 00:33:39 +0100 | [diff] [blame] | 164 | mova128 MSGTMP0, XMMTMP |
| 165 | palignr $4, MSGTMP3, XMMTMP |
| 166 | paddd XMMTMP, MSGTMP1 |
Denys Vlasenko | 6472ac9 | 2022-02-03 14:15:20 +0100 | [diff] [blame] | 167 | sha256msg2 MSGTMP0, MSGTMP1 |
| 168 | shuf128_32 $0x0E, MSG, MSG |
Denys Vlasenko | c2e7780 | 2022-02-12 00:52:12 +0100 | [diff] [blame] | 169 | sha256rnds2 MSG, STATE1, STATE0 |
Denys Vlasenko | 6472ac9 | 2022-02-03 14:15:20 +0100 | [diff] [blame] | 170 | sha256msg1 MSGTMP0, MSGTMP3 |
| 171 | |
| 172 | /* Rounds 36-39 */ |
| 173 | mova128 MSGTMP1, MSG |
Denys Vlasenko | a1429fb | 2022-02-03 15:17:42 +0100 | [diff] [blame] | 174 | paddd 9*16-8*16(SHA256CONSTANTS), MSG |
Denys Vlasenko | c2e7780 | 2022-02-12 00:52:12 +0100 | [diff] [blame] | 175 | sha256rnds2 MSG, STATE0, STATE1 |
Denys Vlasenko | c0ff0d4 | 2022-02-09 00:33:39 +0100 | [diff] [blame] | 176 | mova128 MSGTMP1, XMMTMP |
| 177 | palignr $4, MSGTMP0, XMMTMP |
| 178 | paddd XMMTMP, MSGTMP2 |
Denys Vlasenko | 6472ac9 | 2022-02-03 14:15:20 +0100 | [diff] [blame] | 179 | sha256msg2 MSGTMP1, MSGTMP2 |
| 180 | shuf128_32 $0x0E, MSG, MSG |
Denys Vlasenko | c2e7780 | 2022-02-12 00:52:12 +0100 | [diff] [blame] | 181 | sha256rnds2 MSG, STATE1, STATE0 |
Denys Vlasenko | 6472ac9 | 2022-02-03 14:15:20 +0100 | [diff] [blame] | 182 | sha256msg1 MSGTMP1, MSGTMP0 |
| 183 | |
| 184 | /* Rounds 40-43 */ |
| 185 | mova128 MSGTMP2, MSG |
Denys Vlasenko | a1429fb | 2022-02-03 15:17:42 +0100 | [diff] [blame] | 186 | paddd 10*16-8*16(SHA256CONSTANTS), MSG |
Denys Vlasenko | c2e7780 | 2022-02-12 00:52:12 +0100 | [diff] [blame] | 187 | sha256rnds2 MSG, STATE0, STATE1 |
Denys Vlasenko | c0ff0d4 | 2022-02-09 00:33:39 +0100 | [diff] [blame] | 188 | mova128 MSGTMP2, XMMTMP |
| 189 | palignr $4, MSGTMP1, XMMTMP |
| 190 | paddd XMMTMP, MSGTMP3 |
Denys Vlasenko | 6472ac9 | 2022-02-03 14:15:20 +0100 | [diff] [blame] | 191 | sha256msg2 MSGTMP2, MSGTMP3 |
| 192 | shuf128_32 $0x0E, MSG, MSG |
Denys Vlasenko | c2e7780 | 2022-02-12 00:52:12 +0100 | [diff] [blame] | 193 | sha256rnds2 MSG, STATE1, STATE0 |
Denys Vlasenko | 6472ac9 | 2022-02-03 14:15:20 +0100 | [diff] [blame] | 194 | sha256msg1 MSGTMP2, MSGTMP1 |
| 195 | |
| 196 | /* Rounds 44-47 */ |
| 197 | mova128 MSGTMP3, MSG |
Denys Vlasenko | a1429fb | 2022-02-03 15:17:42 +0100 | [diff] [blame] | 198 | paddd 11*16-8*16(SHA256CONSTANTS), MSG |
Denys Vlasenko | c2e7780 | 2022-02-12 00:52:12 +0100 | [diff] [blame] | 199 | sha256rnds2 MSG, STATE0, STATE1 |
Denys Vlasenko | c0ff0d4 | 2022-02-09 00:33:39 +0100 | [diff] [blame] | 200 | mova128 MSGTMP3, XMMTMP |
| 201 | palignr $4, MSGTMP2, XMMTMP |
| 202 | paddd XMMTMP, MSGTMP0 |
Denys Vlasenko | 6472ac9 | 2022-02-03 14:15:20 +0100 | [diff] [blame] | 203 | sha256msg2 MSGTMP3, MSGTMP0 |
| 204 | shuf128_32 $0x0E, MSG, MSG |
Denys Vlasenko | c2e7780 | 2022-02-12 00:52:12 +0100 | [diff] [blame] | 205 | sha256rnds2 MSG, STATE1, STATE0 |
Denys Vlasenko | 6472ac9 | 2022-02-03 14:15:20 +0100 | [diff] [blame] | 206 | sha256msg1 MSGTMP3, MSGTMP2 |
| 207 | |
| 208 | /* Rounds 48-51 */ |
| 209 | mova128 MSGTMP0, MSG |
Denys Vlasenko | a1429fb | 2022-02-03 15:17:42 +0100 | [diff] [blame] | 210 | paddd 12*16-8*16(SHA256CONSTANTS), MSG |
Denys Vlasenko | c2e7780 | 2022-02-12 00:52:12 +0100 | [diff] [blame] | 211 | sha256rnds2 MSG, STATE0, STATE1 |
Denys Vlasenko | c0ff0d4 | 2022-02-09 00:33:39 +0100 | [diff] [blame] | 212 | mova128 MSGTMP0, XMMTMP |
| 213 | palignr $4, MSGTMP3, XMMTMP |
| 214 | paddd XMMTMP, MSGTMP1 |
Denys Vlasenko | 6472ac9 | 2022-02-03 14:15:20 +0100 | [diff] [blame] | 215 | sha256msg2 MSGTMP0, MSGTMP1 |
| 216 | shuf128_32 $0x0E, MSG, MSG |
Denys Vlasenko | c2e7780 | 2022-02-12 00:52:12 +0100 | [diff] [blame] | 217 | sha256rnds2 MSG, STATE1, STATE0 |
Denys Vlasenko | 6472ac9 | 2022-02-03 14:15:20 +0100 | [diff] [blame] | 218 | sha256msg1 MSGTMP0, MSGTMP3 |
| 219 | |
| 220 | /* Rounds 52-55 */ |
| 221 | mova128 MSGTMP1, MSG |
Denys Vlasenko | a1429fb | 2022-02-03 15:17:42 +0100 | [diff] [blame] | 222 | paddd 13*16-8*16(SHA256CONSTANTS), MSG |
Denys Vlasenko | c2e7780 | 2022-02-12 00:52:12 +0100 | [diff] [blame] | 223 | sha256rnds2 MSG, STATE0, STATE1 |
Denys Vlasenko | c0ff0d4 | 2022-02-09 00:33:39 +0100 | [diff] [blame] | 224 | mova128 MSGTMP1, XMMTMP |
| 225 | palignr $4, MSGTMP0, XMMTMP |
| 226 | paddd XMMTMP, MSGTMP2 |
Denys Vlasenko | 6472ac9 | 2022-02-03 14:15:20 +0100 | [diff] [blame] | 227 | sha256msg2 MSGTMP1, MSGTMP2 |
| 228 | shuf128_32 $0x0E, MSG, MSG |
Denys Vlasenko | c2e7780 | 2022-02-12 00:52:12 +0100 | [diff] [blame] | 229 | sha256rnds2 MSG, STATE1, STATE0 |
Denys Vlasenko | 6472ac9 | 2022-02-03 14:15:20 +0100 | [diff] [blame] | 230 | |
| 231 | /* Rounds 56-59 */ |
| 232 | mova128 MSGTMP2, MSG |
Denys Vlasenko | a1429fb | 2022-02-03 15:17:42 +0100 | [diff] [blame] | 233 | paddd 14*16-8*16(SHA256CONSTANTS), MSG |
Denys Vlasenko | c2e7780 | 2022-02-12 00:52:12 +0100 | [diff] [blame] | 234 | sha256rnds2 MSG, STATE0, STATE1 |
Denys Vlasenko | c0ff0d4 | 2022-02-09 00:33:39 +0100 | [diff] [blame] | 235 | mova128 MSGTMP2, XMMTMP |
| 236 | palignr $4, MSGTMP1, XMMTMP |
| 237 | paddd XMMTMP, MSGTMP3 |
Denys Vlasenko | 6472ac9 | 2022-02-03 14:15:20 +0100 | [diff] [blame] | 238 | sha256msg2 MSGTMP2, MSGTMP3 |
| 239 | shuf128_32 $0x0E, MSG, MSG |
Denys Vlasenko | c2e7780 | 2022-02-12 00:52:12 +0100 | [diff] [blame] | 240 | sha256rnds2 MSG, STATE1, STATE0 |
Denys Vlasenko | 6472ac9 | 2022-02-03 14:15:20 +0100 | [diff] [blame] | 241 | |
| 242 | /* Rounds 60-63 */ |
| 243 | mova128 MSGTMP3, MSG |
Denys Vlasenko | a1429fb | 2022-02-03 15:17:42 +0100 | [diff] [blame] | 244 | paddd 15*16-8*16(SHA256CONSTANTS), MSG |
Denys Vlasenko | c2e7780 | 2022-02-12 00:52:12 +0100 | [diff] [blame] | 245 | sha256rnds2 MSG, STATE0, STATE1 |
Denys Vlasenko | 6472ac9 | 2022-02-03 14:15:20 +0100 | [diff] [blame] | 246 | shuf128_32 $0x0E, MSG, MSG |
Denys Vlasenko | c2e7780 | 2022-02-12 00:52:12 +0100 | [diff] [blame] | 247 | sha256rnds2 MSG, STATE1, STATE0 |
Denys Vlasenko | 6472ac9 | 2022-02-03 14:15:20 +0100 | [diff] [blame] | 248 | |
| 249 | /* Add current hash values with previously saved */ |
Denys Vlasenko | c2e7780 | 2022-02-12 00:52:12 +0100 | [diff] [blame] | 250 | paddd SAVE0, STATE0 |
| 251 | paddd SAVE1, STATE1 |
Denys Vlasenko | 6472ac9 | 2022-02-03 14:15:20 +0100 | [diff] [blame] | 252 | |
| 253 | /* Write hash values back in the correct order */ |
Denys Vlasenko | c0ff0d4 | 2022-02-09 00:33:39 +0100 | [diff] [blame] | 254 | mova128 STATE0, XMMTMP |
Denys Vlasenko | 11bcea7 | 2022-02-09 01:42:49 +0100 | [diff] [blame] | 255 | /* shufps takes dwords 0,1 from *2nd* operand, and dwords 2,3 from 1st one */ |
Denys Vlasenko | 6f56fa1 | 2022-02-10 15:38:10 +0100 | [diff] [blame] | 256 | /* --- -------------- HGDC -- FEBA */ |
| 257 | shufps SHUF(3,2,3,2), STATE1, STATE0 /* ABCD */ |
| 258 | shufps SHUF(1,0,1,0), STATE1, XMMTMP /* EFGH */ |
Denys Vlasenko | 6472ac9 | 2022-02-03 14:15:20 +0100 | [diff] [blame] | 259 | movu128 STATE0, 80+0*16(%rdi) |
Denys Vlasenko | 11bcea7 | 2022-02-09 01:42:49 +0100 | [diff] [blame] | 260 | movu128 XMMTMP, 80+1*16(%rdi) |
Denys Vlasenko | 6472ac9 | 2022-02-03 14:15:20 +0100 | [diff] [blame] | 261 | |
| 262 | ret |
| 263 | .size sha256_process_block64_shaNI, .-sha256_process_block64_shaNI |
| 264 | |
Denys Vlasenko | c193cbd | 2022-02-07 02:06:18 +0100 | [diff] [blame] | 265 | .section .rodata.cst256.K256, "aM", @progbits, 256 |
Denys Vlasenko | 6a6c1c0 | 2022-02-09 11:29:23 +0100 | [diff] [blame] | 266 | .balign 16 |
Denys Vlasenko | 6472ac9 | 2022-02-03 14:15:20 +0100 | [diff] [blame] | 267 | K256: |
| 268 | .long 0x428a2f98,0x71374491,0xb5c0fbcf,0xe9b5dba5 |
| 269 | .long 0x3956c25b,0x59f111f1,0x923f82a4,0xab1c5ed5 |
| 270 | .long 0xd807aa98,0x12835b01,0x243185be,0x550c7dc3 |
| 271 | .long 0x72be5d74,0x80deb1fe,0x9bdc06a7,0xc19bf174 |
| 272 | .long 0xe49b69c1,0xefbe4786,0x0fc19dc6,0x240ca1cc |
| 273 | .long 0x2de92c6f,0x4a7484aa,0x5cb0a9dc,0x76f988da |
| 274 | .long 0x983e5152,0xa831c66d,0xb00327c8,0xbf597fc7 |
| 275 | .long 0xc6e00bf3,0xd5a79147,0x06ca6351,0x14292967 |
| 276 | .long 0x27b70a85,0x2e1b2138,0x4d2c6dfc,0x53380d13 |
| 277 | .long 0x650a7354,0x766a0abb,0x81c2c92e,0x92722c85 |
| 278 | .long 0xa2bfe8a1,0xa81a664b,0xc24b8b70,0xc76c51a3 |
| 279 | .long 0xd192e819,0xd6990624,0xf40e3585,0x106aa070 |
| 280 | .long 0x19a4c116,0x1e376c08,0x2748774c,0x34b0bcb5 |
| 281 | .long 0x391c0cb3,0x4ed8aa4a,0x5b9cca4f,0x682e6ff3 |
| 282 | .long 0x748f82ee,0x78a5636f,0x84c87814,0x8cc70208 |
| 283 | .long 0x90befffa,0xa4506ceb,0xbef9a3f7,0xc67178f2 |
| 284 | |
Denys Vlasenko | c193cbd | 2022-02-07 02:06:18 +0100 | [diff] [blame] | 285 | .section .rodata.cst16.PSHUFFLE_BSWAP32_FLIP_MASK, "aM", @progbits, 16 |
Denys Vlasenko | 6a6c1c0 | 2022-02-09 11:29:23 +0100 | [diff] [blame] | 286 | .balign 16 |
Denys Vlasenko | 6472ac9 | 2022-02-03 14:15:20 +0100 | [diff] [blame] | 287 | PSHUFFLE_BSWAP32_FLIP_MASK: |
Denys Vlasenko | 6a6c1c0 | 2022-02-09 11:29:23 +0100 | [diff] [blame] | 288 | .octa 0x0c0d0e0f08090a0b0405060700010203 |
Denys Vlasenko | 6472ac9 | 2022-02-03 14:15:20 +0100 | [diff] [blame] | 289 | |
| 290 | #endif |