2019-05-27 14:55:05 +08:00
|
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
2012-07-12 01:38:57 +08:00
|
|
|
|
/*
|
|
|
|
|
* Cast6 Cipher 8-way parallel algorithm (AVX/x86_64)
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2012 Johannes Goetzfried
|
|
|
|
|
* <Johannes.Goetzfried@informatik.stud.uni-erlangen.de>
|
|
|
|
|
*
|
2013-04-09 02:51:05 +08:00
|
|
|
|
* Copyright © 2012-2013 Jussi Kivilinna <jussi.kivilinna@iki.fi>
|
2012-07-12 01:38:57 +08:00
|
|
|
|
*/
|
|
|
|
|
|
2013-01-19 19:39:16 +08:00
|
|
|
|
#include <linux/linkage.h>
|
2016-01-22 06:49:19 +08:00
|
|
|
|
#include <asm/frame.h>
|
2012-10-20 20:06:41 +08:00
|
|
|
|
#include "glue_helper-asm-avx.S"
|
|
|
|
|
|
2012-07-12 01:38:57 +08:00
|
|
|
|
.file "cast6-avx-x86_64-asm_64.S"
|
|
|
|
|
|
2012-11-13 17:43:14 +08:00
|
|
|
|
.extern cast_s1
|
|
|
|
|
.extern cast_s2
|
|
|
|
|
.extern cast_s3
|
|
|
|
|
.extern cast_s4
|
2012-07-12 01:38:57 +08:00
|
|
|
|
|
|
|
|
|
/* structure of crypto context */
|
|
|
|
|
#define km 0
|
|
|
|
|
#define kr (12*4*4)
|
|
|
|
|
|
|
|
|
|
/* s-boxes */
|
2012-11-13 17:43:14 +08:00
|
|
|
|
#define s1 cast_s1
|
|
|
|
|
#define s2 cast_s2
|
|
|
|
|
#define s3 cast_s3
|
|
|
|
|
#define s4 cast_s4
|
2012-07-12 01:38:57 +08:00
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
|
8-way AVX cast6
|
|
|
|
|
**********************************************************************/
|
2017-09-19 03:42:03 +08:00
|
|
|
|
#define CTX %r15
|
2012-07-12 01:38:57 +08:00
|
|
|
|
|
|
|
|
|
#define RA1 %xmm0
|
|
|
|
|
#define RB1 %xmm1
|
|
|
|
|
#define RC1 %xmm2
|
|
|
|
|
#define RD1 %xmm3
|
|
|
|
|
|
|
|
|
|
#define RA2 %xmm4
|
|
|
|
|
#define RB2 %xmm5
|
|
|
|
|
#define RC2 %xmm6
|
|
|
|
|
#define RD2 %xmm7
|
|
|
|
|
|
2012-08-28 19:24:54 +08:00
|
|
|
|
#define RX %xmm8
|
2012-07-12 01:38:57 +08:00
|
|
|
|
|
|
|
|
|
#define RKM %xmm9
|
2012-08-28 19:24:54 +08:00
|
|
|
|
#define RKR %xmm10
|
|
|
|
|
#define RKRF %xmm11
|
|
|
|
|
#define RKRR %xmm12
|
|
|
|
|
#define R32 %xmm13
|
|
|
|
|
#define R1ST %xmm14
|
2012-07-12 01:38:57 +08:00
|
|
|
|
|
2012-08-28 19:24:54 +08:00
|
|
|
|
#define RTMP %xmm15
|
2012-07-12 01:38:57 +08:00
|
|
|
|
|
2017-09-19 03:42:03 +08:00
|
|
|
|
#define RID1 %rdi
|
|
|
|
|
#define RID1d %edi
|
2012-08-28 19:24:54 +08:00
|
|
|
|
#define RID2 %rsi
|
|
|
|
|
#define RID2d %esi
|
2012-07-12 01:38:57 +08:00
|
|
|
|
|
|
|
|
|
#define RGI1 %rdx
|
|
|
|
|
#define RGI1bl %dl
|
|
|
|
|
#define RGI1bh %dh
|
|
|
|
|
#define RGI2 %rcx
|
|
|
|
|
#define RGI2bl %cl
|
|
|
|
|
#define RGI2bh %ch
|
|
|
|
|
|
2012-08-28 19:24:54 +08:00
|
|
|
|
#define RGI3 %rax
|
|
|
|
|
#define RGI3bl %al
|
|
|
|
|
#define RGI3bh %ah
|
|
|
|
|
#define RGI4 %rbx
|
|
|
|
|
#define RGI4bl %bl
|
|
|
|
|
#define RGI4bh %bh
|
|
|
|
|
|
2012-07-12 01:38:57 +08:00
|
|
|
|
#define RFS1 %r8
|
|
|
|
|
#define RFS1d %r8d
|
|
|
|
|
#define RFS2 %r9
|
|
|
|
|
#define RFS2d %r9d
|
|
|
|
|
#define RFS3 %r10
|
|
|
|
|
#define RFS3d %r10d
|
|
|
|
|
|
|
|
|
|
|
2012-08-28 19:24:54 +08:00
|
|
|
|
#define lookup_32bit(src, dst, op1, op2, op3, interleave_op, il_reg) \
|
|
|
|
|
movzbl src ## bh, RID1d; \
|
|
|
|
|
movzbl src ## bl, RID2d; \
|
|
|
|
|
shrq $16, src; \
|
2012-07-12 01:38:57 +08:00
|
|
|
|
movl s1(, RID1, 4), dst ## d; \
|
|
|
|
|
op1 s2(, RID2, 4), dst ## d; \
|
2012-08-28 19:24:54 +08:00
|
|
|
|
movzbl src ## bh, RID1d; \
|
|
|
|
|
movzbl src ## bl, RID2d; \
|
|
|
|
|
interleave_op(il_reg); \
|
2012-07-12 01:38:57 +08:00
|
|
|
|
op2 s3(, RID1, 4), dst ## d; \
|
|
|
|
|
op3 s4(, RID2, 4), dst ## d;
|
|
|
|
|
|
2012-08-28 19:24:54 +08:00
|
|
|
|
#define dummy(d) /* do nothing */
|
|
|
|
|
|
|
|
|
|
#define shr_next(reg) \
|
|
|
|
|
shrq $16, reg;
|
|
|
|
|
|
|
|
|
|
#define F_head(a, x, gi1, gi2, op0) \
|
2012-07-12 01:38:57 +08:00
|
|
|
|
op0 a, RKM, x; \
|
2012-08-28 19:24:54 +08:00
|
|
|
|
vpslld RKRF, x, RTMP; \
|
|
|
|
|
vpsrld RKRR, x, x; \
|
2012-07-12 01:38:57 +08:00
|
|
|
|
vpor RTMP, x, x; \
|
|
|
|
|
\
|
2012-08-28 19:24:54 +08:00
|
|
|
|
vmovq x, gi1; \
|
|
|
|
|
vpextrq $1, x, gi2;
|
|
|
|
|
|
|
|
|
|
#define F_tail(a, x, gi1, gi2, op1, op2, op3) \
|
|
|
|
|
lookup_32bit(##gi1, RFS1, op1, op2, op3, shr_next, ##gi1); \
|
|
|
|
|
lookup_32bit(##gi2, RFS3, op1, op2, op3, shr_next, ##gi2); \
|
2012-07-12 01:38:57 +08:00
|
|
|
|
\
|
2012-08-28 19:24:54 +08:00
|
|
|
|
lookup_32bit(##gi1, RFS2, op1, op2, op3, dummy, none); \
|
|
|
|
|
shlq $32, RFS2; \
|
|
|
|
|
orq RFS1, RFS2; \
|
|
|
|
|
lookup_32bit(##gi2, RFS1, op1, op2, op3, dummy, none); \
|
|
|
|
|
shlq $32, RFS1; \
|
|
|
|
|
orq RFS1, RFS3; \
|
2012-07-12 01:38:57 +08:00
|
|
|
|
\
|
2012-08-28 19:24:54 +08:00
|
|
|
|
vmovq RFS2, x; \
|
2012-07-12 01:38:57 +08:00
|
|
|
|
vpinsrq $1, RFS3, x, x;
|
|
|
|
|
|
2012-08-28 19:24:54 +08:00
|
|
|
|
#define F_2(a1, b1, a2, b2, op0, op1, op2, op3) \
|
|
|
|
|
F_head(b1, RX, RGI1, RGI2, op0); \
|
|
|
|
|
F_head(b2, RX, RGI3, RGI4, op0); \
|
|
|
|
|
\
|
|
|
|
|
F_tail(b1, RX, RGI1, RGI2, op1, op2, op3); \
|
|
|
|
|
F_tail(b2, RTMP, RGI3, RGI4, op1, op2, op3); \
|
|
|
|
|
\
|
|
|
|
|
vpxor a1, RX, a1; \
|
|
|
|
|
vpxor a2, RTMP, a2;
|
|
|
|
|
|
|
|
|
|
#define F1_2(a1, b1, a2, b2) \
|
|
|
|
|
F_2(a1, b1, a2, b2, vpaddd, xorl, subl, addl)
|
|
|
|
|
#define F2_2(a1, b1, a2, b2) \
|
|
|
|
|
F_2(a1, b1, a2, b2, vpxor, subl, addl, xorl)
|
|
|
|
|
#define F3_2(a1, b1, a2, b2) \
|
|
|
|
|
F_2(a1, b1, a2, b2, vpsubd, addl, xorl, subl)
|
2012-07-12 01:38:57 +08:00
|
|
|
|
|
2012-08-28 19:24:54 +08:00
|
|
|
|
#define qop(in, out, f) \
|
|
|
|
|
F ## f ## _2(out ## 1, in ## 1, out ## 2, in ## 2);
|
|
|
|
|
|
|
|
|
|
#define get_round_keys(nn) \
|
|
|
|
|
vbroadcastss (km+(4*(nn)))(CTX), RKM; \
|
|
|
|
|
vpand R1ST, RKR, RKRF; \
|
|
|
|
|
vpsubq RKRF, R32, RKRR; \
|
|
|
|
|
vpsrldq $1, RKR, RKR;
|
2012-07-12 01:38:57 +08:00
|
|
|
|
|
|
|
|
|
#define Q(n) \
|
2012-08-28 19:24:54 +08:00
|
|
|
|
get_round_keys(4*n+0); \
|
|
|
|
|
qop(RD, RC, 1); \
|
2012-07-12 01:38:57 +08:00
|
|
|
|
\
|
2012-08-28 19:24:54 +08:00
|
|
|
|
get_round_keys(4*n+1); \
|
|
|
|
|
qop(RC, RB, 2); \
|
2012-07-12 01:38:57 +08:00
|
|
|
|
\
|
2012-08-28 19:24:54 +08:00
|
|
|
|
get_round_keys(4*n+2); \
|
|
|
|
|
qop(RB, RA, 3); \
|
2012-07-12 01:38:57 +08:00
|
|
|
|
\
|
2012-08-28 19:24:54 +08:00
|
|
|
|
get_round_keys(4*n+3); \
|
|
|
|
|
qop(RA, RD, 1);
|
2012-07-12 01:38:57 +08:00
|
|
|
|
|
|
|
|
|
#define QBAR(n) \
|
2012-08-28 19:24:54 +08:00
|
|
|
|
get_round_keys(4*n+3); \
|
|
|
|
|
qop(RA, RD, 1); \
|
2012-07-12 01:38:57 +08:00
|
|
|
|
\
|
2012-08-28 19:24:54 +08:00
|
|
|
|
get_round_keys(4*n+2); \
|
|
|
|
|
qop(RB, RA, 3); \
|
2012-07-12 01:38:57 +08:00
|
|
|
|
\
|
2012-08-28 19:24:54 +08:00
|
|
|
|
get_round_keys(4*n+1); \
|
|
|
|
|
qop(RC, RB, 2); \
|
2012-07-12 01:38:57 +08:00
|
|
|
|
\
|
2012-08-28 19:24:54 +08:00
|
|
|
|
get_round_keys(4*n+0); \
|
|
|
|
|
qop(RD, RC, 1);
|
|
|
|
|
|
|
|
|
|
#define shuffle(mask) \
|
|
|
|
|
vpshufb mask, RKR, RKR;
|
2012-07-12 01:38:57 +08:00
|
|
|
|
|
2012-08-28 19:24:54 +08:00
|
|
|
|
#define preload_rkr(n, do_mask, mask) \
|
|
|
|
|
vbroadcastss .L16_mask, RKR; \
|
|
|
|
|
/* add 16-bit rotation to key rotations (mod 32) */ \
|
|
|
|
|
vpxor (kr+n*16)(CTX), RKR, RKR; \
|
|
|
|
|
do_mask(mask);
|
2012-07-12 01:38:57 +08:00
|
|
|
|
|
|
|
|
|
#define transpose_4x4(x0, x1, x2, x3, t0, t1, t2) \
|
|
|
|
|
vpunpckldq x1, x0, t0; \
|
|
|
|
|
vpunpckhdq x1, x0, t2; \
|
|
|
|
|
vpunpckldq x3, x2, t1; \
|
|
|
|
|
vpunpckhdq x3, x2, x3; \
|
|
|
|
|
\
|
|
|
|
|
vpunpcklqdq t1, t0, x0; \
|
|
|
|
|
vpunpckhqdq t1, t0, x1; \
|
|
|
|
|
vpunpcklqdq x3, t2, x2; \
|
|
|
|
|
vpunpckhqdq x3, t2, x3;
|
|
|
|
|
|
2012-10-20 20:06:41 +08:00
|
|
|
|
#define inpack_blocks(x0, x1, x2, x3, t0, t1, t2, rmask) \
|
2012-08-28 19:24:54 +08:00
|
|
|
|
vpshufb rmask, x0, x0; \
|
|
|
|
|
vpshufb rmask, x1, x1; \
|
|
|
|
|
vpshufb rmask, x2, x2; \
|
|
|
|
|
vpshufb rmask, x3, x3; \
|
2012-07-12 01:38:57 +08:00
|
|
|
|
\
|
|
|
|
|
transpose_4x4(x0, x1, x2, x3, t0, t1, t2)
|
|
|
|
|
|
2012-10-20 20:06:41 +08:00
|
|
|
|
#define outunpack_blocks(x0, x1, x2, x3, t0, t1, t2, rmask) \
|
2012-07-12 01:38:57 +08:00
|
|
|
|
transpose_4x4(x0, x1, x2, x3, t0, t1, t2) \
|
|
|
|
|
\
|
2012-08-28 19:24:54 +08:00
|
|
|
|
vpshufb rmask, x0, x0; \
|
|
|
|
|
vpshufb rmask, x1, x1; \
|
|
|
|
|
vpshufb rmask, x2, x2; \
|
2012-10-20 20:06:41 +08:00
|
|
|
|
vpshufb rmask, x3, x3;
|
2012-07-12 01:38:57 +08:00
|
|
|
|
|
crypto: x86 - make constants readonly, allow linker to merge them
A lot of asm-optimized routines in arch/x86/crypto/ keep its
constants in .data. This is wrong, they should be on .rodata.
Mnay of these constants are the same in different modules.
For example, 128-bit shuffle mask 0x000102030405060708090A0B0C0D0E0F
exists in at least half a dozen places.
There is a way to let linker merge them and use just one copy.
The rules are as follows: mergeable objects of different sizes
should not share sections. You can't put them all in one .rodata
section, they will lose "mergeability".
GCC puts its mergeable constants in ".rodata.cstSIZE" sections,
or ".rodata.cstSIZE.<object_name>" if -fdata-sections is used.
This patch does the same:
.section .rodata.cst16.SHUF_MASK, "aM", @progbits, 16
It is important that all data in such section consists of
16-byte elements, not larger ones, and there are no implicit
use of one element from another.
When this is not the case, use non-mergeable section:
.section .rodata[.VAR_NAME], "a", @progbits
This reduces .data by ~15 kbytes:
text data bss dec hex filename
11097415 2705840 2630712 16433967 fac32f vmlinux-prev.o
11112095 2690672 2630712 16433479 fac147 vmlinux.o
Merged objects are visible in System.map:
ffffffff81a28810 r POLY
ffffffff81a28810 r POLY
ffffffff81a28820 r TWOONE
ffffffff81a28820 r TWOONE
ffffffff81a28830 r PSHUFFLE_BYTE_FLIP_MASK <- merged regardless of
ffffffff81a28830 r SHUF_MASK <------------- the name difference
ffffffff81a28830 r SHUF_MASK
ffffffff81a28830 r SHUF_MASK
..
ffffffff81a28d00 r K512 <- merged three identical 640-byte tables
ffffffff81a28d00 r K512
ffffffff81a28d00 r K512
Use of object names in section name suffixes is not strictly necessary,
but might help if someday link stage will use garbage collection
to eliminate unused sections (ld --gc-sections).
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
CC: Herbert Xu <herbert@gondor.apana.org.au>
CC: Josh Poimboeuf <jpoimboe@redhat.com>
CC: Xiaodong Liu <xiaodong.liu@intel.com>
CC: Megha Dey <megha.dey@intel.com>
CC: linux-crypto@vger.kernel.org
CC: x86@kernel.org
CC: linux-kernel@vger.kernel.org
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2017-01-20 05:33:04 +08:00
|
|
|
|
.section .rodata.cst16, "aM", @progbits, 16
|
2012-07-12 01:38:57 +08:00
|
|
|
|
.align 16
|
2013-04-09 02:51:05 +08:00
|
|
|
|
.Lxts_gf128mul_and_shl1_mask:
|
|
|
|
|
.byte 0x87, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0
|
2012-07-12 01:38:57 +08:00
|
|
|
|
.Lbswap_mask:
|
|
|
|
|
.byte 3, 2, 1, 0, 7, 6, 5, 4, 11, 10, 9, 8, 15, 14, 13, 12
|
2012-10-20 20:06:41 +08:00
|
|
|
|
.Lbswap128_mask:
|
|
|
|
|
.byte 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
|
2012-08-28 19:24:54 +08:00
|
|
|
|
.Lrkr_enc_Q_Q_QBAR_QBAR:
|
|
|
|
|
.byte 0, 1, 2, 3, 4, 5, 6, 7, 11, 10, 9, 8, 15, 14, 13, 12
|
|
|
|
|
.Lrkr_enc_QBAR_QBAR_QBAR_QBAR:
|
|
|
|
|
.byte 3, 2, 1, 0, 7, 6, 5, 4, 11, 10, 9, 8, 15, 14, 13, 12
|
|
|
|
|
.Lrkr_dec_Q_Q_Q_Q:
|
|
|
|
|
.byte 12, 13, 14, 15, 8, 9, 10, 11, 4, 5, 6, 7, 0, 1, 2, 3
|
|
|
|
|
.Lrkr_dec_Q_Q_QBAR_QBAR:
|
|
|
|
|
.byte 12, 13, 14, 15, 8, 9, 10, 11, 7, 6, 5, 4, 3, 2, 1, 0
|
|
|
|
|
.Lrkr_dec_QBAR_QBAR_QBAR_QBAR:
|
|
|
|
|
.byte 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
|
crypto: x86 - make constants readonly, allow linker to merge them
A lot of asm-optimized routines in arch/x86/crypto/ keep its
constants in .data. This is wrong, they should be on .rodata.
Mnay of these constants are the same in different modules.
For example, 128-bit shuffle mask 0x000102030405060708090A0B0C0D0E0F
exists in at least half a dozen places.
There is a way to let linker merge them and use just one copy.
The rules are as follows: mergeable objects of different sizes
should not share sections. You can't put them all in one .rodata
section, they will lose "mergeability".
GCC puts its mergeable constants in ".rodata.cstSIZE" sections,
or ".rodata.cstSIZE.<object_name>" if -fdata-sections is used.
This patch does the same:
.section .rodata.cst16.SHUF_MASK, "aM", @progbits, 16
It is important that all data in such section consists of
16-byte elements, not larger ones, and there are no implicit
use of one element from another.
When this is not the case, use non-mergeable section:
.section .rodata[.VAR_NAME], "a", @progbits
This reduces .data by ~15 kbytes:
text data bss dec hex filename
11097415 2705840 2630712 16433967 fac32f vmlinux-prev.o
11112095 2690672 2630712 16433479 fac147 vmlinux.o
Merged objects are visible in System.map:
ffffffff81a28810 r POLY
ffffffff81a28810 r POLY
ffffffff81a28820 r TWOONE
ffffffff81a28820 r TWOONE
ffffffff81a28830 r PSHUFFLE_BYTE_FLIP_MASK <- merged regardless of
ffffffff81a28830 r SHUF_MASK <------------- the name difference
ffffffff81a28830 r SHUF_MASK
ffffffff81a28830 r SHUF_MASK
..
ffffffff81a28d00 r K512 <- merged three identical 640-byte tables
ffffffff81a28d00 r K512
ffffffff81a28d00 r K512
Use of object names in section name suffixes is not strictly necessary,
but might help if someday link stage will use garbage collection
to eliminate unused sections (ld --gc-sections).
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
CC: Herbert Xu <herbert@gondor.apana.org.au>
CC: Josh Poimboeuf <jpoimboe@redhat.com>
CC: Xiaodong Liu <xiaodong.liu@intel.com>
CC: Megha Dey <megha.dey@intel.com>
CC: linux-crypto@vger.kernel.org
CC: x86@kernel.org
CC: linux-kernel@vger.kernel.org
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2017-01-20 05:33:04 +08:00
|
|
|
|
|
|
|
|
|
.section .rodata.cst4.L16_mask, "aM", @progbits, 4
|
|
|
|
|
.align 4
|
2012-08-28 19:24:54 +08:00
|
|
|
|
.L16_mask:
|
|
|
|
|
.byte 16, 16, 16, 16
|
crypto: x86 - make constants readonly, allow linker to merge them
A lot of asm-optimized routines in arch/x86/crypto/ keep its
constants in .data. This is wrong, they should be on .rodata.
Mnay of these constants are the same in different modules.
For example, 128-bit shuffle mask 0x000102030405060708090A0B0C0D0E0F
exists in at least half a dozen places.
There is a way to let linker merge them and use just one copy.
The rules are as follows: mergeable objects of different sizes
should not share sections. You can't put them all in one .rodata
section, they will lose "mergeability".
GCC puts its mergeable constants in ".rodata.cstSIZE" sections,
or ".rodata.cstSIZE.<object_name>" if -fdata-sections is used.
This patch does the same:
.section .rodata.cst16.SHUF_MASK, "aM", @progbits, 16
It is important that all data in such section consists of
16-byte elements, not larger ones, and there are no implicit
use of one element from another.
When this is not the case, use non-mergeable section:
.section .rodata[.VAR_NAME], "a", @progbits
This reduces .data by ~15 kbytes:
text data bss dec hex filename
11097415 2705840 2630712 16433967 fac32f vmlinux-prev.o
11112095 2690672 2630712 16433479 fac147 vmlinux.o
Merged objects are visible in System.map:
ffffffff81a28810 r POLY
ffffffff81a28810 r POLY
ffffffff81a28820 r TWOONE
ffffffff81a28820 r TWOONE
ffffffff81a28830 r PSHUFFLE_BYTE_FLIP_MASK <- merged regardless of
ffffffff81a28830 r SHUF_MASK <------------- the name difference
ffffffff81a28830 r SHUF_MASK
ffffffff81a28830 r SHUF_MASK
..
ffffffff81a28d00 r K512 <- merged three identical 640-byte tables
ffffffff81a28d00 r K512
ffffffff81a28d00 r K512
Use of object names in section name suffixes is not strictly necessary,
but might help if someday link stage will use garbage collection
to eliminate unused sections (ld --gc-sections).
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
CC: Herbert Xu <herbert@gondor.apana.org.au>
CC: Josh Poimboeuf <jpoimboe@redhat.com>
CC: Xiaodong Liu <xiaodong.liu@intel.com>
CC: Megha Dey <megha.dey@intel.com>
CC: linux-crypto@vger.kernel.org
CC: x86@kernel.org
CC: linux-kernel@vger.kernel.org
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2017-01-20 05:33:04 +08:00
|
|
|
|
|
|
|
|
|
.section .rodata.cst4.L32_mask, "aM", @progbits, 4
|
|
|
|
|
.align 4
|
2012-07-12 01:38:57 +08:00
|
|
|
|
.L32_mask:
|
2012-08-28 19:24:54 +08:00
|
|
|
|
.byte 32, 0, 0, 0
|
crypto: x86 - make constants readonly, allow linker to merge them
A lot of asm-optimized routines in arch/x86/crypto/ keep its
constants in .data. This is wrong, they should be on .rodata.
Mnay of these constants are the same in different modules.
For example, 128-bit shuffle mask 0x000102030405060708090A0B0C0D0E0F
exists in at least half a dozen places.
There is a way to let linker merge them and use just one copy.
The rules are as follows: mergeable objects of different sizes
should not share sections. You can't put them all in one .rodata
section, they will lose "mergeability".
GCC puts its mergeable constants in ".rodata.cstSIZE" sections,
or ".rodata.cstSIZE.<object_name>" if -fdata-sections is used.
This patch does the same:
.section .rodata.cst16.SHUF_MASK, "aM", @progbits, 16
It is important that all data in such section consists of
16-byte elements, not larger ones, and there are no implicit
use of one element from another.
When this is not the case, use non-mergeable section:
.section .rodata[.VAR_NAME], "a", @progbits
This reduces .data by ~15 kbytes:
text data bss dec hex filename
11097415 2705840 2630712 16433967 fac32f vmlinux-prev.o
11112095 2690672 2630712 16433479 fac147 vmlinux.o
Merged objects are visible in System.map:
ffffffff81a28810 r POLY
ffffffff81a28810 r POLY
ffffffff81a28820 r TWOONE
ffffffff81a28820 r TWOONE
ffffffff81a28830 r PSHUFFLE_BYTE_FLIP_MASK <- merged regardless of
ffffffff81a28830 r SHUF_MASK <------------- the name difference
ffffffff81a28830 r SHUF_MASK
ffffffff81a28830 r SHUF_MASK
..
ffffffff81a28d00 r K512 <- merged three identical 640-byte tables
ffffffff81a28d00 r K512
ffffffff81a28d00 r K512
Use of object names in section name suffixes is not strictly necessary,
but might help if someday link stage will use garbage collection
to eliminate unused sections (ld --gc-sections).
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
CC: Herbert Xu <herbert@gondor.apana.org.au>
CC: Josh Poimboeuf <jpoimboe@redhat.com>
CC: Xiaodong Liu <xiaodong.liu@intel.com>
CC: Megha Dey <megha.dey@intel.com>
CC: linux-crypto@vger.kernel.org
CC: x86@kernel.org
CC: linux-kernel@vger.kernel.org
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2017-01-20 05:33:04 +08:00
|
|
|
|
|
|
|
|
|
.section .rodata.cst4.first_mask, "aM", @progbits, 4
|
|
|
|
|
.align 4
|
2012-08-28 19:24:54 +08:00
|
|
|
|
.Lfirst_mask:
|
|
|
|
|
.byte 0x1f, 0, 0, 0
|
|
|
|
|
|
|
|
|
|
.text
|
2012-07-12 01:38:57 +08:00
|
|
|
|
|
2012-10-20 20:06:41 +08:00
|
|
|
|
.align 8
|
|
|
|
|
__cast6_enc_blk8:
|
2012-07-12 01:38:57 +08:00
|
|
|
|
/* input:
|
2017-09-19 03:42:03 +08:00
|
|
|
|
* %rdi: ctx
|
2012-10-20 20:06:41 +08:00
|
|
|
|
* RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2: blocks
|
|
|
|
|
* output:
|
|
|
|
|
* RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2: encrypted blocks
|
2012-07-12 01:38:57 +08:00
|
|
|
|
*/
|
|
|
|
|
|
2017-09-19 03:42:03 +08:00
|
|
|
|
pushq %r15;
|
2012-07-12 01:38:57 +08:00
|
|
|
|
pushq %rbx;
|
|
|
|
|
|
2017-09-19 03:42:03 +08:00
|
|
|
|
movq %rdi, CTX;
|
|
|
|
|
|
2012-08-28 19:24:54 +08:00
|
|
|
|
vmovdqa .Lbswap_mask, RKM;
|
|
|
|
|
vmovd .Lfirst_mask, R1ST;
|
|
|
|
|
vmovd .L32_mask, R32;
|
2012-07-12 01:38:57 +08:00
|
|
|
|
|
2012-10-20 20:06:41 +08:00
|
|
|
|
inpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
|
|
|
|
|
inpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
|
2012-07-12 01:38:57 +08:00
|
|
|
|
|
2012-08-28 19:24:54 +08:00
|
|
|
|
preload_rkr(0, dummy, none);
|
2012-07-12 01:38:57 +08:00
|
|
|
|
Q(0);
|
|
|
|
|
Q(1);
|
|
|
|
|
Q(2);
|
|
|
|
|
Q(3);
|
2012-08-28 19:24:54 +08:00
|
|
|
|
preload_rkr(1, shuffle, .Lrkr_enc_Q_Q_QBAR_QBAR);
|
2012-07-12 01:38:57 +08:00
|
|
|
|
Q(4);
|
|
|
|
|
Q(5);
|
|
|
|
|
QBAR(6);
|
|
|
|
|
QBAR(7);
|
2012-08-28 19:24:54 +08:00
|
|
|
|
preload_rkr(2, shuffle, .Lrkr_enc_QBAR_QBAR_QBAR_QBAR);
|
2012-07-12 01:38:57 +08:00
|
|
|
|
QBAR(8);
|
|
|
|
|
QBAR(9);
|
|
|
|
|
QBAR(10);
|
|
|
|
|
QBAR(11);
|
|
|
|
|
|
|
|
|
|
popq %rbx;
|
2017-09-19 03:42:03 +08:00
|
|
|
|
popq %r15;
|
2012-07-12 01:38:57 +08:00
|
|
|
|
|
2012-08-28 19:24:54 +08:00
|
|
|
|
vmovdqa .Lbswap_mask, RKM;
|
2012-07-12 01:38:57 +08:00
|
|
|
|
|
2012-10-20 20:06:41 +08:00
|
|
|
|
outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
|
|
|
|
|
outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
|
2012-07-12 01:38:57 +08:00
|
|
|
|
|
|
|
|
|
ret;
|
2013-01-19 19:39:16 +08:00
|
|
|
|
ENDPROC(__cast6_enc_blk8)
|
2012-07-12 01:38:57 +08:00
|
|
|
|
|
2012-10-20 20:06:41 +08:00
|
|
|
|
.align 8
|
|
|
|
|
__cast6_dec_blk8:
|
2012-07-12 01:38:57 +08:00
|
|
|
|
/* input:
|
2017-09-19 03:42:03 +08:00
|
|
|
|
* %rdi: ctx
|
2012-10-20 20:06:41 +08:00
|
|
|
|
* RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2: encrypted blocks
|
|
|
|
|
* output:
|
|
|
|
|
* RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2: decrypted blocks
|
2012-07-12 01:38:57 +08:00
|
|
|
|
*/
|
|
|
|
|
|
2017-09-19 03:42:03 +08:00
|
|
|
|
pushq %r15;
|
2012-07-12 01:38:57 +08:00
|
|
|
|
pushq %rbx;
|
|
|
|
|
|
2017-09-19 03:42:03 +08:00
|
|
|
|
movq %rdi, CTX;
|
|
|
|
|
|
2012-08-28 19:24:54 +08:00
|
|
|
|
vmovdqa .Lbswap_mask, RKM;
|
|
|
|
|
vmovd .Lfirst_mask, R1ST;
|
|
|
|
|
vmovd .L32_mask, R32;
|
2012-07-12 01:38:57 +08:00
|
|
|
|
|
2012-10-20 20:06:41 +08:00
|
|
|
|
inpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
|
|
|
|
|
inpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
|
2012-07-12 01:38:57 +08:00
|
|
|
|
|
2012-08-28 19:24:54 +08:00
|
|
|
|
preload_rkr(2, shuffle, .Lrkr_dec_Q_Q_Q_Q);
|
2012-07-12 01:38:57 +08:00
|
|
|
|
Q(11);
|
|
|
|
|
Q(10);
|
|
|
|
|
Q(9);
|
|
|
|
|
Q(8);
|
2012-08-28 19:24:54 +08:00
|
|
|
|
preload_rkr(1, shuffle, .Lrkr_dec_Q_Q_QBAR_QBAR);
|
2012-07-12 01:38:57 +08:00
|
|
|
|
Q(7);
|
|
|
|
|
Q(6);
|
|
|
|
|
QBAR(5);
|
|
|
|
|
QBAR(4);
|
2012-08-28 19:24:54 +08:00
|
|
|
|
preload_rkr(0, shuffle, .Lrkr_dec_QBAR_QBAR_QBAR_QBAR);
|
2012-07-12 01:38:57 +08:00
|
|
|
|
QBAR(3);
|
|
|
|
|
QBAR(2);
|
|
|
|
|
QBAR(1);
|
|
|
|
|
QBAR(0);
|
|
|
|
|
|
|
|
|
|
popq %rbx;
|
2017-09-19 03:42:03 +08:00
|
|
|
|
popq %r15;
|
2012-07-12 01:38:57 +08:00
|
|
|
|
|
2012-08-28 19:24:54 +08:00
|
|
|
|
vmovdqa .Lbswap_mask, RKM;
|
2012-10-20 20:06:41 +08:00
|
|
|
|
outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
|
|
|
|
|
outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
|
|
|
|
|
|
|
|
|
|
ret;
|
2013-01-19 19:39:16 +08:00
|
|
|
|
ENDPROC(__cast6_dec_blk8)
|
2012-10-20 20:06:41 +08:00
|
|
|
|
|
2013-01-19 19:39:16 +08:00
|
|
|
|
ENTRY(cast6_ecb_enc_8way)
|
2012-10-20 20:06:41 +08:00
|
|
|
|
/* input:
|
2017-09-19 03:42:03 +08:00
|
|
|
|
* %rdi: ctx
|
2012-10-20 20:06:41 +08:00
|
|
|
|
* %rsi: dst
|
|
|
|
|
* %rdx: src
|
|
|
|
|
*/
|
2016-01-22 06:49:19 +08:00
|
|
|
|
FRAME_BEGIN
|
2017-09-19 03:42:03 +08:00
|
|
|
|
pushq %r15;
|
2012-10-20 20:06:41 +08:00
|
|
|
|
|
2017-09-19 03:42:03 +08:00
|
|
|
|
movq %rdi, CTX;
|
2012-10-20 20:06:41 +08:00
|
|
|
|
movq %rsi, %r11;
|
|
|
|
|
|
|
|
|
|
load_8way(%rdx, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
|
|
|
|
|
|
|
|
|
|
call __cast6_enc_blk8;
|
|
|
|
|
|
|
|
|
|
store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
|
|
|
|
|
|
2017-09-19 03:42:03 +08:00
|
|
|
|
popq %r15;
|
2016-01-22 06:49:19 +08:00
|
|
|
|
FRAME_END
|
2012-10-20 20:06:41 +08:00
|
|
|
|
ret;
|
2013-01-19 19:39:16 +08:00
|
|
|
|
ENDPROC(cast6_ecb_enc_8way)
|
2012-10-20 20:06:41 +08:00
|
|
|
|
|
2013-01-19 19:39:16 +08:00
|
|
|
|
ENTRY(cast6_ecb_dec_8way)
|
2012-10-20 20:06:41 +08:00
|
|
|
|
/* input:
|
2017-09-19 03:42:03 +08:00
|
|
|
|
* %rdi: ctx
|
2012-10-20 20:06:41 +08:00
|
|
|
|
* %rsi: dst
|
|
|
|
|
* %rdx: src
|
|
|
|
|
*/
|
2016-01-22 06:49:19 +08:00
|
|
|
|
FRAME_BEGIN
|
2017-09-19 03:42:03 +08:00
|
|
|
|
pushq %r15;
|
2012-10-20 20:06:41 +08:00
|
|
|
|
|
2017-09-19 03:42:03 +08:00
|
|
|
|
movq %rdi, CTX;
|
2012-10-20 20:06:41 +08:00
|
|
|
|
movq %rsi, %r11;
|
|
|
|
|
|
|
|
|
|
load_8way(%rdx, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
|
|
|
|
|
|
|
|
|
|
call __cast6_dec_blk8;
|
|
|
|
|
|
|
|
|
|
store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
|
|
|
|
|
|
2017-09-19 03:42:03 +08:00
|
|
|
|
popq %r15;
|
2016-01-22 06:49:19 +08:00
|
|
|
|
FRAME_END
|
2012-10-20 20:06:41 +08:00
|
|
|
|
ret;
|
2013-01-19 19:39:16 +08:00
|
|
|
|
ENDPROC(cast6_ecb_dec_8way)
|
2012-10-20 20:06:41 +08:00
|
|
|
|
|
2013-01-19 19:39:16 +08:00
|
|
|
|
ENTRY(cast6_cbc_dec_8way)
|
2012-10-20 20:06:41 +08:00
|
|
|
|
/* input:
|
2017-09-19 03:42:03 +08:00
|
|
|
|
* %rdi: ctx
|
2012-10-20 20:06:41 +08:00
|
|
|
|
* %rsi: dst
|
|
|
|
|
* %rdx: src
|
|
|
|
|
*/
|
2016-01-22 06:49:19 +08:00
|
|
|
|
FRAME_BEGIN
|
2012-10-20 20:06:41 +08:00
|
|
|
|
pushq %r12;
|
2017-09-19 03:42:03 +08:00
|
|
|
|
pushq %r15;
|
2012-10-20 20:06:41 +08:00
|
|
|
|
|
2017-09-19 03:42:03 +08:00
|
|
|
|
movq %rdi, CTX;
|
2012-10-20 20:06:41 +08:00
|
|
|
|
movq %rsi, %r11;
|
|
|
|
|
movq %rdx, %r12;
|
|
|
|
|
|
|
|
|
|
load_8way(%rdx, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
|
|
|
|
|
|
|
|
|
|
call __cast6_dec_blk8;
|
|
|
|
|
|
|
|
|
|
store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
|
|
|
|
|
|
2017-09-19 03:42:03 +08:00
|
|
|
|
popq %r15;
|
2012-10-20 20:06:41 +08:00
|
|
|
|
popq %r12;
|
2016-01-22 06:49:19 +08:00
|
|
|
|
FRAME_END
|
2012-10-20 20:06:41 +08:00
|
|
|
|
ret;
|
2013-01-19 19:39:16 +08:00
|
|
|
|
ENDPROC(cast6_cbc_dec_8way)
|
2012-10-20 20:06:41 +08:00
|
|
|
|
|
2013-01-19 19:39:16 +08:00
|
|
|
|
ENTRY(cast6_ctr_8way)
|
2012-10-20 20:06:41 +08:00
|
|
|
|
/* input:
|
|
|
|
|
* %rdi: ctx, CTX
|
|
|
|
|
* %rsi: dst
|
|
|
|
|
* %rdx: src
|
|
|
|
|
* %rcx: iv (little endian, 128bit)
|
|
|
|
|
*/
|
2016-01-22 06:49:19 +08:00
|
|
|
|
FRAME_BEGIN
|
2012-10-20 20:06:41 +08:00
|
|
|
|
pushq %r12;
|
2017-09-19 03:42:03 +08:00
|
|
|
|
pushq %r15
|
2012-10-20 20:06:41 +08:00
|
|
|
|
|
2017-09-19 03:42:03 +08:00
|
|
|
|
movq %rdi, CTX;
|
2012-10-20 20:06:41 +08:00
|
|
|
|
movq %rsi, %r11;
|
|
|
|
|
movq %rdx, %r12;
|
|
|
|
|
|
|
|
|
|
load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
|
|
|
|
|
RD2, RX, RKR, RKM);
|
|
|
|
|
|
|
|
|
|
call __cast6_enc_blk8;
|
|
|
|
|
|
|
|
|
|
store_ctr_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
|
|
|
|
|
|
2017-09-19 03:42:03 +08:00
|
|
|
|
popq %r15;
|
2012-10-20 20:06:41 +08:00
|
|
|
|
popq %r12;
|
2016-01-22 06:49:19 +08:00
|
|
|
|
FRAME_END
|
2012-07-12 01:38:57 +08:00
|
|
|
|
ret;
|
2013-01-19 19:39:16 +08:00
|
|
|
|
ENDPROC(cast6_ctr_8way)
|
2013-04-09 02:51:05 +08:00
|
|
|
|
|
|
|
|
|
ENTRY(cast6_xts_enc_8way)
|
|
|
|
|
/* input:
|
|
|
|
|
* %rdi: ctx, CTX
|
|
|
|
|
* %rsi: dst
|
|
|
|
|
* %rdx: src
|
|
|
|
|
* %rcx: iv (t ⊕ αⁿ ∈ GF(2¹²⁸))
|
|
|
|
|
*/
|
2016-01-22 06:49:19 +08:00
|
|
|
|
FRAME_BEGIN
|
2017-09-19 03:42:03 +08:00
|
|
|
|
pushq %r15;
|
2013-04-09 02:51:05 +08:00
|
|
|
|
|
2017-09-19 03:42:03 +08:00
|
|
|
|
movq %rdi, CTX
|
2013-04-09 02:51:05 +08:00
|
|
|
|
movq %rsi, %r11;
|
|
|
|
|
|
|
|
|
|
/* regs <= src, dst <= IVs, regs <= regs xor IVs */
|
|
|
|
|
load_xts_8way(%rcx, %rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2,
|
|
|
|
|
RX, RKR, RKM, .Lxts_gf128mul_and_shl1_mask);
|
|
|
|
|
|
|
|
|
|
call __cast6_enc_blk8;
|
|
|
|
|
|
|
|
|
|
/* dst <= regs xor IVs(in dst) */
|
|
|
|
|
store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
|
|
|
|
|
|
2017-09-19 03:42:03 +08:00
|
|
|
|
popq %r15;
|
2016-01-22 06:49:19 +08:00
|
|
|
|
FRAME_END
|
2013-04-09 02:51:05 +08:00
|
|
|
|
ret;
|
|
|
|
|
ENDPROC(cast6_xts_enc_8way)
|
|
|
|
|
|
|
|
|
|
ENTRY(cast6_xts_dec_8way)
|
|
|
|
|
/* input:
|
|
|
|
|
* %rdi: ctx, CTX
|
|
|
|
|
* %rsi: dst
|
|
|
|
|
* %rdx: src
|
|
|
|
|
* %rcx: iv (t ⊕ αⁿ ∈ GF(2¹²⁸))
|
|
|
|
|
*/
|
2016-01-22 06:49:19 +08:00
|
|
|
|
FRAME_BEGIN
|
2017-09-19 03:42:03 +08:00
|
|
|
|
pushq %r15;
|
2013-04-09 02:51:05 +08:00
|
|
|
|
|
2017-09-19 03:42:03 +08:00
|
|
|
|
movq %rdi, CTX
|
2013-04-09 02:51:05 +08:00
|
|
|
|
movq %rsi, %r11;
|
|
|
|
|
|
|
|
|
|
/* regs <= src, dst <= IVs, regs <= regs xor IVs */
|
|
|
|
|
load_xts_8way(%rcx, %rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2,
|
|
|
|
|
RX, RKR, RKM, .Lxts_gf128mul_and_shl1_mask);
|
|
|
|
|
|
|
|
|
|
call __cast6_dec_blk8;
|
|
|
|
|
|
|
|
|
|
/* dst <= regs xor IVs(in dst) */
|
|
|
|
|
store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
|
|
|
|
|
|
2017-09-19 03:42:03 +08:00
|
|
|
|
popq %r15;
|
2016-01-22 06:49:19 +08:00
|
|
|
|
FRAME_END
|
2013-04-09 02:51:05 +08:00
|
|
|
|
ret;
|
|
|
|
|
ENDPROC(cast6_xts_dec_8way)
|