2015-09-10 15:26:59 -07:00
/ *
* Intel S H A E x t e n s i o n s o p t i m i z e d i m p l e m e n t a t i o n o f a S H A - 1 u p d a t e f u n c t i o n
*
* This f i l e i s p r o v i d e d u n d e r a d u a l B S D / G P L v2 l i c e n s e . W h e n u s i n g o r
* redistributing t h i s f i l e , y o u m a y d o s o u n d e r e i t h e r l i c e n s e .
*
* GPL L I C E N S E S U M M A R Y
*
* Copyright( c ) 2 0 1 5 I n t e l C o r p o r a t i o n .
*
* This p r o g r a m i s f r e e s o f t w a r e ; you can redistribute it and/or modify
* it u n d e r t h e t e r m s o f v e r s i o n 2 o f t h e G N U G e n e r a l P u b l i c L i c e n s e a s
* published b y t h e F r e e S o f t w a r e F o u n d a t i o n .
*
* This p r o g r a m i s d i s t r i b u t e d i n t h e h o p e t h a t i t w i l l b e u s e f u l , b u t
* WITHOUT A N Y W A R R A N T Y ; without even the implied warranty of
* MERCHANTABILITY o r F I T N E S S F O R A P A R T I C U L A R P U R P O S E . S e e t h e G N U
* General P u b l i c L i c e n s e f o r m o r e d e t a i l s .
*
* Contact I n f o r m a t i o n :
* Sean G u l l e y < s e a n . m . g u l l e y @intel.com>
* Tim C h e n < t i m . c . c h e n @linux.intel.com>
*
* BSD L I C E N S E
*
* Copyright( c ) 2 0 1 5 I n t e l C o r p o r a t i o n .
*
* Redistribution a n d u s e i n s o u r c e a n d b i n a r y f o r m s , w i t h o r w i t h o u t
* modification, a r e p e r m i t t e d p r o v i d e d t h a t t h e f o l l o w i n g c o n d i t i o n s
* are m e t :
*
* * Redistributions o f s o u r c e c o d e m u s t r e t a i n t h e a b o v e c o p y r i g h t
* notice, t h i s l i s t o f c o n d i t i o n s a n d t h e f o l l o w i n g d i s c l a i m e r .
* * Redistributions i n b i n a r y f o r m m u s t r e p r o d u c e t h e a b o v e c o p y r i g h t
* notice, t h i s l i s t o f c o n d i t i o n s a n d t h e f o l l o w i n g d i s c l a i m e r i n
* the d o c u m e n t a t i o n a n d / o r o t h e r m a t e r i a l s p r o v i d e d w i t h t h e
* distribution.
* * Neither t h e n a m e o f I n t e l C o r p o r a t i o n n o r t h e n a m e s o f i t s
* contributors m a y b e u s e d t o e n d o r s e o r p r o m o t e p r o d u c t s d e r i v e d
* from t h i s s o f t w a r e w i t h o u t s p e c i f i c p r i o r w r i t t e n p e r m i s s i o n .
*
* THIS S O F T W A R E I S P R O V I D E D B Y T H E C O P Y R I G H T H O L D E R S A N D C O N T R I B U T O R S
* " AS I S " A N D A N Y E X P R E S S O R I M P L I E D W A R R A N T I E S , I N C L U D I N G , B U T N O T
* LIMITED T O , T H E I M P L I E D W A R R A N T I E S O F M E R C H A N T A B I L I T Y A N D F I T N E S S F O R
* A P A R T I C U L A R P U R P O S E A R E D I S C L A I M E D . I N N O E V E N T S H A L L T H E C O P Y R I G H T
* OWNER O R C O N T R I B U T O R S B E L I A B L E F O R A N Y D I R E C T , I N D I R E C T , I N C I D E N T A L ,
* SPECIAL, E X E M P L A R Y , O R C O N S E Q U E N T I A L D A M A G E S ( I N C L U D I N G , B U T N O T
* LIMITED T O , P R O C U R E M E N T O F S U B S T I T U T E G O O D S O R S E R V I C E S ; LOSS OF USE,
* DATA, O R P R O F I T S ; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY O F L I A B I L I T Y , W H E T H E R I N C O N T R A C T , S T R I C T L I A B I L I T Y , O R T O R T
* ( INCLUDING N E G L I G E N C E O R O T H E R W I S E ) A R I S I N G I N A N Y W A Y O U T O F T H E U S E
* OF T H I S S O F T W A R E , E V E N I F A D V I S E D O F T H E P O S S I B I L I T Y O F S U C H D A M A G E .
*
* /
# include < l i n u x / l i n k a g e . h >
# define D I G E S T _ P T R % r d i / * 1 s t a r g * /
# define D A T A _ P T R % r s i / * 2 n d a r g * /
# define N U M _ B L K S % r d x / * 3 r d a r g * /
/* gcc conversion */
# define F R A M E _ S I Z E 3 2 / * s p a c e f o r 2 x16 b y t e s * /
# define A B C D % x m m 0
# define E 0 % x m m 1 / * N e e d t w o E ' s b / c t h e y p i n g p o n g * /
# define E 1 % x m m 2
# define M S G 0 % x m m 3
# define M S G 1 % x m m 4
# define M S G 2 % x m m 5
# define M S G 3 % x m m 6
# define S H U F _ M A S K % x m m 7
/ *
* Intel S H A E x t e n s i o n s o p t i m i z e d i m p l e m e n t a t i o n o f a S H A - 1 u p d a t e f u n c t i o n
*
* The f u n c t i o n t a k e s a p o i n t e r t o t h e c u r r e n t h a s h v a l u e s , a p o i n t e r t o t h e
* input d a t a , a n d a n u m b e r o f 6 4 b y t e b l o c k s t o p r o c e s s . O n c e a l l b l o c k s h a v e
* been p r o c e s s e d , t h e d i g e s t p o i n t e r i s u p d a t e d w i t h t h e r e s u l t i n g h a s h v a l u e .
* The f u n c t i o n o n l y p r o c e s s e s c o m p l e t e b l o c k s , t h e r e i s n o f u n c t i o n a l i t y t o
* store p a r t i a l b l o c k s . A l l m e s s a g e p a d d i n g a n d h a s h v a l u e i n i t i a l i z a t i o n m u s t
* be d o n e o u t s i d e t h e u p d a t e f u n c t i o n .
*
* The i n d e n t e d l i n e s i n t h e l o o p a r e i n s t r u c t i o n s r e l a t e d t o r o u n d s p r o c e s s i n g .
* The n o n - i n d e n t e d l i n e s a r e i n s t r u c t i o n s r e l a t e d t o t h e m e s s a g e s c h e d u l e .
*
* void s h a1 _ n i _ t r a n s f o r m ( u i n t 3 2 _ t * d i g e s t , c o n s t v o i d * d a t a ,
uint3 2 _ t n u m B l o c k s )
* digest : p o i n t e r t o d i g e s t
* data : pointer t o i n p u t d a t a
* numBlocks : Number o f b l o c k s t o p r o c e s s
* /
.text
2019-10-11 13:51:04 +02:00
SYM_ F U N C _ S T A R T ( s h a1 _ n i _ t r a n s f o r m )
2021-02-24 10:29:20 -06:00
push % r b p
mov % r s p , % r b p
2015-09-10 15:26:59 -07:00
sub $ F R A M E _ S I Z E , % r s p
and $ ~ 0 x F , % r s p
shl $ 6 , N U M _ B L K S / * c o n v e r t t o b y t e s * /
jz . L d o n e _ h a s h
add D A T A _ P T R , N U M _ B L K S / * p o i n t e r t o e n d o f d a t a * /
/* load initial hash values */
pinsrd $ 3 , 1 * 1 6 ( D I G E S T _ P T R ) , E 0
movdqu 0 * 1 6 ( D I G E S T _ P T R ) , A B C D
pand U P P E R _ W O R D _ M A S K ( % r i p ) , E 0
pshufd $ 0 x1 B , A B C D , A B C D
movdqa P S H U F F L E _ B Y T E _ F L I P _ M A S K ( % r i p ) , S H U F _ M A S K
.Lloop0 :
/* Save hash values for addition after rounds */
movdqa E 0 , ( 0 * 1 6 ) ( % r s p )
movdqa A B C D , ( 1 * 1 6 ) ( % r s p )
/* Rounds 0-3 */
movdqu 0 * 1 6 ( D A T A _ P T R ) , M S G 0
pshufb S H U F _ M A S K , M S G 0
paddd M S G 0 , E 0
movdqa A B C D , E 1
sha1 r n d s4 $ 0 , E 0 , A B C D
/* Rounds 4-7 */
movdqu 1 * 1 6 ( D A T A _ P T R ) , M S G 1
pshufb S H U F _ M A S K , M S G 1
sha1 n e x t e M S G 1 , E 1
movdqa A B C D , E 0
sha1 r n d s4 $ 0 , E 1 , A B C D
sha1 m s g 1 M S G 1 , M S G 0
/* Rounds 8-11 */
movdqu 2 * 1 6 ( D A T A _ P T R ) , M S G 2
pshufb S H U F _ M A S K , M S G 2
sha1 n e x t e M S G 2 , E 0
movdqa A B C D , E 1
sha1 r n d s4 $ 0 , E 0 , A B C D
sha1 m s g 1 M S G 2 , M S G 1
pxor M S G 2 , M S G 0
/* Rounds 12-15 */
movdqu 3 * 1 6 ( D A T A _ P T R ) , M S G 3
pshufb S H U F _ M A S K , M S G 3
sha1 n e x t e M S G 3 , E 1
movdqa A B C D , E 0
sha1 m s g 2 M S G 3 , M S G 0
sha1 r n d s4 $ 0 , E 1 , A B C D
sha1 m s g 1 M S G 3 , M S G 2
pxor M S G 3 , M S G 1
/* Rounds 16-19 */
sha1 n e x t e M S G 0 , E 0
movdqa A B C D , E 1
sha1 m s g 2 M S G 0 , M S G 1
sha1 r n d s4 $ 0 , E 0 , A B C D
sha1 m s g 1 M S G 0 , M S G 3
pxor M S G 0 , M S G 2
/* Rounds 20-23 */
sha1 n e x t e M S G 1 , E 1
movdqa A B C D , E 0
sha1 m s g 2 M S G 1 , M S G 2
sha1 r n d s4 $ 1 , E 1 , A B C D
sha1 m s g 1 M S G 1 , M S G 0
pxor M S G 1 , M S G 3
/* Rounds 24-27 */
sha1 n e x t e M S G 2 , E 0
movdqa A B C D , E 1
sha1 m s g 2 M S G 2 , M S G 3
sha1 r n d s4 $ 1 , E 0 , A B C D
sha1 m s g 1 M S G 2 , M S G 1
pxor M S G 2 , M S G 0
/* Rounds 28-31 */
sha1 n e x t e M S G 3 , E 1
movdqa A B C D , E 0
sha1 m s g 2 M S G 3 , M S G 0
sha1 r n d s4 $ 1 , E 1 , A B C D
sha1 m s g 1 M S G 3 , M S G 2
pxor M S G 3 , M S G 1
/* Rounds 32-35 */
sha1 n e x t e M S G 0 , E 0
movdqa A B C D , E 1
sha1 m s g 2 M S G 0 , M S G 1
sha1 r n d s4 $ 1 , E 0 , A B C D
sha1 m s g 1 M S G 0 , M S G 3
pxor M S G 0 , M S G 2
/* Rounds 36-39 */
sha1 n e x t e M S G 1 , E 1
movdqa A B C D , E 0
sha1 m s g 2 M S G 1 , M S G 2
sha1 r n d s4 $ 1 , E 1 , A B C D
sha1 m s g 1 M S G 1 , M S G 0
pxor M S G 1 , M S G 3
/* Rounds 40-43 */
sha1 n e x t e M S G 2 , E 0
movdqa A B C D , E 1
sha1 m s g 2 M S G 2 , M S G 3
sha1 r n d s4 $ 2 , E 0 , A B C D
sha1 m s g 1 M S G 2 , M S G 1
pxor M S G 2 , M S G 0
/* Rounds 44-47 */
sha1 n e x t e M S G 3 , E 1
movdqa A B C D , E 0
sha1 m s g 2 M S G 3 , M S G 0
sha1 r n d s4 $ 2 , E 1 , A B C D
sha1 m s g 1 M S G 3 , M S G 2
pxor M S G 3 , M S G 1
/* Rounds 48-51 */
sha1 n e x t e M S G 0 , E 0
movdqa A B C D , E 1
sha1 m s g 2 M S G 0 , M S G 1
sha1 r n d s4 $ 2 , E 0 , A B C D
sha1 m s g 1 M S G 0 , M S G 3
pxor M S G 0 , M S G 2
/* Rounds 52-55 */
sha1 n e x t e M S G 1 , E 1
movdqa A B C D , E 0
sha1 m s g 2 M S G 1 , M S G 2
sha1 r n d s4 $ 2 , E 1 , A B C D
sha1 m s g 1 M S G 1 , M S G 0
pxor M S G 1 , M S G 3
/* Rounds 56-59 */
sha1 n e x t e M S G 2 , E 0
movdqa A B C D , E 1
sha1 m s g 2 M S G 2 , M S G 3
sha1 r n d s4 $ 2 , E 0 , A B C D
sha1 m s g 1 M S G 2 , M S G 1
pxor M S G 2 , M S G 0
/* Rounds 60-63 */
sha1 n e x t e M S G 3 , E 1
movdqa A B C D , E 0
sha1 m s g 2 M S G 3 , M S G 0
sha1 r n d s4 $ 3 , E 1 , A B C D
sha1 m s g 1 M S G 3 , M S G 2
pxor M S G 3 , M S G 1
/* Rounds 64-67 */
sha1 n e x t e M S G 0 , E 0
movdqa A B C D , E 1
sha1 m s g 2 M S G 0 , M S G 1
sha1 r n d s4 $ 3 , E 0 , A B C D
sha1 m s g 1 M S G 0 , M S G 3
pxor M S G 0 , M S G 2
/* Rounds 68-71 */
sha1 n e x t e M S G 1 , E 1
movdqa A B C D , E 0
sha1 m s g 2 M S G 1 , M S G 2
sha1 r n d s4 $ 3 , E 1 , A B C D
pxor M S G 1 , M S G 3
/* Rounds 72-75 */
sha1 n e x t e M S G 2 , E 0
movdqa A B C D , E 1
sha1 m s g 2 M S G 2 , M S G 3
sha1 r n d s4 $ 3 , E 0 , A B C D
/* Rounds 76-79 */
sha1 n e x t e M S G 3 , E 1
movdqa A B C D , E 0
sha1 r n d s4 $ 3 , E 1 , A B C D
/* Add current hash values with previously saved */
sha1 n e x t e ( 0 * 1 6 ) ( % r s p ) , E 0
paddd ( 1 * 1 6 ) ( % r s p ) , A B C D
/* Increment data pointer and loop if more to process */
add $ 6 4 , D A T A _ P T R
cmp N U M _ B L K S , D A T A _ P T R
jne . L l o o p0
/* Write hash values back in the correct order */
pshufd $ 0 x1 B , A B C D , A B C D
movdqu A B C D , 0 * 1 6 ( D I G E S T _ P T R )
pextrd $ 3 , E 0 , 1 * 1 6 ( D I G E S T _ P T R )
.Ldone_hash :
2021-02-24 10:29:20 -06:00
mov % r b p , % r s p
pop % r b p
2015-09-10 15:26:59 -07:00
2021-12-04 14:43:40 +01:00
RET
2019-10-11 13:51:04 +02:00
SYM_ F U N C _ E N D ( s h a1 _ n i _ t r a n s f o r m )
2015-09-10 15:26:59 -07: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-19 22:33:04 +01:00
.section .rodata .cst16 .PSHUFFLE_BYTE_FLIP_MASK , " aM" , @progbits, 16
.align 16
2015-09-10 15:26:59 -07:00
PSHUFFLE_BYTE_FLIP_MASK :
.octa 0x000102030405060708090a0b0c0d0e0f
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-19 22:33:04 +01:00
.section .rodata .cst16 .UPPER_WORD_MASK , " aM" , @progbits, 16
.align 16
2015-09-10 15:26:59 -07:00
UPPER_WORD_MASK :
.octa 0xFFFFFFFF000000000000000000000000