2009-10-19 10:53:06 +08:00
|
|
|
/*
|
|
|
|
* Accelerated GHASH implementation with Intel PCLMULQDQ-NI
|
|
|
|
* instructions. This file contains accelerated part of ghash
|
|
|
|
* implementation. More information about PCLMULQDQ can be found at:
|
|
|
|
*
|
|
|
|
* http://software.intel.com/en-us/articles/carry-less-multiplication-and-its-usage-for-computing-the-gcm-mode/
|
|
|
|
*
|
|
|
|
* Copyright (c) 2009 Intel Corp.
|
|
|
|
* Author: Huang Ying <ying.huang@intel.com>
|
|
|
|
* Vinodh Gopal
|
|
|
|
* Erdinc Ozturk
|
|
|
|
* Deniz Karakoyunlu
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 as published
|
|
|
|
* by the Free Software Foundation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/linkage.h>
|
2009-11-23 19:55:22 +08:00
|
|
|
#include <asm/inst.h>
|
2016-01-22 06:49:19 +08:00
|
|
|
#include <asm/frame.h>
|
2009-10-19 10:53:06 +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.bswap_mask, "aM", @progbits, 16
|
2009-10-19 10:53:06 +08:00
|
|
|
.align 16
|
|
|
|
.Lbswap_mask:
|
|
|
|
.octa 0x000102030405060708090a0b0c0d0e0f
|
|
|
|
|
|
|
|
#define DATA %xmm0
|
|
|
|
#define SHASH %xmm1
|
|
|
|
#define T1 %xmm2
|
|
|
|
#define T2 %xmm3
|
|
|
|
#define T3 %xmm4
|
|
|
|
#define BSWAP %xmm5
|
|
|
|
#define IN1 %xmm6
|
|
|
|
|
|
|
|
.text
|
|
|
|
|
|
|
|
/*
|
|
|
|
* __clmul_gf128mul_ble: internal ABI
|
|
|
|
* input:
|
|
|
|
* DATA: operand1
|
|
|
|
* SHASH: operand2, hash_key << 1 mod poly
|
|
|
|
* output:
|
|
|
|
* DATA: operand1 * operand2 mod poly
|
|
|
|
* changed:
|
|
|
|
* T1
|
|
|
|
* T2
|
|
|
|
* T3
|
|
|
|
*/
|
|
|
|
__clmul_gf128mul_ble:
|
|
|
|
movaps DATA, T1
|
|
|
|
pshufd $0b01001110, DATA, T2
|
|
|
|
pshufd $0b01001110, SHASH, T3
|
|
|
|
pxor DATA, T2
|
|
|
|
pxor SHASH, T3
|
|
|
|
|
2009-11-23 19:55:22 +08:00
|
|
|
PCLMULQDQ 0x00 SHASH DATA # DATA = a0 * b0
|
|
|
|
PCLMULQDQ 0x11 SHASH T1 # T1 = a1 * b1
|
|
|
|
PCLMULQDQ 0x00 T3 T2 # T2 = (a1 + a0) * (b1 + b0)
|
2009-10-19 10:53:06 +08:00
|
|
|
pxor DATA, T2
|
|
|
|
pxor T1, T2 # T2 = a0 * b1 + a1 * b0
|
|
|
|
|
|
|
|
movaps T2, T3
|
|
|
|
pslldq $8, T3
|
|
|
|
psrldq $8, T2
|
|
|
|
pxor T3, DATA
|
|
|
|
pxor T2, T1 # <T1:DATA> is result of
|
|
|
|
# carry-less multiplication
|
|
|
|
|
|
|
|
# first phase of the reduction
|
|
|
|
movaps DATA, T3
|
|
|
|
psllq $1, T3
|
|
|
|
pxor DATA, T3
|
|
|
|
psllq $5, T3
|
|
|
|
pxor DATA, T3
|
|
|
|
psllq $57, T3
|
|
|
|
movaps T3, T2
|
|
|
|
pslldq $8, T2
|
|
|
|
psrldq $8, T3
|
|
|
|
pxor T2, DATA
|
|
|
|
pxor T3, T1
|
|
|
|
|
|
|
|
# second phase of the reduction
|
|
|
|
movaps DATA, T2
|
|
|
|
psrlq $5, T2
|
|
|
|
pxor DATA, T2
|
|
|
|
psrlq $1, T2
|
|
|
|
pxor DATA, T2
|
|
|
|
psrlq $1, T2
|
|
|
|
pxor T2, T1
|
|
|
|
pxor T1, DATA
|
|
|
|
ret
|
2013-01-19 19:39:26 +08:00
|
|
|
ENDPROC(__clmul_gf128mul_ble)
|
2009-10-19 10:53:06 +08:00
|
|
|
|
2014-04-04 20:24:03 +08:00
|
|
|
/* void clmul_ghash_mul(char *dst, const u128 *shash) */
|
2009-10-19 10:53:06 +08:00
|
|
|
ENTRY(clmul_ghash_mul)
|
2016-01-22 06:49:19 +08:00
|
|
|
FRAME_BEGIN
|
2009-10-19 10:53:06 +08:00
|
|
|
movups (%rdi), DATA
|
|
|
|
movups (%rsi), SHASH
|
|
|
|
movaps .Lbswap_mask, BSWAP
|
2009-11-23 19:55:22 +08:00
|
|
|
PSHUFB_XMM BSWAP DATA
|
2009-10-19 10:53:06 +08:00
|
|
|
call __clmul_gf128mul_ble
|
2009-11-23 19:55:22 +08:00
|
|
|
PSHUFB_XMM BSWAP DATA
|
2009-10-19 10:53:06 +08:00
|
|
|
movups DATA, (%rdi)
|
2016-01-22 06:49:19 +08:00
|
|
|
FRAME_END
|
2009-10-19 10:53:06 +08:00
|
|
|
ret
|
2013-01-19 19:39:26 +08:00
|
|
|
ENDPROC(clmul_ghash_mul)
|
2009-10-19 10:53:06 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* void clmul_ghash_update(char *dst, const char *src, unsigned int srclen,
|
2014-04-04 20:24:03 +08:00
|
|
|
* const u128 *shash);
|
2009-10-19 10:53:06 +08:00
|
|
|
*/
|
|
|
|
ENTRY(clmul_ghash_update)
|
2016-01-22 06:49:19 +08:00
|
|
|
FRAME_BEGIN
|
2009-10-19 10:53:06 +08:00
|
|
|
cmp $16, %rdx
|
|
|
|
jb .Lupdate_just_ret # check length
|
|
|
|
movaps .Lbswap_mask, BSWAP
|
|
|
|
movups (%rdi), DATA
|
|
|
|
movups (%rcx), SHASH
|
2009-11-23 19:55:22 +08:00
|
|
|
PSHUFB_XMM BSWAP DATA
|
2009-10-19 10:53:06 +08:00
|
|
|
.align 4
|
|
|
|
.Lupdate_loop:
|
|
|
|
movups (%rsi), IN1
|
2009-11-23 19:55:22 +08:00
|
|
|
PSHUFB_XMM BSWAP IN1
|
2009-10-19 10:53:06 +08:00
|
|
|
pxor IN1, DATA
|
|
|
|
call __clmul_gf128mul_ble
|
|
|
|
sub $16, %rdx
|
|
|
|
add $16, %rsi
|
|
|
|
cmp $16, %rdx
|
|
|
|
jge .Lupdate_loop
|
2009-11-23 19:55:22 +08:00
|
|
|
PSHUFB_XMM BSWAP DATA
|
2009-10-19 10:53:06 +08:00
|
|
|
movups DATA, (%rdi)
|
|
|
|
.Lupdate_just_ret:
|
2016-01-22 06:49:19 +08:00
|
|
|
FRAME_END
|
2009-10-19 10:53:06 +08:00
|
|
|
ret
|
2013-01-19 19:39:26 +08:00
|
|
|
ENDPROC(clmul_ghash_update)
|