| 1 |
/* twofish-amd64.S - AMD64 assembly implementation of Twofish cipher |
| 2 |
* |
| 3 |
* Copyright (C) 2013-2015 Jussi Kivilinna <[email protected]> |
| 4 |
* |
| 5 |
* This file is part of Libgcrypt. |
| 6 |
* |
| 7 |
* Libgcrypt is free software; you can redistribute it and/or modify |
| 8 |
* it under the terms of the GNU Lesser General Public License as |
| 9 |
* published by the Free Software Foundation; either version 2.1 of |
| 10 |
* the License, or (at your option) any later version. |
| 11 |
* |
| 12 |
* Libgcrypt is distributed in the hope that it will be useful, |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
* GNU Lesser General Public License for more details. |
| 16 |
* |
| 17 |
* You should have received a copy of the GNU Lesser General Public |
| 18 |
* License along with this program; if not, see <http://www.gnu.org/licenses/>. |
| 19 |
*/ |
| 20 |
|
| 21 |
#ifdef __x86_64 |
| 22 |
#include <config.h> |
| 23 |
#if (defined(HAVE_COMPATIBLE_GCC_AMD64_PLATFORM_AS) || \ |
| 24 |
defined(HAVE_COMPATIBLE_GCC_WIN64_PLATFORM_AS)) && defined(USE_TWOFISH) |
| 25 |
|
| 26 |
#include "asm-common-amd64.h" |
| 27 |
|
| 28 |
.text |
| 29 |
|
| 30 |
/* structure of TWOFISH_context: */ |
| 31 |
#define s0 0 |
| 32 |
#define s1 ((s0) + 4 * 256) |
| 33 |
#define s2 ((s1) + 4 * 256) |
| 34 |
#define s3 ((s2) + 4 * 256) |
| 35 |
#define w ((s3) + 4 * 256) |
| 36 |
#define k ((w) + 4 * 8) |
| 37 |
|
| 38 |
/* register macros */ |
| 39 |
#define CTX %rdi |
| 40 |
|
| 41 |
#define RA %rax |
| 42 |
#define RB %rbx |
| 43 |
#define RC %rcx |
| 44 |
#define RD %rdx |
| 45 |
|
| 46 |
#define RAd %eax |
| 47 |
#define RBd %ebx |
| 48 |
#define RCd %ecx |
| 49 |
#define RDd %edx |
| 50 |
|
| 51 |
#define RAbl %al |
| 52 |
#define RBbl %bl |
| 53 |
#define RCbl %cl |
| 54 |
#define RDbl %dl |
| 55 |
|
| 56 |
#define RAbh %ah |
| 57 |
#define RBbh %bh |
| 58 |
#define RCbh %ch |
| 59 |
#define RDbh %dh |
| 60 |
|
| 61 |
#define RX %r8 |
| 62 |
#define RY %r9 |
| 63 |
|
| 64 |
#define RXd %r8d |
| 65 |
#define RYd %r9d |
| 66 |
|
| 67 |
#define RT0 %rsi |
| 68 |
#define RT1 %rbp |
| 69 |
#define RT2 %r10 |
| 70 |
#define RT3 %r11 |
| 71 |
|
| 72 |
#define RT0d %esi |
| 73 |
#define RT1d %ebp |
| 74 |
#define RT2d %r10d |
| 75 |
#define RT3d %r11d |
| 76 |
|
| 77 |
/*********************************************************************** |
| 78 |
* AMD64 assembly implementation of the Twofish cipher |
| 79 |
***********************************************************************/ |
| 80 |
#define enc_g1_2(a, b, x, y) \ |
| 81 |
movzbl b ## bl, RT3d; \ |
| 82 |
movzbl b ## bh, RT1d; \ |
| 83 |
movzbl a ## bl, RT2d; \ |
| 84 |
movzbl a ## bh, RT0d; \ |
| 85 |
rorl $16, b ## d; \ |
| 86 |
rorl $16, a ## d; \ |
| 87 |
movl s1(CTX, RT3, 4), RYd; \ |
| 88 |
movzbl b ## bl, RT3d; \ |
| 89 |
movl s0(CTX, RT2, 4), RXd; \ |
| 90 |
movzbl a ## bl, RT2d; \ |
| 91 |
xorl s2(CTX, RT1, 4), RYd; \ |
| 92 |
movzbl b ## bh, RT1d; \ |
| 93 |
xorl s1(CTX, RT0, 4), RXd; \ |
| 94 |
movzbl a ## bh, RT0d; \ |
| 95 |
rorl $16, b ## d; \ |
| 96 |
rorl $16, a ## d; \ |
| 97 |
xorl s3(CTX, RT3, 4), RYd; \ |
| 98 |
xorl s2(CTX, RT2, 4), RXd; \ |
| 99 |
xorl s0(CTX, RT1, 4), RYd; \ |
| 100 |
xorl s3(CTX, RT0, 4), RXd; |
| 101 |
|
| 102 |
#define dec_g1_2(a, b, x, y) \ |
| 103 |
movzbl a ## bl, RT2d; \ |
| 104 |
movzbl a ## bh, RT0d; \ |
| 105 |
movzbl b ## bl, RT3d; \ |
| 106 |
movzbl b ## bh, RT1d; \ |
| 107 |
rorl $16, a ## d; \ |
| 108 |
rorl $16, b ## d; \ |
| 109 |
movl s0(CTX, RT2, 4), RXd; \ |
| 110 |
movzbl a ## bl, RT2d; \ |
| 111 |
movl s1(CTX, RT3, 4), RYd; \ |
| 112 |
movzbl b ## bl, RT3d; \ |
| 113 |
xorl s1(CTX, RT0, 4), RXd; \ |
| 114 |
movzbl a ## bh, RT0d; \ |
| 115 |
xorl s2(CTX, RT1, 4), RYd; \ |
| 116 |
movzbl b ## bh, RT1d; \ |
| 117 |
rorl $16, a ## d; \ |
| 118 |
rorl $16, b ## d; \ |
| 119 |
xorl s2(CTX, RT2, 4), RXd; \ |
| 120 |
xorl s3(CTX, RT3, 4), RYd; \ |
| 121 |
xorl s3(CTX, RT0, 4), RXd; \ |
| 122 |
xorl s0(CTX, RT1, 4), RYd; |
| 123 |
|
| 124 |
#define encrypt_round(ra, rb, rc, rd, n) \ |
| 125 |
enc_g1_2(##ra, ##rb, RX, RY); \ |
| 126 |
\ |
| 127 |
leal (RXd, RYd, 2), RT0d; \ |
| 128 |
addl RYd, RXd; \ |
| 129 |
addl (k + 8 * (n) + 4)(CTX), RT0d; \ |
| 130 |
roll $1, rd ## d; \ |
| 131 |
addl (k + 8 * (n))(CTX), RXd; \ |
| 132 |
xorl RT0d, rd ## d; \ |
| 133 |
xorl RXd, rc ## d; \ |
| 134 |
rorl $1, rc ## d; |
| 135 |
|
| 136 |
#define decrypt_round(ra, rb, rc, rd, n) \ |
| 137 |
dec_g1_2(##ra, ##rb, RX, RY); \ |
| 138 |
\ |
| 139 |
leal (RXd, RYd, 2), RT0d; \ |
| 140 |
addl RYd, RXd; \ |
| 141 |
addl (k + 8 * (n) + 4)(CTX), RT0d; \ |
| 142 |
roll $1, rc ## d; \ |
| 143 |
addl (k + 8 * (n))(CTX), RXd; \ |
| 144 |
xorl RXd, rc ## d; \ |
| 145 |
xorl RT0d, rd ## d; \ |
| 146 |
rorl $1, rd ## d; |
| 147 |
|
| 148 |
#define encrypt_cycle(a, b, c, d, nc) \ |
| 149 |
encrypt_round(##a, ##b, ##c, ##d, (nc) * 2); \ |
| 150 |
encrypt_round(##c, ##d, ##a, ##b, (nc) * 2 + 1); |
| 151 |
|
| 152 |
#define decrypt_cycle(a, b, c, d, nc) \ |
| 153 |
decrypt_round(##c, ##d, ##a, ##b, (nc) * 2 + 1); \ |
| 154 |
decrypt_round(##a, ##b, ##c, ##d, (nc) * 2); |
| 155 |
|
| 156 |
#define inpack(in, n, x, m) \ |
| 157 |
movl (4 * (n))(in), x; \ |
| 158 |
xorl (w + 4 * (m))(CTX), x; |
| 159 |
|
| 160 |
#define outunpack(out, n, x, m) \ |
| 161 |
xorl (w + 4 * (m))(CTX), x; \ |
| 162 |
movl x, (4 * (n))(out); |
| 163 |
|
| 164 |
.align 16 |
| 165 |
.globl _gcry_twofish_amd64_encrypt_block |
| 166 |
ELF(.type _gcry_twofish_amd64_encrypt_block,@function;) |
| 167 |
|
| 168 |
_gcry_twofish_amd64_encrypt_block: |
| 169 |
/* input: |
| 170 |
* %rdi: context, CTX |
| 171 |
* %rsi: dst |
| 172 |
* %rdx: src |
| 173 |
*/ |
| 174 |
CFI_STARTPROC(); |
| 175 |
ENTER_SYSV_FUNC_PARAMS_0_4 |
| 176 |
|
| 177 |
subq $(3 * 8), %rsp; |
| 178 |
CFI_ADJUST_CFA_OFFSET(3 * 8); |
| 179 |
movq %rsi, (0 * 8)(%rsp); |
| 180 |
movq %rbp, (1 * 8)(%rsp); |
| 181 |
movq %rbx, (2 * 8)(%rsp); |
| 182 |
CFI_REL_OFFSET(%rbp, 1 * 8); |
| 183 |
CFI_REL_OFFSET(%rbx, 2 * 8); |
| 184 |
|
| 185 |
movq %rdx, RX; |
| 186 |
inpack(RX, 0, RAd, 0); |
| 187 |
inpack(RX, 1, RBd, 1); |
| 188 |
inpack(RX, 2, RCd, 2); |
| 189 |
inpack(RX, 3, RDd, 3); |
| 190 |
|
| 191 |
encrypt_cycle(RA, RB, RC, RD, 0); |
| 192 |
encrypt_cycle(RA, RB, RC, RD, 1); |
| 193 |
encrypt_cycle(RA, RB, RC, RD, 2); |
| 194 |
encrypt_cycle(RA, RB, RC, RD, 3); |
| 195 |
encrypt_cycle(RA, RB, RC, RD, 4); |
| 196 |
encrypt_cycle(RA, RB, RC, RD, 5); |
| 197 |
encrypt_cycle(RA, RB, RC, RD, 6); |
| 198 |
encrypt_cycle(RA, RB, RC, RD, 7); |
| 199 |
|
| 200 |
movq (0 * 8)(%rsp), RX; /*dst*/ |
| 201 |
outunpack(RX, 0, RCd, 4); |
| 202 |
outunpack(RX, 1, RDd, 5); |
| 203 |
outunpack(RX, 2, RAd, 6); |
| 204 |
outunpack(RX, 3, RBd, 7); |
| 205 |
|
| 206 |
movq (2 * 8)(%rsp), %rbx; |
| 207 |
movq (1 * 8)(%rsp), %rbp; |
| 208 |
CFI_RESTORE(%rbx); |
| 209 |
CFI_RESTORE(%rbp); |
| 210 |
addq $(3 * 8), %rsp; |
| 211 |
CFI_ADJUST_CFA_OFFSET(-3 * 8); |
| 212 |
|
| 213 |
EXIT_SYSV_FUNC |
| 214 |
ret_spec_stop; |
| 215 |
CFI_ENDPROC(); |
| 216 |
ELF(.size _gcry_twofish_amd64_encrypt_block,.-_gcry_twofish_amd64_encrypt_block;) |
| 217 |
|
| 218 |
.align 16 |
| 219 |
.globl _gcry_twofish_amd64_decrypt_block |
| 220 |
ELF(.type _gcry_twofish_amd64_decrypt_block,@function;) |
| 221 |
|
| 222 |
_gcry_twofish_amd64_decrypt_block: |
| 223 |
/* input: |
| 224 |
* %rdi: context, CTX |
| 225 |
* %rsi: dst |
| 226 |
* %rdx: src |
| 227 |
*/ |
| 228 |
CFI_STARTPROC(); |
| 229 |
ENTER_SYSV_FUNC_PARAMS_0_4 |
| 230 |
|
| 231 |
subq $(3 * 8), %rsp; |
| 232 |
CFI_ADJUST_CFA_OFFSET(3 * 8); |
| 233 |
movq %rsi, (0 * 8)(%rsp); |
| 234 |
movq %rbp, (1 * 8)(%rsp); |
| 235 |
movq %rbx, (2 * 8)(%rsp); |
| 236 |
CFI_REL_OFFSET(%rbp, 1 * 8); |
| 237 |
CFI_REL_OFFSET(%rbx, 2 * 8); |
| 238 |
|
| 239 |
movq %rdx, RX; |
| 240 |
inpack(RX, 0, RCd, 4); |
| 241 |
inpack(RX, 1, RDd, 5); |
| 242 |
inpack(RX, 2, RAd, 6); |
| 243 |
inpack(RX, 3, RBd, 7); |
| 244 |
|
| 245 |
decrypt_cycle(RA, RB, RC, RD, 7); |
| 246 |
decrypt_cycle(RA, RB, RC, RD, 6); |
| 247 |
decrypt_cycle(RA, RB, RC, RD, 5); |
| 248 |
decrypt_cycle(RA, RB, RC, RD, 4); |
| 249 |
decrypt_cycle(RA, RB, RC, RD, 3); |
| 250 |
decrypt_cycle(RA, RB, RC, RD, 2); |
| 251 |
decrypt_cycle(RA, RB, RC, RD, 1); |
| 252 |
decrypt_cycle(RA, RB, RC, RD, 0); |
| 253 |
|
| 254 |
movq (0 * 8)(%rsp), RX; /*dst*/ |
| 255 |
outunpack(RX, 0, RAd, 0); |
| 256 |
outunpack(RX, 1, RBd, 1); |
| 257 |
outunpack(RX, 2, RCd, 2); |
| 258 |
outunpack(RX, 3, RDd, 3); |
| 259 |
|
| 260 |
movq (2 * 8)(%rsp), %rbx; |
| 261 |
movq (1 * 8)(%rsp), %rbp; |
| 262 |
CFI_RESTORE(%rbx); |
| 263 |
CFI_RESTORE(%rbp); |
| 264 |
addq $(3 * 8), %rsp; |
| 265 |
CFI_ADJUST_CFA_OFFSET(-3 * 8); |
| 266 |
|
| 267 |
EXIT_SYSV_FUNC |
| 268 |
ret_spec_stop; |
| 269 |
CFI_ENDPROC(); |
| 270 |
ELF(.size _gcry_twofish_amd64_encrypt_block,.-_gcry_twofish_amd64_encrypt_block;) |
| 271 |
|
| 272 |
#undef CTX |
| 273 |
|
| 274 |
#undef RA |
| 275 |
#undef RB |
| 276 |
#undef RC |
| 277 |
#undef RD |
| 278 |
|
| 279 |
#undef RAd |
| 280 |
#undef RBd |
| 281 |
#undef RCd |
| 282 |
#undef RDd |
| 283 |
|
| 284 |
#undef RAbl |
| 285 |
#undef RBbl |
| 286 |
#undef RCbl |
| 287 |
#undef RDbl |
| 288 |
|
| 289 |
#undef RAbh |
| 290 |
#undef RBbh |
| 291 |
#undef RCbh |
| 292 |
#undef RDbh |
| 293 |
|
| 294 |
#undef RX |
| 295 |
#undef RY |
| 296 |
|
| 297 |
#undef RXd |
| 298 |
#undef RYd |
| 299 |
|
| 300 |
#undef RT0 |
| 301 |
#undef RT1 |
| 302 |
#undef RT2 |
| 303 |
#undef RT3 |
| 304 |
|
| 305 |
#undef RT0d |
| 306 |
#undef RT1d |
| 307 |
#undef RT2d |
| 308 |
#undef RT3d |
| 309 |
|
| 310 |
/*********************************************************************** |
| 311 |
* AMD64 assembly implementation of the Twofish cipher, 3-way parallel |
| 312 |
***********************************************************************/ |
| 313 |
#define CTX %rdi |
| 314 |
#define RIO %rdx |
| 315 |
|
| 316 |
#define RAB0 %rax |
| 317 |
#define RAB1 %rbx |
| 318 |
#define RAB2 %rcx |
| 319 |
|
| 320 |
#define RAB0d %eax |
| 321 |
#define RAB1d %ebx |
| 322 |
#define RAB2d %ecx |
| 323 |
|
| 324 |
#define RAB0bh %ah |
| 325 |
#define RAB1bh %bh |
| 326 |
#define RAB2bh %ch |
| 327 |
|
| 328 |
#define RAB0bl %al |
| 329 |
#define RAB1bl %bl |
| 330 |
#define RAB2bl %cl |
| 331 |
|
| 332 |
#define RCD0 %r8 |
| 333 |
#define RCD1 %r9 |
| 334 |
#define RCD2 %r10 |
| 335 |
|
| 336 |
#define RCD0d %r8d |
| 337 |
#define RCD1d %r9d |
| 338 |
#define RCD2d %r10d |
| 339 |
|
| 340 |
#define RX0 %rbp |
| 341 |
#define RX1 %r11 |
| 342 |
#define RX2 %r12 |
| 343 |
|
| 344 |
#define RX0d %ebp |
| 345 |
#define RX1d %r11d |
| 346 |
#define RX2d %r12d |
| 347 |
|
| 348 |
#define RY0 %r13 |
| 349 |
#define RY1 %r14 |
| 350 |
#define RY2 %r15 |
| 351 |
|
| 352 |
#define RY0d %r13d |
| 353 |
#define RY1d %r14d |
| 354 |
#define RY2d %r15d |
| 355 |
|
| 356 |
#define RT0 %rdx |
| 357 |
#define RT1 %rsi |
| 358 |
|
| 359 |
#define RT0d %edx |
| 360 |
#define RT1d %esi |
| 361 |
|
| 362 |
#define do16bit_ror(rot, op1, op2, T0, T1, tmp1, tmp2, ab, dst) \ |
| 363 |
movzbl ab ## bl, tmp2 ## d; \ |
| 364 |
movzbl ab ## bh, tmp1 ## d; \ |
| 365 |
rorq $(rot), ab; \ |
| 366 |
op1##l T0(CTX, tmp2, 4), dst ## d; \ |
| 367 |
op2##l T1(CTX, tmp1, 4), dst ## d; |
| 368 |
|
| 369 |
/* |
| 370 |
* Combined G1 & G2 function. Reordered with help of rotates to have moves |
| 371 |
* at beginning. |
| 372 |
*/ |
| 373 |
#define g1g2_3(ab, cd, Tx0, Tx1, Tx2, Tx3, Ty0, Ty1, Ty2, Ty3, x, y) \ |
| 374 |
/* G1,1 && G2,1 */ \ |
| 375 |
do16bit_ror(32, mov, xor, Tx0, Tx1, RT0, x ## 0, ab ## 0, x ## 0); \ |
| 376 |
do16bit_ror(48, mov, xor, Ty1, Ty2, RT0, y ## 0, ab ## 0, y ## 0); \ |
| 377 |
\ |
| 378 |
do16bit_ror(32, mov, xor, Tx0, Tx1, RT0, x ## 1, ab ## 1, x ## 1); \ |
| 379 |
do16bit_ror(48, mov, xor, Ty1, Ty2, RT0, y ## 1, ab ## 1, y ## 1); \ |
| 380 |
\ |
| 381 |
do16bit_ror(32, mov, xor, Tx0, Tx1, RT0, x ## 2, ab ## 2, x ## 2); \ |
| 382 |
do16bit_ror(48, mov, xor, Ty1, Ty2, RT0, y ## 2, ab ## 2, y ## 2); \ |
| 383 |
\ |
| 384 |
/* G1,2 && G2,2 */ \ |
| 385 |
do16bit_ror(32, xor, xor, Tx2, Tx3, RT0, RT1, ab ## 0, x ## 0); \ |
| 386 |
do16bit_ror(16, xor, xor, Ty3, Ty0, RT0, RT1, ab ## 0, y ## 0); \ |
| 387 |
movq ab ## 0, RT0; \ |
| 388 |
movq cd ## 0, ab ## 0; \ |
| 389 |
movq RT0, cd ## 0; \ |
| 390 |
\ |
| 391 |
do16bit_ror(32, xor, xor, Tx2, Tx3, RT0, RT1, ab ## 1, x ## 1); \ |
| 392 |
do16bit_ror(16, xor, xor, Ty3, Ty0, RT0, RT1, ab ## 1, y ## 1); \ |
| 393 |
movq ab ## 1, RT0; \ |
| 394 |
movq cd ## 1, ab ## 1; \ |
| 395 |
movq RT0, cd ## 1; \ |
| 396 |
\ |
| 397 |
do16bit_ror(32, xor, xor, Tx2, Tx3, RT0, RT1, ab ## 2, x ## 2); \ |
| 398 |
do16bit_ror(16, xor, xor, Ty3, Ty0, RT0, RT1, ab ## 2, y ## 2); \ |
| 399 |
movq ab ## 2, RT0; \ |
| 400 |
movq cd ## 2, ab ## 2; \ |
| 401 |
movq RT0, cd ## 2; |
| 402 |
|
| 403 |
#define enc_round_end(ab, x, y, n) \ |
| 404 |
addl y ## d, x ## d; \ |
| 405 |
addl x ## d, y ## d; \ |
| 406 |
addl k+4*(2*(n))(CTX), x ## d; \ |
| 407 |
xorl ab ## d, x ## d; \ |
| 408 |
addl k+4*(2*(n)+1)(CTX), y ## d; \ |
| 409 |
shrq $32, ab; \ |
| 410 |
roll $1, ab ## d; \ |
| 411 |
xorl y ## d, ab ## d; \ |
| 412 |
shlq $32, ab; \ |
| 413 |
rorl $1, x ## d; \ |
| 414 |
orq x, ab; |
| 415 |
|
| 416 |
#define dec_round_end(ba, x, y, n) \ |
| 417 |
addl y ## d, x ## d; \ |
| 418 |
addl x ## d, y ## d; \ |
| 419 |
addl k+4*(2*(n))(CTX), x ## d; \ |
| 420 |
addl k+4*(2*(n)+1)(CTX), y ## d; \ |
| 421 |
xorl ba ## d, y ## d; \ |
| 422 |
shrq $32, ba; \ |
| 423 |
roll $1, ba ## d; \ |
| 424 |
xorl x ## d, ba ## d; \ |
| 425 |
shlq $32, ba; \ |
| 426 |
rorl $1, y ## d; \ |
| 427 |
orq y, ba; |
| 428 |
|
| 429 |
#define encrypt_round3(ab, cd, n) \ |
| 430 |
g1g2_3(ab, cd, s0, s1, s2, s3, s0, s1, s2, s3, RX, RY); \ |
| 431 |
\ |
| 432 |
enc_round_end(ab ## 0, RX0, RY0, n); \ |
| 433 |
enc_round_end(ab ## 1, RX1, RY1, n); \ |
| 434 |
enc_round_end(ab ## 2, RX2, RY2, n); |
| 435 |
|
| 436 |
#define decrypt_round3(ba, dc, n) \ |
| 437 |
g1g2_3(ba, dc, s1, s2, s3, s0, s3, s0, s1, s2, RY, RX); \ |
| 438 |
\ |
| 439 |
dec_round_end(ba ## 0, RX0, RY0, n); \ |
| 440 |
dec_round_end(ba ## 1, RX1, RY1, n); \ |
| 441 |
dec_round_end(ba ## 2, RX2, RY2, n); |
| 442 |
|
| 443 |
#define encrypt_cycle3(ab, cd, n) \ |
| 444 |
encrypt_round3(ab, cd, n*2); \ |
| 445 |
encrypt_round3(ab, cd, (n*2)+1); |
| 446 |
|
| 447 |
#define decrypt_cycle3(ba, dc, n) \ |
| 448 |
decrypt_round3(ba, dc, (n*2)+1); \ |
| 449 |
decrypt_round3(ba, dc, (n*2)); |
| 450 |
|
| 451 |
#define inpack3(xy, m) \ |
| 452 |
xorq w+4*m(CTX), xy ## 0; \ |
| 453 |
xorq w+4*m(CTX), xy ## 1; \ |
| 454 |
xorq w+4*m(CTX), xy ## 2; |
| 455 |
|
| 456 |
#define outunpack3(xy, m) \ |
| 457 |
xorq w+4*m(CTX), xy ## 0; \ |
| 458 |
xorq w+4*m(CTX), xy ## 1; \ |
| 459 |
xorq w+4*m(CTX), xy ## 2; |
| 460 |
|
| 461 |
#define inpack_enc3() \ |
| 462 |
inpack3(RAB, 0); \ |
| 463 |
inpack3(RCD, 2); |
| 464 |
|
| 465 |
#define outunpack_enc3() \ |
| 466 |
outunpack3(RAB, 6); \ |
| 467 |
outunpack3(RCD, 4); |
| 468 |
|
| 469 |
#define inpack_dec3() \ |
| 470 |
inpack3(RAB, 4); \ |
| 471 |
rorq $32, RAB0; \ |
| 472 |
rorq $32, RAB1; \ |
| 473 |
rorq $32, RAB2; \ |
| 474 |
inpack3(RCD, 6); \ |
| 475 |
rorq $32, RCD0; \ |
| 476 |
rorq $32, RCD1; \ |
| 477 |
rorq $32, RCD2; |
| 478 |
|
| 479 |
#define outunpack_dec3() \ |
| 480 |
rorq $32, RCD0; \ |
| 481 |
rorq $32, RCD1; \ |
| 482 |
rorq $32, RCD2; \ |
| 483 |
outunpack3(RCD, 0); \ |
| 484 |
rorq $32, RAB0; \ |
| 485 |
rorq $32, RAB1; \ |
| 486 |
rorq $32, RAB2; \ |
| 487 |
outunpack3(RAB, 2); |
| 488 |
|
| 489 |
.align 16 |
| 490 |
ELF(.type __twofish_enc_blk3,@function;) |
| 491 |
|
| 492 |
__twofish_enc_blk3: |
| 493 |
/* input: |
| 494 |
* %rdi: ctx, CTX |
| 495 |
* RAB0,RCD0,RAB1,RCD1,RAB2,RCD2: three plaintext blocks |
| 496 |
* output: |
| 497 |
* RCD0,RAB0,RCD1,RAB1,RCD2,RAB2: three ciphertext blocks |
| 498 |
*/ |
| 499 |
CFI_STARTPROC(); |
| 500 |
|
| 501 |
inpack_enc3(); |
| 502 |
|
| 503 |
encrypt_cycle3(RAB, RCD, 0); |
| 504 |
encrypt_cycle3(RAB, RCD, 1); |
| 505 |
encrypt_cycle3(RAB, RCD, 2); |
| 506 |
encrypt_cycle3(RAB, RCD, 3); |
| 507 |
encrypt_cycle3(RAB, RCD, 4); |
| 508 |
encrypt_cycle3(RAB, RCD, 5); |
| 509 |
encrypt_cycle3(RAB, RCD, 6); |
| 510 |
encrypt_cycle3(RAB, RCD, 7); |
| 511 |
|
| 512 |
outunpack_enc3(); |
| 513 |
|
| 514 |
ret_spec_stop; |
| 515 |
CFI_ENDPROC(); |
| 516 |
ELF(.size __twofish_enc_blk3,.-__twofish_enc_blk3;) |
| 517 |
|
| 518 |
.align 16 |
| 519 |
ELF(.type __twofish_dec_blk3,@function;) |
| 520 |
|
| 521 |
__twofish_dec_blk3: |
| 522 |
/* input: |
| 523 |
* %rdi: ctx, CTX |
| 524 |
* RAB0,RCD0,RAB1,RCD1,RAB2,RCD2: three ciphertext blocks |
| 525 |
* output: |
| 526 |
* RCD0,RAB0,RCD1,RAB1,RCD2,RAB2: three plaintext blocks |
| 527 |
*/ |
| 528 |
CFI_STARTPROC(); |
| 529 |
|
| 530 |
inpack_dec3(); |
| 531 |
|
| 532 |
decrypt_cycle3(RAB, RCD, 7); |
| 533 |
decrypt_cycle3(RAB, RCD, 6); |
| 534 |
decrypt_cycle3(RAB, RCD, 5); |
| 535 |
decrypt_cycle3(RAB, RCD, 4); |
| 536 |
decrypt_cycle3(RAB, RCD, 3); |
| 537 |
decrypt_cycle3(RAB, RCD, 2); |
| 538 |
decrypt_cycle3(RAB, RCD, 1); |
| 539 |
decrypt_cycle3(RAB, RCD, 0); |
| 540 |
|
| 541 |
outunpack_dec3(); |
| 542 |
|
| 543 |
ret_spec_stop; |
| 544 |
CFI_ENDPROC(); |
| 545 |
ELF(.size __twofish_dec_blk3,.-__twofish_dec_blk3;) |
| 546 |
|
| 547 |
.align 16 |
| 548 |
.globl _gcry_twofish_amd64_blk3 |
| 549 |
ELF(.type _gcry_twofish_amd64_blk3,@function;) |
| 550 |
_gcry_twofish_amd64_blk3: |
| 551 |
/* input: |
| 552 |
* %rdi: ctx, CTX |
| 553 |
* %rsi: dst (3 blocks) |
| 554 |
* %rdx: src (3 blocks) |
| 555 |
* %ecx: encrypt (0 or 1) |
| 556 |
*/ |
| 557 |
CFI_STARTPROC(); |
| 558 |
ENTER_SYSV_FUNC_PARAMS_0_4 |
| 559 |
|
| 560 |
subq $(8 * 8), %rsp; |
| 561 |
CFI_ADJUST_CFA_OFFSET(8 * 8); |
| 562 |
movq %rbp, (0 * 8)(%rsp); |
| 563 |
movq %rbx, (1 * 8)(%rsp); |
| 564 |
movq %r12, (2 * 8)(%rsp); |
| 565 |
movq %r13, (3 * 8)(%rsp); |
| 566 |
movq %r14, (4 * 8)(%rsp); |
| 567 |
movq %r15, (5 * 8)(%rsp); |
| 568 |
CFI_REL_OFFSET(%rbp, 0 * 8); |
| 569 |
CFI_REL_OFFSET(%rbx, 1 * 8); |
| 570 |
CFI_REL_OFFSET(%r12, 2 * 8); |
| 571 |
CFI_REL_OFFSET(%r13, 3 * 8); |
| 572 |
CFI_REL_OFFSET(%r14, 4 * 8); |
| 573 |
CFI_REL_OFFSET(%r15, 5 * 8); |
| 574 |
|
| 575 |
testl %ecx, %ecx; |
| 576 |
movq %rdx, RX0; |
| 577 |
movq %rsi, (6 * 8)(%rsp); |
| 578 |
|
| 579 |
movq (0 * 8)(RX0), RAB0; |
| 580 |
movq (1 * 8)(RX0), RCD0; |
| 581 |
movq (2 * 8)(RX0), RAB1; |
| 582 |
movq (3 * 8)(RX0), RCD1; |
| 583 |
movq (4 * 8)(RX0), RAB2; |
| 584 |
movq (5 * 8)(RX0), RCD2; |
| 585 |
|
| 586 |
jz .Lblk1_3_dec; |
| 587 |
call __twofish_enc_blk3; |
| 588 |
jmp .Lblk1_3_end; |
| 589 |
.Lblk1_3_dec: |
| 590 |
call __twofish_dec_blk3; |
| 591 |
|
| 592 |
.Lblk1_3_end: |
| 593 |
movq (6 * 8)(%rsp), RX0; |
| 594 |
movq RCD0, (0 * 8)(RX0); |
| 595 |
movq RAB0, (1 * 8)(RX0); |
| 596 |
movq RCD1, (2 * 8)(RX0); |
| 597 |
movq RAB1, (3 * 8)(RX0); |
| 598 |
movq RCD2, (4 * 8)(RX0); |
| 599 |
movq RAB2, (5 * 8)(RX0); |
| 600 |
|
| 601 |
movq (0 * 8)(%rsp), %rbp; |
| 602 |
movq (1 * 8)(%rsp), %rbx; |
| 603 |
movq (2 * 8)(%rsp), %r12; |
| 604 |
movq (3 * 8)(%rsp), %r13; |
| 605 |
movq (4 * 8)(%rsp), %r14; |
| 606 |
movq (5 * 8)(%rsp), %r15; |
| 607 |
CFI_RESTORE(%rbp); |
| 608 |
CFI_RESTORE(%rbx); |
| 609 |
CFI_RESTORE(%r12); |
| 610 |
CFI_RESTORE(%r13); |
| 611 |
CFI_RESTORE(%r14); |
| 612 |
CFI_RESTORE(%r15); |
| 613 |
addq $(8 * 8), %rsp; |
| 614 |
CFI_ADJUST_CFA_OFFSET(-8 * 8); |
| 615 |
|
| 616 |
EXIT_SYSV_FUNC |
| 617 |
ret_spec_stop; |
| 618 |
CFI_ENDPROC(); |
| 619 |
ELF(.size _gcry_twofish_amd64_blk3,.-_gcry_twofish_amd64_blk3;) |
| 620 |
|
| 621 |
.align 16 |
| 622 |
.globl _gcry_twofish_amd64_ctr_enc |
| 623 |
ELF(.type _gcry_twofish_amd64_ctr_enc,@function;) |
| 624 |
_gcry_twofish_amd64_ctr_enc: |
| 625 |
/* input: |
| 626 |
* %rdi: ctx, CTX |
| 627 |
* %rsi: dst (3 blocks) |
| 628 |
* %rdx: src (3 blocks) |
| 629 |
* %rcx: iv (big endian, 128bit) |
| 630 |
*/ |
| 631 |
CFI_STARTPROC(); |
| 632 |
ENTER_SYSV_FUNC_PARAMS_0_4 |
| 633 |
|
| 634 |
subq $(8 * 8), %rsp; |
| 635 |
CFI_ADJUST_CFA_OFFSET(8 * 8); |
| 636 |
movq %rbp, (0 * 8)(%rsp); |
| 637 |
movq %rbx, (1 * 8)(%rsp); |
| 638 |
movq %r12, (2 * 8)(%rsp); |
| 639 |
movq %r13, (3 * 8)(%rsp); |
| 640 |
movq %r14, (4 * 8)(%rsp); |
| 641 |
movq %r15, (5 * 8)(%rsp); |
| 642 |
CFI_REL_OFFSET(%rbp, 0 * 8); |
| 643 |
CFI_REL_OFFSET(%rbx, 1 * 8); |
| 644 |
CFI_REL_OFFSET(%r12, 2 * 8); |
| 645 |
CFI_REL_OFFSET(%r13, 3 * 8); |
| 646 |
CFI_REL_OFFSET(%r14, 4 * 8); |
| 647 |
CFI_REL_OFFSET(%r15, 5 * 8); |
| 648 |
|
| 649 |
movq %rsi, (6 * 8)(%rsp); |
| 650 |
movq %rdx, (7 * 8)(%rsp); |
| 651 |
movq %rcx, RX0; |
| 652 |
|
| 653 |
/* load IV and byteswap */ |
| 654 |
movq 8(RX0), RT0; |
| 655 |
movq 0(RX0), RT1; |
| 656 |
movq RT0, RCD0; |
| 657 |
movq RT1, RAB0; |
| 658 |
bswapq RT0; |
| 659 |
bswapq RT1; |
| 660 |
|
| 661 |
/* construct IVs */ |
| 662 |
movq RT0, RCD1; |
| 663 |
movq RT1, RAB1; |
| 664 |
movq RT0, RCD2; |
| 665 |
movq RT1, RAB2; |
| 666 |
addq $1, RCD1; |
| 667 |
adcq $0, RAB1; |
| 668 |
bswapq RCD1; |
| 669 |
bswapq RAB1; |
| 670 |
addq $2, RCD2; |
| 671 |
adcq $0, RAB2; |
| 672 |
bswapq RCD2; |
| 673 |
bswapq RAB2; |
| 674 |
addq $3, RT0; |
| 675 |
adcq $0, RT1; |
| 676 |
bswapq RT0; |
| 677 |
bswapq RT1; |
| 678 |
|
| 679 |
/* store new IV */ |
| 680 |
movq RT0, 8(RX0); |
| 681 |
movq RT1, 0(RX0); |
| 682 |
|
| 683 |
call __twofish_enc_blk3; |
| 684 |
|
| 685 |
movq (7 * 8)(%rsp), RX0; /*src*/ |
| 686 |
movq (6 * 8)(%rsp), RX1; /*dst*/ |
| 687 |
|
| 688 |
/* XOR key-stream with plaintext */ |
| 689 |
xorq (0 * 8)(RX0), RCD0; |
| 690 |
xorq (1 * 8)(RX0), RAB0; |
| 691 |
xorq (2 * 8)(RX0), RCD1; |
| 692 |
xorq (3 * 8)(RX0), RAB1; |
| 693 |
xorq (4 * 8)(RX0), RCD2; |
| 694 |
xorq (5 * 8)(RX0), RAB2; |
| 695 |
movq RCD0, (0 * 8)(RX1); |
| 696 |
movq RAB0, (1 * 8)(RX1); |
| 697 |
movq RCD1, (2 * 8)(RX1); |
| 698 |
movq RAB1, (3 * 8)(RX1); |
| 699 |
movq RCD2, (4 * 8)(RX1); |
| 700 |
movq RAB2, (5 * 8)(RX1); |
| 701 |
|
| 702 |
movq (0 * 8)(%rsp), %rbp; |
| 703 |
movq (1 * 8)(%rsp), %rbx; |
| 704 |
movq (2 * 8)(%rsp), %r12; |
| 705 |
movq (3 * 8)(%rsp), %r13; |
| 706 |
movq (4 * 8)(%rsp), %r14; |
| 707 |
movq (5 * 8)(%rsp), %r15; |
| 708 |
CFI_RESTORE(%rbp); |
| 709 |
CFI_RESTORE(%rbx); |
| 710 |
CFI_RESTORE(%r12); |
| 711 |
CFI_RESTORE(%r13); |
| 712 |
CFI_RESTORE(%r14); |
| 713 |
CFI_RESTORE(%r15); |
| 714 |
addq $(8 * 8), %rsp; |
| 715 |
CFI_ADJUST_CFA_OFFSET(-8 * 8); |
| 716 |
|
| 717 |
EXIT_SYSV_FUNC |
| 718 |
ret_spec_stop; |
| 719 |
CFI_ENDPROC(); |
| 720 |
ELF(.size _gcry_twofish_amd64_ctr_enc,.-_gcry_twofish_amd64_ctr_enc;) |
| 721 |
|
| 722 |
.align 16 |
| 723 |
.globl _gcry_twofish_amd64_cbc_dec |
| 724 |
ELF(.type _gcry_twofish_amd64_cbc_dec,@function;) |
| 725 |
_gcry_twofish_amd64_cbc_dec: |
| 726 |
/* input: |
| 727 |
* %rdi: ctx, CTX |
| 728 |
* %rsi: dst (3 blocks) |
| 729 |
* %rdx: src (3 blocks) |
| 730 |
* %rcx: iv (128bit) |
| 731 |
*/ |
| 732 |
CFI_STARTPROC(); |
| 733 |
ENTER_SYSV_FUNC_PARAMS_0_4 |
| 734 |
|
| 735 |
subq $(9 * 8), %rsp; |
| 736 |
CFI_ADJUST_CFA_OFFSET(9 * 8); |
| 737 |
movq %rbp, (0 * 8)(%rsp); |
| 738 |
movq %rbx, (1 * 8)(%rsp); |
| 739 |
movq %r12, (2 * 8)(%rsp); |
| 740 |
movq %r13, (3 * 8)(%rsp); |
| 741 |
movq %r14, (4 * 8)(%rsp); |
| 742 |
movq %r15, (5 * 8)(%rsp); |
| 743 |
CFI_REL_OFFSET(%rbp, 0 * 8); |
| 744 |
CFI_REL_OFFSET(%rbx, 1 * 8); |
| 745 |
CFI_REL_OFFSET(%r12, 2 * 8); |
| 746 |
CFI_REL_OFFSET(%r13, 3 * 8); |
| 747 |
CFI_REL_OFFSET(%r14, 4 * 8); |
| 748 |
CFI_REL_OFFSET(%r15, 5 * 8); |
| 749 |
|
| 750 |
movq %rsi, (6 * 8)(%rsp); |
| 751 |
movq %rdx, (7 * 8)(%rsp); |
| 752 |
movq %rcx, (8 * 8)(%rsp); |
| 753 |
movq %rdx, RX0; |
| 754 |
|
| 755 |
/* load input */ |
| 756 |
movq (0 * 8)(RX0), RAB0; |
| 757 |
movq (1 * 8)(RX0), RCD0; |
| 758 |
movq (2 * 8)(RX0), RAB1; |
| 759 |
movq (3 * 8)(RX0), RCD1; |
| 760 |
movq (4 * 8)(RX0), RAB2; |
| 761 |
movq (5 * 8)(RX0), RCD2; |
| 762 |
|
| 763 |
call __twofish_dec_blk3; |
| 764 |
|
| 765 |
movq (8 * 8)(%rsp), RT0; /*iv*/ |
| 766 |
movq (7 * 8)(%rsp), RX0; /*src*/ |
| 767 |
movq (6 * 8)(%rsp), RX1; /*dst*/ |
| 768 |
|
| 769 |
movq (4 * 8)(RX0), RY0; |
| 770 |
movq (5 * 8)(RX0), RY1; |
| 771 |
xorq (0 * 8)(RT0), RCD0; |
| 772 |
xorq (1 * 8)(RT0), RAB0; |
| 773 |
xorq (0 * 8)(RX0), RCD1; |
| 774 |
xorq (1 * 8)(RX0), RAB1; |
| 775 |
xorq (2 * 8)(RX0), RCD2; |
| 776 |
xorq (3 * 8)(RX0), RAB2; |
| 777 |
movq RY0, (0 * 8)(RT0); |
| 778 |
movq RY1, (1 * 8)(RT0); |
| 779 |
|
| 780 |
movq RCD0, (0 * 8)(RX1); |
| 781 |
movq RAB0, (1 * 8)(RX1); |
| 782 |
movq RCD1, (2 * 8)(RX1); |
| 783 |
movq RAB1, (3 * 8)(RX1); |
| 784 |
movq RCD2, (4 * 8)(RX1); |
| 785 |
movq RAB2, (5 * 8)(RX1); |
| 786 |
|
| 787 |
movq (0 * 8)(%rsp), %rbp; |
| 788 |
movq (1 * 8)(%rsp), %rbx; |
| 789 |
movq (2 * 8)(%rsp), %r12; |
| 790 |
movq (3 * 8)(%rsp), %r13; |
| 791 |
movq (4 * 8)(%rsp), %r14; |
| 792 |
movq (5 * 8)(%rsp), %r15; |
| 793 |
CFI_RESTORE(%rbp); |
| 794 |
CFI_RESTORE(%rbx); |
| 795 |
CFI_RESTORE(%r12); |
| 796 |
CFI_RESTORE(%r13); |
| 797 |
CFI_RESTORE(%r14); |
| 798 |
CFI_RESTORE(%r15); |
| 799 |
addq $(9 * 8), %rsp; |
| 800 |
CFI_ADJUST_CFA_OFFSET(-9 * 8); |
| 801 |
|
| 802 |
EXIT_SYSV_FUNC |
| 803 |
ret_spec_stop; |
| 804 |
CFI_ENDPROC(); |
| 805 |
ELF(.size _gcry_twofish_amd64_cbc_dec,.-_gcry_twofish_amd64_cbc_dec;) |
| 806 |
|
| 807 |
.align 16 |
| 808 |
.globl _gcry_twofish_amd64_cfb_dec |
| 809 |
ELF(.type _gcry_twofish_amd64_cfb_dec,@function;) |
| 810 |
_gcry_twofish_amd64_cfb_dec: |
| 811 |
/* input: |
| 812 |
* %rdi: ctx, CTX |
| 813 |
* %rsi: dst (3 blocks) |
| 814 |
* %rdx: src (3 blocks) |
| 815 |
* %rcx: iv (128bit) |
| 816 |
*/ |
| 817 |
CFI_STARTPROC(); |
| 818 |
ENTER_SYSV_FUNC_PARAMS_0_4 |
| 819 |
|
| 820 |
subq $(8 * 8), %rsp; |
| 821 |
CFI_ADJUST_CFA_OFFSET(8 * 8); |
| 822 |
movq %rbp, (0 * 8)(%rsp); |
| 823 |
movq %rbx, (1 * 8)(%rsp); |
| 824 |
movq %r12, (2 * 8)(%rsp); |
| 825 |
movq %r13, (3 * 8)(%rsp); |
| 826 |
movq %r14, (4 * 8)(%rsp); |
| 827 |
movq %r15, (5 * 8)(%rsp); |
| 828 |
CFI_REL_OFFSET(%rbp, 0 * 8); |
| 829 |
CFI_REL_OFFSET(%rbx, 1 * 8); |
| 830 |
CFI_REL_OFFSET(%r12, 2 * 8); |
| 831 |
CFI_REL_OFFSET(%r13, 3 * 8); |
| 832 |
CFI_REL_OFFSET(%r14, 4 * 8); |
| 833 |
CFI_REL_OFFSET(%r15, 5 * 8); |
| 834 |
|
| 835 |
movq %rsi, (6 * 8)(%rsp); |
| 836 |
movq %rdx, (7 * 8)(%rsp); |
| 837 |
movq %rdx, RX0; |
| 838 |
movq %rcx, RX1; |
| 839 |
|
| 840 |
/* load input */ |
| 841 |
movq (0 * 8)(RX1), RAB0; |
| 842 |
movq (1 * 8)(RX1), RCD0; |
| 843 |
movq (0 * 8)(RX0), RAB1; |
| 844 |
movq (1 * 8)(RX0), RCD1; |
| 845 |
movq (2 * 8)(RX0), RAB2; |
| 846 |
movq (3 * 8)(RX0), RCD2; |
| 847 |
|
| 848 |
/* Update IV */ |
| 849 |
movq (4 * 8)(RX0), RY0; |
| 850 |
movq (5 * 8)(RX0), RY1; |
| 851 |
movq RY0, (0 * 8)(RX1); |
| 852 |
movq RY1, (1 * 8)(RX1); |
| 853 |
|
| 854 |
call __twofish_enc_blk3; |
| 855 |
|
| 856 |
movq (7 * 8)(%rsp), RX0; /*src*/ |
| 857 |
movq (6 * 8)(%rsp), RX1; /*dst*/ |
| 858 |
|
| 859 |
xorq (0 * 8)(RX0), RCD0; |
| 860 |
xorq (1 * 8)(RX0), RAB0; |
| 861 |
xorq (2 * 8)(RX0), RCD1; |
| 862 |
xorq (3 * 8)(RX0), RAB1; |
| 863 |
xorq (4 * 8)(RX0), RCD2; |
| 864 |
xorq (5 * 8)(RX0), RAB2; |
| 865 |
movq RCD0, (0 * 8)(RX1); |
| 866 |
movq RAB0, (1 * 8)(RX1); |
| 867 |
movq RCD1, (2 * 8)(RX1); |
| 868 |
movq RAB1, (3 * 8)(RX1); |
| 869 |
movq RCD2, (4 * 8)(RX1); |
| 870 |
movq RAB2, (5 * 8)(RX1); |
| 871 |
|
| 872 |
movq (0 * 8)(%rsp), %rbp; |
| 873 |
movq (1 * 8)(%rsp), %rbx; |
| 874 |
movq (2 * 8)(%rsp), %r12; |
| 875 |
movq (3 * 8)(%rsp), %r13; |
| 876 |
movq (4 * 8)(%rsp), %r14; |
| 877 |
movq (5 * 8)(%rsp), %r15; |
| 878 |
CFI_RESTORE(%rbp); |
| 879 |
CFI_RESTORE(%rbx); |
| 880 |
CFI_RESTORE(%r12); |
| 881 |
CFI_RESTORE(%r13); |
| 882 |
CFI_RESTORE(%r14); |
| 883 |
CFI_RESTORE(%r15); |
| 884 |
addq $(8 * 8), %rsp; |
| 885 |
CFI_ADJUST_CFA_OFFSET(-8 * 8); |
| 886 |
|
| 887 |
EXIT_SYSV_FUNC |
| 888 |
ret_spec_stop; |
| 889 |
CFI_ENDPROC(); |
| 890 |
ELF(.size _gcry_twofish_amd64_cfb_dec,.-_gcry_twofish_amd64_cfb_dec;) |
| 891 |
|
| 892 |
.align 16 |
| 893 |
.globl _gcry_twofish_amd64_ocb_enc |
| 894 |
ELF(.type _gcry_twofish_amd64_ocb_enc,@function;) |
| 895 |
_gcry_twofish_amd64_ocb_enc: |
| 896 |
/* input: |
| 897 |
* %rdi: ctx, CTX |
| 898 |
* %rsi: dst (3 blocks) |
| 899 |
* %rdx: src (3 blocks) |
| 900 |
* %rcx: offset |
| 901 |
* %r8 : checksum |
| 902 |
* %r9 : L pointers (void *L[3]) |
| 903 |
*/ |
| 904 |
CFI_STARTPROC(); |
| 905 |
ENTER_SYSV_FUNC_PARAMS_6 |
| 906 |
|
| 907 |
subq $(8 * 8), %rsp; |
| 908 |
CFI_ADJUST_CFA_OFFSET(8 * 8); |
| 909 |
movq %rbp, (0 * 8)(%rsp); |
| 910 |
movq %rbx, (1 * 8)(%rsp); |
| 911 |
movq %r12, (2 * 8)(%rsp); |
| 912 |
movq %r13, (3 * 8)(%rsp); |
| 913 |
movq %r14, (4 * 8)(%rsp); |
| 914 |
movq %r15, (5 * 8)(%rsp); |
| 915 |
CFI_REL_OFFSET(%rbp, 0 * 8); |
| 916 |
CFI_REL_OFFSET(%rbx, 1 * 8); |
| 917 |
CFI_REL_OFFSET(%r12, 2 * 8); |
| 918 |
CFI_REL_OFFSET(%r13, 3 * 8); |
| 919 |
CFI_REL_OFFSET(%r14, 4 * 8); |
| 920 |
CFI_REL_OFFSET(%r15, 5 * 8); |
| 921 |
|
| 922 |
movq %rsi, (6 * 8)(%rsp); |
| 923 |
movq %rdx, RX0; |
| 924 |
movq %rcx, RX1; |
| 925 |
movq %r8, RX2; |
| 926 |
movq %r9, RY0; |
| 927 |
movq %rsi, RY1; |
| 928 |
|
| 929 |
/* Load offset */ |
| 930 |
movq (0 * 8)(RX1), RT0; |
| 931 |
movq (1 * 8)(RX1), RT1; |
| 932 |
|
| 933 |
/* Offset_i = Offset_{i-1} xor L_{ntz(i)} */ |
| 934 |
movq (RY0), RY2; |
| 935 |
xorq (0 * 8)(RY2), RT0; |
| 936 |
xorq (1 * 8)(RY2), RT1; |
| 937 |
movq (0 * 8)(RX0), RAB0; |
| 938 |
movq (1 * 8)(RX0), RCD0; |
| 939 |
/* Store Offset_i */ |
| 940 |
movq RT0, (0 * 8)(RY1); |
| 941 |
movq RT1, (1 * 8)(RY1); |
| 942 |
/* Checksum_i = Checksum_{i-1} xor P_i */ |
| 943 |
xor RAB0, (0 * 8)(RX2); |
| 944 |
xor RCD0, (1 * 8)(RX2); |
| 945 |
/* PX_i = P_i xor Offset_i */ |
| 946 |
xorq RT0, RAB0; |
| 947 |
xorq RT1, RCD0; |
| 948 |
|
| 949 |
/* Offset_i = Offset_{i-1} xor L_{ntz(i)} */ |
| 950 |
movq 8(RY0), RY2; |
| 951 |
xorq (0 * 8)(RY2), RT0; |
| 952 |
xorq (1 * 8)(RY2), RT1; |
| 953 |
movq (2 * 8)(RX0), RAB1; |
| 954 |
movq (3 * 8)(RX0), RCD1; |
| 955 |
/* Store Offset_i */ |
| 956 |
movq RT0, (2 * 8)(RY1); |
| 957 |
movq RT1, (3 * 8)(RY1); |
| 958 |
/* Checksum_i = Checksum_{i-1} xor P_i */ |
| 959 |
xor RAB1, (0 * 8)(RX2); |
| 960 |
xor RCD1, (1 * 8)(RX2); |
| 961 |
/* PX_i = P_i xor Offset_i */ |
| 962 |
xorq RT0, RAB1; |
| 963 |
xorq RT1, RCD1; |
| 964 |
|
| 965 |
/* Offset_i = Offset_{i-1} xor L_{ntz(i)} */ |
| 966 |
movq 16(RY0), RY2; |
| 967 |
xorq (0 * 8)(RY2), RT0; |
| 968 |
xorq (1 * 8)(RY2), RT1; |
| 969 |
movq (4 * 8)(RX0), RAB2; |
| 970 |
movq (5 * 8)(RX0), RCD2; |
| 971 |
/* Store Offset_i */ |
| 972 |
movq RT0, (4 * 8)(RY1); |
| 973 |
movq RT1, (5 * 8)(RY1); |
| 974 |
/* Checksum_i = Checksum_{i-1} xor P_i */ |
| 975 |
xor RAB2, (0 * 8)(RX2); |
| 976 |
xor RCD2, (1 * 8)(RX2); |
| 977 |
/* PX_i = P_i xor Offset_i */ |
| 978 |
xorq RT0, RAB2; |
| 979 |
xorq RT1, RCD2; |
| 980 |
|
| 981 |
/* Store offset */ |
| 982 |
movq RT0, (0 * 8)(RX1); |
| 983 |
movq RT1, (1 * 8)(RX1); |
| 984 |
|
| 985 |
/* CX_i = ENCIPHER(K, PX_i) */ |
| 986 |
call __twofish_enc_blk3; |
| 987 |
|
| 988 |
movq (6 * 8)(%rsp), RX1; /*dst*/ |
| 989 |
|
| 990 |
/* C_i = CX_i xor Offset_i */ |
| 991 |
xorq RCD0, (0 * 8)(RX1); |
| 992 |
xorq RAB0, (1 * 8)(RX1); |
| 993 |
xorq RCD1, (2 * 8)(RX1); |
| 994 |
xorq RAB1, (3 * 8)(RX1); |
| 995 |
xorq RCD2, (4 * 8)(RX1); |
| 996 |
xorq RAB2, (5 * 8)(RX1); |
| 997 |
|
| 998 |
movq (0 * 8)(%rsp), %rbp; |
| 999 |
movq (1 * 8)(%rsp), %rbx; |
| 1000 |
movq (2 * 8)(%rsp), %r12; |
| 1001 |
movq (3 * 8)(%rsp), %r13; |
| 1002 |
movq (4 * 8)(%rsp), %r14; |
| 1003 |
movq (5 * 8)(%rsp), %r15; |
| 1004 |
CFI_RESTORE(%rbp); |
| 1005 |
CFI_RESTORE(%rbx); |
| 1006 |
CFI_RESTORE(%r12); |
| 1007 |
CFI_RESTORE(%r13); |
| 1008 |
CFI_RESTORE(%r14); |
| 1009 |
CFI_RESTORE(%r15); |
| 1010 |
addq $(8 * 8), %rsp; |
| 1011 |
CFI_ADJUST_CFA_OFFSET(-8 * 8); |
| 1012 |
|
| 1013 |
EXIT_SYSV_FUNC |
| 1014 |
ret_spec_stop; |
| 1015 |
CFI_ENDPROC(); |
| 1016 |
ELF(.size _gcry_twofish_amd64_ocb_enc,.-_gcry_twofish_amd64_ocb_enc;) |
| 1017 |
|
| 1018 |
.align 16 |
| 1019 |
.globl _gcry_twofish_amd64_ocb_dec |
| 1020 |
ELF(.type _gcry_twofish_amd64_ocb_dec,@function;) |
| 1021 |
_gcry_twofish_amd64_ocb_dec: |
| 1022 |
/* input: |
| 1023 |
* %rdi: ctx, CTX |
| 1024 |
* %rsi: dst (3 blocks) |
| 1025 |
* %rdx: src (3 blocks) |
| 1026 |
* %rcx: offset |
| 1027 |
* %r8 : checksum |
| 1028 |
* %r9 : L pointers (void *L[3]) |
| 1029 |
*/ |
| 1030 |
CFI_STARTPROC(); |
| 1031 |
ENTER_SYSV_FUNC_PARAMS_6 |
| 1032 |
|
| 1033 |
subq $(8 * 8), %rsp; |
| 1034 |
CFI_ADJUST_CFA_OFFSET(8 * 8); |
| 1035 |
movq %rbp, (0 * 8)(%rsp); |
| 1036 |
movq %rbx, (1 * 8)(%rsp); |
| 1037 |
movq %r12, (2 * 8)(%rsp); |
| 1038 |
movq %r13, (3 * 8)(%rsp); |
| 1039 |
movq %r14, (4 * 8)(%rsp); |
| 1040 |
movq %r15, (5 * 8)(%rsp); |
| 1041 |
CFI_REL_OFFSET(%rbp, 0 * 8); |
| 1042 |
CFI_REL_OFFSET(%rbx, 1 * 8); |
| 1043 |
CFI_REL_OFFSET(%r12, 2 * 8); |
| 1044 |
CFI_REL_OFFSET(%r13, 3 * 8); |
| 1045 |
CFI_REL_OFFSET(%r14, 4 * 8); |
| 1046 |
CFI_REL_OFFSET(%r15, 5 * 8); |
| 1047 |
|
| 1048 |
movq %rsi, (6 * 8)(%rsp); |
| 1049 |
movq %r8, (7 * 8)(%rsp); |
| 1050 |
movq %rdx, RX0; |
| 1051 |
movq %rcx, RX1; |
| 1052 |
movq %r9, RY0; |
| 1053 |
movq %rsi, RY1; |
| 1054 |
|
| 1055 |
/* Load offset */ |
| 1056 |
movq (0 * 8)(RX1), RT0; |
| 1057 |
movq (1 * 8)(RX1), RT1; |
| 1058 |
|
| 1059 |
/* Offset_i = Offset_{i-1} xor L_{ntz(i)} */ |
| 1060 |
movq (RY0), RY2; |
| 1061 |
xorq (0 * 8)(RY2), RT0; |
| 1062 |
xorq (1 * 8)(RY2), RT1; |
| 1063 |
movq (0 * 8)(RX0), RAB0; |
| 1064 |
movq (1 * 8)(RX0), RCD0; |
| 1065 |
/* Store Offset_i */ |
| 1066 |
movq RT0, (0 * 8)(RY1); |
| 1067 |
movq RT1, (1 * 8)(RY1); |
| 1068 |
/* CX_i = C_i xor Offset_i */ |
| 1069 |
xorq RT0, RAB0; |
| 1070 |
xorq RT1, RCD0; |
| 1071 |
|
| 1072 |
/* Offset_i = Offset_{i-1} xor L_{ntz(i)} */ |
| 1073 |
movq 8(RY0), RY2; |
| 1074 |
xorq (0 * 8)(RY2), RT0; |
| 1075 |
xorq (1 * 8)(RY2), RT1; |
| 1076 |
movq (2 * 8)(RX0), RAB1; |
| 1077 |
movq (3 * 8)(RX0), RCD1; |
| 1078 |
/* Store Offset_i */ |
| 1079 |
movq RT0, (2 * 8)(RY1); |
| 1080 |
movq RT1, (3 * 8)(RY1); |
| 1081 |
/* PX_i = P_i xor Offset_i */ |
| 1082 |
xorq RT0, RAB1; |
| 1083 |
xorq RT1, RCD1; |
| 1084 |
|
| 1085 |
/* Offset_i = Offset_{i-1} xor L_{ntz(i)} */ |
| 1086 |
movq 16(RY0), RY2; |
| 1087 |
xorq (0 * 8)(RY2), RT0; |
| 1088 |
xorq (1 * 8)(RY2), RT1; |
| 1089 |
movq (4 * 8)(RX0), RAB2; |
| 1090 |
movq (5 * 8)(RX0), RCD2; |
| 1091 |
/* Store Offset_i */ |
| 1092 |
movq RT0, (4 * 8)(RY1); |
| 1093 |
movq RT1, (5 * 8)(RY1); |
| 1094 |
/* PX_i = P_i xor Offset_i */ |
| 1095 |
xorq RT0, RAB2; |
| 1096 |
xorq RT1, RCD2; |
| 1097 |
|
| 1098 |
/* Store offset */ |
| 1099 |
movq RT0, (0 * 8)(RX1); |
| 1100 |
movq RT1, (1 * 8)(RX1); |
| 1101 |
|
| 1102 |
/* PX_i = DECIPHER(K, CX_i) */ |
| 1103 |
call __twofish_dec_blk3; |
| 1104 |
|
| 1105 |
movq (7 * 8)(%rsp), RX2; /*checksum*/ |
| 1106 |
movq (6 * 8)(%rsp), RX1; /*dst*/ |
| 1107 |
|
| 1108 |
/* Load checksum */ |
| 1109 |
movq (0 * 8)(RX2), RT0; |
| 1110 |
movq (1 * 8)(RX2), RT1; |
| 1111 |
|
| 1112 |
/* P_i = PX_i xor Offset_i */ |
| 1113 |
xorq RCD0, (0 * 8)(RX1); |
| 1114 |
xorq RAB0, (1 * 8)(RX1); |
| 1115 |
xorq RCD1, (2 * 8)(RX1); |
| 1116 |
xorq RAB1, (3 * 8)(RX1); |
| 1117 |
xorq RCD2, (4 * 8)(RX1); |
| 1118 |
xorq RAB2, (5 * 8)(RX1); |
| 1119 |
|
| 1120 |
/* Checksum_i = Checksum_{i-1} xor P_i */ |
| 1121 |
xorq (0 * 8)(RX1), RT0; |
| 1122 |
xorq (1 * 8)(RX1), RT1; |
| 1123 |
xorq (2 * 8)(RX1), RT0; |
| 1124 |
xorq (3 * 8)(RX1), RT1; |
| 1125 |
xorq (4 * 8)(RX1), RT0; |
| 1126 |
xorq (5 * 8)(RX1), RT1; |
| 1127 |
|
| 1128 |
/* Store checksum */ |
| 1129 |
movq RT0, (0 * 8)(RX2); |
| 1130 |
movq RT1, (1 * 8)(RX2); |
| 1131 |
|
| 1132 |
movq (0 * 8)(%rsp), %rbp; |
| 1133 |
movq (1 * 8)(%rsp), %rbx; |
| 1134 |
movq (2 * 8)(%rsp), %r12; |
| 1135 |
movq (3 * 8)(%rsp), %r13; |
| 1136 |
movq (4 * 8)(%rsp), %r14; |
| 1137 |
movq (5 * 8)(%rsp), %r15; |
| 1138 |
CFI_RESTORE(%rbp); |
| 1139 |
CFI_RESTORE(%rbx); |
| 1140 |
CFI_RESTORE(%r12); |
| 1141 |
CFI_RESTORE(%r13); |
| 1142 |
CFI_RESTORE(%r14); |
| 1143 |
CFI_RESTORE(%r15); |
| 1144 |
addq $(8 * 8), %rsp; |
| 1145 |
CFI_ADJUST_CFA_OFFSET(-8 * 8); |
| 1146 |
|
| 1147 |
EXIT_SYSV_FUNC |
| 1148 |
ret_spec_stop; |
| 1149 |
CFI_ENDPROC(); |
| 1150 |
ELF(.size _gcry_twofish_amd64_ocb_dec,.-_gcry_twofish_amd64_ocb_dec;) |
| 1151 |
|
| 1152 |
.align 16 |
| 1153 |
.globl _gcry_twofish_amd64_ocb_auth |
| 1154 |
ELF(.type _gcry_twofish_amd64_ocb_auth,@function;) |
| 1155 |
_gcry_twofish_amd64_ocb_auth: |
| 1156 |
/* input: |
| 1157 |
* %rdi: ctx, CTX |
| 1158 |
* %rsi: abuf (3 blocks) |
| 1159 |
* %rdx: offset |
| 1160 |
* %rcx: checksum |
| 1161 |
* %r8 : L pointers (void *L[3]) |
| 1162 |
*/ |
| 1163 |
CFI_STARTPROC(); |
| 1164 |
ENTER_SYSV_FUNC_PARAMS_5 |
| 1165 |
|
| 1166 |
subq $(8 * 8), %rsp; |
| 1167 |
CFI_ADJUST_CFA_OFFSET(8 * 8); |
| 1168 |
movq %rbp, (0 * 8)(%rsp); |
| 1169 |
movq %rbx, (1 * 8)(%rsp); |
| 1170 |
movq %r12, (2 * 8)(%rsp); |
| 1171 |
movq %r13, (3 * 8)(%rsp); |
| 1172 |
movq %r14, (4 * 8)(%rsp); |
| 1173 |
movq %r15, (5 * 8)(%rsp); |
| 1174 |
CFI_REL_OFFSET(%rbp, 0 * 8); |
| 1175 |
CFI_REL_OFFSET(%rbx, 1 * 8); |
| 1176 |
CFI_REL_OFFSET(%r12, 2 * 8); |
| 1177 |
CFI_REL_OFFSET(%r13, 3 * 8); |
| 1178 |
CFI_REL_OFFSET(%r14, 4 * 8); |
| 1179 |
CFI_REL_OFFSET(%r15, 5 * 8); |
| 1180 |
|
| 1181 |
movq %rcx, (6 * 8)(%rsp); |
| 1182 |
movq %rsi, RX0; |
| 1183 |
movq %rdx, RX1; |
| 1184 |
movq %r8, RY0; |
| 1185 |
|
| 1186 |
/* Load offset */ |
| 1187 |
movq (0 * 8)(RX1), RT0; |
| 1188 |
movq (1 * 8)(RX1), RT1; |
| 1189 |
|
| 1190 |
/* Offset_i = Offset_{i-1} xor L_{ntz(i)} */ |
| 1191 |
movq (RY0), RY2; |
| 1192 |
xorq (0 * 8)(RY2), RT0; |
| 1193 |
xorq (1 * 8)(RY2), RT1; |
| 1194 |
movq (0 * 8)(RX0), RAB0; |
| 1195 |
movq (1 * 8)(RX0), RCD0; |
| 1196 |
/* PX_i = P_i xor Offset_i */ |
| 1197 |
xorq RT0, RAB0; |
| 1198 |
xorq RT1, RCD0; |
| 1199 |
|
| 1200 |
/* Offset_i = Offset_{i-1} xor L_{ntz(i)} */ |
| 1201 |
movq 8(RY0), RY2; |
| 1202 |
xorq (0 * 8)(RY2), RT0; |
| 1203 |
xorq (1 * 8)(RY2), RT1; |
| 1204 |
movq (2 * 8)(RX0), RAB1; |
| 1205 |
movq (3 * 8)(RX0), RCD1; |
| 1206 |
/* PX_i = P_i xor Offset_i */ |
| 1207 |
xorq RT0, RAB1; |
| 1208 |
xorq RT1, RCD1; |
| 1209 |
|
| 1210 |
/* Offset_i = Offset_{i-1} xor L_{ntz(i)} */ |
| 1211 |
movq 16(RY0), RY2; |
| 1212 |
xorq (0 * 8)(RY2), RT0; |
| 1213 |
xorq (1 * 8)(RY2), RT1; |
| 1214 |
movq (4 * 8)(RX0), RAB2; |
| 1215 |
movq (5 * 8)(RX0), RCD2; |
| 1216 |
/* PX_i = P_i xor Offset_i */ |
| 1217 |
xorq RT0, RAB2; |
| 1218 |
xorq RT1, RCD2; |
| 1219 |
|
| 1220 |
/* Store offset */ |
| 1221 |
movq RT0, (0 * 8)(RX1); |
| 1222 |
movq RT1, (1 * 8)(RX1); |
| 1223 |
|
| 1224 |
/* C_i = ENCIPHER(K, PX_i) */ |
| 1225 |
call __twofish_enc_blk3; |
| 1226 |
|
| 1227 |
movq (6 * 8)(%rsp), RX1; /*checksum*/ |
| 1228 |
|
| 1229 |
/* Checksum_i = C_i xor Checksum_i */ |
| 1230 |
xorq RCD0, RCD1; |
| 1231 |
xorq RAB0, RAB1; |
| 1232 |
xorq RCD1, RCD2; |
| 1233 |
xorq RAB1, RAB2; |
| 1234 |
xorq RCD2, (0 * 8)(RX1); |
| 1235 |
xorq RAB2, (1 * 8)(RX1); |
| 1236 |
|
| 1237 |
movq (0 * 8)(%rsp), %rbp; |
| 1238 |
movq (1 * 8)(%rsp), %rbx; |
| 1239 |
movq (2 * 8)(%rsp), %r12; |
| 1240 |
movq (3 * 8)(%rsp), %r13; |
| 1241 |
movq (4 * 8)(%rsp), %r14; |
| 1242 |
movq (5 * 8)(%rsp), %r15; |
| 1243 |
CFI_RESTORE(%rbp); |
| 1244 |
CFI_RESTORE(%rbx); |
| 1245 |
CFI_RESTORE(%r12); |
| 1246 |
CFI_RESTORE(%r13); |
| 1247 |
CFI_RESTORE(%r14); |
| 1248 |
CFI_RESTORE(%r15); |
| 1249 |
addq $(8 * 8), %rsp; |
| 1250 |
CFI_ADJUST_CFA_OFFSET(-8 * 8); |
| 1251 |
|
| 1252 |
EXIT_SYSV_FUNC |
| 1253 |
ret_spec_stop; |
| 1254 |
CFI_ENDPROC(); |
| 1255 |
ELF(.size _gcry_twofish_amd64_ocb_auth,.-_gcry_twofish_amd64_ocb_auth;) |
| 1256 |
|
| 1257 |
#endif /*USE_TWOFISH*/ |
| 1258 |
#endif /*__x86_64*/ |