2013-03-27 00:59:37 +04:00
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Implement f a s t S H A - 5 1 2 w i t h S S S E 3 i n s t r u c t i o n s . ( x86 _ 6 4 )
#
# Copyright ( C ) 2 0 1 3 I n t e l C o r p o r a t i o n .
#
# Authors :
# James G u i l f o r d < j a m e s . g u i l f o r d @intel.com>
# Kirk Y a p < k i r k . s . y a p @intel.com>
# David C o t e < d a v i d . m . c o t e @intel.com>
# Tim C h e n < t i m . c . c h e n @linux.intel.com>
#
# This s o f t w a r e i s a v a i l a b l e t o y o u u n d e r a c h o i c e o f o n e o f t w o
# licenses. Y o u m a y c h o o s e t o b e l i c e n s e d u n d e r t h e t e r m s o f t h e G N U
# General P u b l i c L i c e n s e ( G P L ) V e r s i o n 2 , a v a i l a b l e f r o m t h e f i l e
# COPYING i n t h e m a i n d i r e c t o r y o f t h i s s o u r c e t r e e , o r t h e
# OpenIB. o r g B S D l i c e n s e b e l o w :
#
# 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
# without m o d i f i c a t i o n , 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
# conditions a r e 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
# copyright n o t i c e , 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
# disclaimer.
#
# - 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
# copyright n o t i c e , 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
# disclaimer i n t h e 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
# provided w i t h t h e d i s t r i b u t i o n .
#
# THE S O F T W A R E I S P R O V I D E D " A S I S " , W I T H O U T W A R R A N T Y O F A N Y K I N D ,
# EXPRESS O R I M P L I E D , I N C L U D I N G B U T N O T L I M I T E D T O T H E W A R R A N T I E S O F
# MERCHANTABILITY, 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 N D
# NONINFRINGEMENT. I N N O E V E N T S H A L L T H E A U T H O R S O R C O P Y R I G H T H O L D E R S
# BE L I A B L E F O R A N Y C L A I M , D A M A G E S O R O T H E R L I A B I L I T Y , W H E T H E R I N A N
# ACTION O F C O N T R A C T , T O R T O R O T H E R W I S E , A R I S I N G F R O M , O U T O F O R I N
# CONNECTION W I T H T H E S O F T W A R E O R T H E U S E O R O T H E R D E A L I N G S I N T H E
# SOFTWARE.
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
# This c o d e i s d e s c r i b e d i n a n I n t e l W h i t e - P a p e r :
# " Fast S H A - 5 1 2 I m p l e m e n t a t i o n s o n I n t e l A r c h i t e c t u r e P r o c e s s o r s "
#
# To f i n d i t , s u r f t o h t t p : / / w w w . i n t e l . c o m / p / e n _ U S / e m b e d d e d
# and s e a r c h f o r t h a t t i t l e .
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# include < l i n u x / l i n k a g e . h >
2022-11-18 22:44:15 +03:00
# include < l i n u x / c f i _ t y p e s . h >
2013-03-27 00:59:37 +04:00
.text
# Virtual R e g i s t e r s
# ARG1
2015-04-09 13:55:48 +03:00
digest = % r d i
2013-03-27 00:59:37 +04:00
# ARG2
2015-04-09 13:55:48 +03:00
msg = % r s i
2013-03-27 00:59:37 +04:00
# ARG3
msglen = % r d x
T1 = % r c x
T2 = % r8
a_ 6 4 = % r9
b_ 6 4 = % r10
c_ 6 4 = % r11
d_ 6 4 = % r12
e_ 6 4 = % r13
f_ 6 4 = % r14
g_ 6 4 = % r15
h_ 6 4 = % r b x
tmp0 = % r a x
# Local v a r i a b l e s ( s t a c k f r a m e )
W_ S I Z E = 8 0 * 8
WK_ S I Z E = 2 * 8
frame_ W = 0
frame_ W K = f r a m e _ W + W _ S I Z E
2021-02-24 19:29:25 +03:00
frame_ s i z e = f r a m e _ W K + W K _ S I Z E
2013-03-27 00:59:37 +04:00
# Useful Q W O R D " a r r a y s " f o r s i m p l e r m e m o r y r e f e r e n c e s
# MSG, D I G E S T , K _ t , W _ t a r e a r r a y s
# WK_ 2 ( t ) p o i n t s t o 1 o f 2 q w o r d s a t f r a m e . W K d e p d e n d i n g o n t b e i n g o d d / e v e n
# Input m e s s a g e ( a r g 1 )
# define M S G ( i ) 8 * i ( m s g )
# Output D i g e s t ( a r g 2 )
# define D I G E S T ( i ) 8 * i ( d i g e s t )
# SHA C o n s t a n t s ( s t a t i c m e m )
# define K _ t ( i ) 8 * i + K 5 1 2 ( % r i p )
# Message S c h e d u l e ( s t a c k f r a m e )
# define W _ t ( i ) 8 * i + f r a m e _ W ( % r s p )
# W[ t ] + K [ t ] ( s t a c k f r a m e )
# define W K _ 2 ( i ) 8 * ( ( i % 2 ) ) + f r a m e _ W K ( % r s p )
.macro RotateState
# Rotate s y m b o l s a . . h r i g h t
TMP = h _ 6 4
h_ 6 4 = g _ 6 4
g_ 6 4 = f _ 6 4
f_ 6 4 = e _ 6 4
e_ 6 4 = d _ 6 4
d_ 6 4 = c _ 6 4
c_ 6 4 = b _ 6 4
b_ 6 4 = a _ 6 4
a_ 6 4 = T M P
.endm
.macro SHA512_Round rnd
# Compute R o u n d % % t
mov f _ 6 4 , T 1 # T 1 = f
mov e _ 6 4 , t m p0 # t m p = e
xor g _ 6 4 , T 1 # T 1 = f ^ g
ror $ 2 3 , t m p0 # 41 # t m p = e r o r 23
and e _ 6 4 , T 1 # T 1 = ( f ^ g ) & e
xor e _ 6 4 , t m p0 # t m p = ( e r o r 23 ) ^ e
xor g _ 6 4 , T 1 # T 1 = ( ( f ^ g ) & e ) ^ g = C H ( e ,f ,g )
idx = \ r n d
add W K _ 2 ( i d x ) , T 1 # W [ t ] + K [ t ] f r o m m e s s a g e s c h e d u l e r
ror $ 4 , t m p0 # 18 # t m p = ( ( e r o r 23 ) ^ e ) r o r 4
xor e _ 6 4 , t m p0 # t m p = ( ( ( e r o r 23 ) ^ e ) r o r 4 ) ^ e
mov a _ 6 4 , T 2 # T 2 = a
add h _ 6 4 , T 1 # T 1 = C H ( e ,f ,g ) + W [ t ] + K [ t ] + h
ror $ 1 4 , t m p0 # 14 # t m p = ( ( ( ( e r o r 23 ) ^ e ) r o r4 ) ^ e ) r o r14 = S 1 ( e )
add t m p0 , T 1 # T 1 = C H ( e ,f ,g ) + W [ t ] + K [ t ] + S 1 ( e )
mov a _ 6 4 , t m p0 # t m p = a
xor c _ 6 4 , T 2 # T 2 = a ^ c
and c _ 6 4 , t m p0 # t m p = a & c
and b _ 6 4 , T 2 # T 2 = ( a ^ c ) & b
xor t m p0 , T 2 # T 2 = ( ( a ^ c ) & b ) ^ ( a & c ) = M a j ( a ,b ,c )
mov a _ 6 4 , t m p0 # t m p = a
ror $ 5 , t m p0 # 39 # t m p = a r o r 5
xor a _ 6 4 , t m p0 # t m p = ( a r o r 5 ) ^ a
add T 1 , d _ 6 4 # e ( n e x t _ s t a t e ) = d + T 1
ror $ 6 , t m p0 # 34 # t m p = ( ( a r o r 5 ) ^ a ) r o r 6
xor a _ 6 4 , t m p0 # t m p = ( ( ( a r o r 5 ) ^ a ) r o r 6 ) ^ a
lea ( T 1 , T 2 ) , h _ 6 4 # a ( n e x t _ s t a t e ) = T 1 + M a j ( a ,b ,c )
ror $ 2 8 , t m p0 # 28 # t m p = ( ( ( ( a r o r 5 ) ^ a ) r o r6 ) ^ a ) r o r28 = S 0 ( a )
add t m p0 , h _ 6 4 # a ( n e x t _ s t a t e ) = T 1 + M a j ( a ,b ,c ) S 0 ( a )
RotateState
.endm
.macro SHA512_2Sched_2Round_sse rnd
# Compute r o u n d s t - 2 a n d t - 1
# Compute m e s s a g e s c h e d u l e Q W O R D S t a n d t + 1
# Two r o u n d s a r e c o m p u t e d b a s e d o n t h e v a l u e s f o r K [ t - 2 ] + W [ t - 2 ] a n d
# K[ t - 1 ] + W [ t - 1 ] w h i c h w e r e p r e v i o u s l y s t o r e d a t W K _ 2 b y t h e m e s s a g e
# scheduler.
# The t w o n e w s c h e d u l e Q W O R D S a r e s t o r e d a t [ W _ t ( % % t ) ] a n d [ W _ t ( % % t + 1 ) ] .
# They a r e t h e n a d d e d t o t h e i r r e s p e c t i v e S H A 5 1 2 c o n s t a n t s a t
# [ K_ t ( % % t ) ] a n d [ K _ t ( % % t + 1 ) ] a n d s t o r e d a t d q w o r d [ W K _ 2 ( % % t ) ]
# For b r i e v i t y , t h e c o m m e n t s f o l l o w i n g v e c t o r e d i n s t r u c t i o n s o n l y r e f e r t o
# the f i r s t o f a p a i r o f Q W O R D S .
# Eg. X M M 2 =W [ t - 2 ] r e a l l y m e a n s X M M 2 = { W [ t - 2 ] | W [ t - 1 ] }
# The c o m p u t a t i o n o f t h e m e s s a g e s c h e d u l e a n d t h e r o u n d s a r e t i g h t l y
# stitched t o t a k e a d v a n t a g e o f i n s t r u c t i o n - l e v e l p a r a l l e l i s m .
# For c l a r i t y , i n t e g e r i n s t r u c t i o n s ( f o r t h e r o u n d s c a l c u l a t i o n ) a r e i n d e n t e d
# by o n e t a b . V e c t o r e d i n s t r u c t i o n s ( f o r t h e m e s s a g e s c h e d u l e r ) a r e i n d e n t e d
# by t w o t a b s .
mov f _ 6 4 , T 1
idx = \ r n d - 2
movdqa W _ t ( i d x ) , % x m m 2 # X M M 2 = W [ t - 2 ]
xor g _ 6 4 , T 1
and e _ 6 4 , T 1
movdqa % x m m 2 , % x m m 0 # X M M 0 = W [ t - 2 ]
xor g _ 6 4 , T 1
idx = \ r n d
add W K _ 2 ( i d x ) , T 1
idx = \ r n d - 1 5
movdqu W _ t ( i d x ) , % x m m 5 # X M M 5 = W [ t - 1 5 ]
mov e _ 6 4 , t m p0
ror $ 2 3 , t m p0 # 41
movdqa % x m m 5 , % x m m 3 # X M M 3 = W [ t - 1 5 ]
xor e _ 6 4 , t m p0
ror $ 4 , t m p0 # 18
psrlq $ 6 1 - 1 9 , % x m m 0 # X M M 0 = W [ t - 2 ] > > 4 2
xor e _ 6 4 , t m p0
ror $ 1 4 , t m p0 # 14
psrlq $ ( 8 - 7 ) , % x m m 3 # X M M 3 = W [ t - 1 5 ] > > 1
add t m p0 , T 1
add h _ 6 4 , T 1
pxor % x m m 2 , % x m m 0 # X M M 0 = ( W [ t - 2 ] > > 4 2 ) ^ W [ t - 2 ]
mov a _ 6 4 , T 2
xor c _ 6 4 , T 2
pxor % x m m 5 , % x m m 3 # X M M 3 = ( W [ t - 1 5 ] > > 1 ) ^ W [ t - 1 5 ]
and b _ 6 4 , T 2
mov a _ 6 4 , t m p0
psrlq $ ( 1 9 - 6 ) , % x m m 0 # X M M 0 = ( ( W [ t - 2 ] > > 4 2 ) ^ W [ t - 2 ] ) > > 1 3
and c _ 6 4 , t m p0
xor t m p0 , T 2
psrlq $ ( 7 - 1 ) , % x m m 3 # X M M 3 = ( ( W [ t - 1 5 ] > > 1 ) ^ W [ t - 1 5 ] ) > > 6
mov a _ 6 4 , t m p0
ror $ 5 , t m p0 # 39
pxor % x m m 2 , % x m m 0 # X M M 0 = ( ( ( W [ t - 2 ] > > 4 2 ) ^ W [ t - 2 ] ) > > 1 3 ) ^ W [ t - 2 ]
xor a _ 6 4 , t m p0
ror $ 6 , t m p0 # 34
pxor % x m m 5 , % x m m 3 # X M M 3 = ( ( ( W [ t - 1 5 ] > > 1 ) ^ W [ t - 1 5 ] ) > > 6 ) ^ W [ t - 1 5 ]
xor a _ 6 4 , t m p0
ror $ 2 8 , t m p0 # 28
psrlq $ 6 , % x m m 0 # X M M 0 = ( ( ( ( W [ t - 2 ] > > 4 2 ) ^ W [ t - 2 ] ) > > 1 3 ) ^ W [ t - 2 ] ) > > 6
add t m p0 , T 2
add T 1 , d _ 6 4
psrlq $ 1 , % x m m 3 # X M M 3 = ( ( ( W [ t - 1 5 ] > > 1 ) ^ W [ t - 1 5 ] ) > > 6 ) ^ W [ t - 1 5 ] > > 1
lea ( T 1 , T 2 ) , h _ 6 4
RotateState
movdqa % x m m 2 , % x m m 1 # X M M 1 = W [ t - 2 ]
mov f _ 6 4 , T 1
xor g _ 6 4 , T 1
movdqa % x m m 5 , % x m m 4 # X M M 4 = W [ t - 1 5 ]
and e _ 6 4 , T 1
xor g _ 6 4 , T 1
psllq $ ( 6 4 - 1 9 ) - ( 6 4 - 6 1 ) , % x m m 1 # X M M 1 = W [ t - 2 ] < < 4 2
idx = \ r n d + 1
add W K _ 2 ( i d x ) , T 1
mov e _ 6 4 , t m p0
psllq $ ( 6 4 - 1 ) - ( 6 4 - 8 ) , % x m m 4 # X M M 4 = W [ t - 1 5 ] < < 7
ror $ 2 3 , t m p0 # 41
xor e _ 6 4 , t m p0
pxor % x m m 2 , % x m m 1 # X M M 1 = ( W [ t - 2 ] < < 4 2 ) ^ W [ t - 2 ]
ror $ 4 , t m p0 # 18
xor e _ 6 4 , t m p0
pxor % x m m 5 , % x m m 4 # X M M 4 = ( W [ t - 1 5 ] < < 7 ) ^ W [ t - 1 5 ]
ror $ 1 4 , t m p0 # 14
add t m p0 , T 1
psllq $ ( 6 4 - 6 1 ) , % x m m 1 # X M M 1 = ( ( W [ t - 2 ] < < 4 2 ) ^ W [ t - 2 ] ) < < 3
add h _ 6 4 , T 1
mov a _ 6 4 , T 2
psllq $ ( 6 4 - 8 ) , % x m m 4 # X M M 4 = ( ( W [ t - 1 5 ] < < 7 ) ^ W [ t - 1 5 ] ) < < 5 6
xor c _ 6 4 , T 2
and b _ 6 4 , T 2
pxor % x m m 1 , % x m m 0 # X M M 0 = s1 ( W [ t - 2 ] )
mov a _ 6 4 , t m p0
and c _ 6 4 , t m p0
idx = \ r n d - 7
movdqu W _ t ( i d x ) , % x m m 1 # X M M 1 = W [ t - 7 ]
xor t m p0 , T 2
pxor % x m m 4 , % x m m 3 # X M M 3 = s0 ( W [ t - 1 5 ] )
mov a _ 6 4 , t m p0
paddq % x m m 3 , % x m m 0 # X M M 0 = s1 ( W [ t - 2 ] ) + s0 ( W [ t - 1 5 ] )
ror $ 5 , t m p0 # 39
idx = \ r n d - 1 6
paddq W _ t ( i d x ) , % x m m 0 # X M M 0 = s1 ( W [ t - 2 ] ) + s0 ( W [ t - 1 5 ] ) + W [ t - 1 6 ]
xor a _ 6 4 , t m p0
paddq % x m m 1 , % x m m 0 # X M M 0 = s1 ( W [ t - 2 ] ) + W [ t - 7 ] + s0 ( W [ t - 1 5 ] ) + W [ t - 1 6 ]
ror $ 6 , t m p0 # 34
movdqa % x m m 0 , W _ t ( \ r n d ) # S t o r e s c h e d u l e d q w o r d s
xor a _ 6 4 , t m p0
paddq K _ t ( \ r n d ) , % x m m 0 # C o m p u t e W [ t ] + K [ t ]
ror $ 2 8 , t m p0 # 28
idx = \ r n d
movdqa % x m m 0 , W K _ 2 ( i d x ) # S t o r e W [ t ] + K [ t ] f o r n e x t r o u n d s
add t m p0 , T 2
add T 1 , d _ 6 4
lea ( T 1 , T 2 ) , h _ 6 4
RotateState
.endm
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
2020-01-15 06:57:29 +03:00
# # void s h a51 2 _ t r a n s f o r m _ s s s e 3 ( s t r u c t s h a51 2 _ s t a t e * s t a t e , c o n s t u 8 * d a t a ,
# # int b l o c k s ) ;
# ( struct s h a51 2 _ s t a t e i s a s s u m e d t o b e g i n w i t h u 6 4 s t a t e [ 8 ] )
# Purpose : Updates t h e S H A 5 1 2 d i g e s t s t o r e d a t " s t a t e " w i t h t h e m e s s a g e
# stored i n " d a t a " .
# The s i z e o f t h e m e s s a g e p o i n t e d t o b y " d a t a " m u s t b e a n i n t e g e r m u l t i p l e
# of S H A 5 1 2 m e s s a g e b l o c k s .
# " blocks" i s t h e m e s s a g e l e n g t h i n S H A 5 1 2 b l o c k s .
2013-03-27 00:59:37 +04:00
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
2022-11-18 22:44:15 +03:00
SYM_ T Y P E D _ F U N C _ S T A R T ( s h a51 2 _ t r a n s f o r m _ s s s e 3 )
2013-03-27 00:59:37 +04:00
2020-11-27 12:59:43 +03:00
test m s g l e n , m s g l e n
2013-03-27 00:59:37 +04:00
je n o w o r k
2021-02-24 19:29:25 +03:00
# Save G P R s
push % r b x
push % r12
push % r13
push % r14
push % r15
2013-03-27 00:59:37 +04:00
# Allocate S t a c k S p a c e
2021-02-24 19:29:25 +03:00
push % r b p
mov % r s p , % r b p
2013-03-27 00:59:37 +04:00
sub $ f r a m e _ s i z e , % r s p
and $ ~ ( 0 x20 - 1 ) , % r s p
updateblock :
# Load s t a t e v a r i a b l e s
mov D I G E S T ( 0 ) , a _ 6 4
mov D I G E S T ( 1 ) , b _ 6 4
mov D I G E S T ( 2 ) , c _ 6 4
mov D I G E S T ( 3 ) , d _ 6 4
mov D I G E S T ( 4 ) , e _ 6 4
mov D I G E S T ( 5 ) , f _ 6 4
mov D I G E S T ( 6 ) , g _ 6 4
mov D I G E S T ( 7 ) , h _ 6 4
t = 0
.rept 8 0 / 2 + 1
# ( 8 0 rounds) / ( 2 r o u n d s / i t e r a t i o n ) + ( 1 i t e r a t i o n )
# + 1 iteration b e c a u s e t h e s c h e d u l e r l e a d s h a s h i n g b y 1 i t e r a t i o n
.if t < 2
# BSWAP 2 Q W O R D S
movdqa X M M _ Q W O R D _ B S W A P ( % r i p ) , % x m m 1
movdqu M S G ( t ) , % x m m 0
pshufb % x m m 1 , % x m m 0 # B S W A P
movdqa % x m m 0 , W _ t ( t ) # S t o r e S c h e d u l e d P a i r
paddq K _ t ( t ) , % x m m 0 # C o m p u t e W [ t ] + K [ t ]
movdqa % x m m 0 , W K _ 2 ( t ) # S t o r e i n t o W K f o r r o u n d s
.elseif t < 1 6
# BSWAP 2 Q W O R D S # C o m p u t e 2 R o u n d s
movdqu M S G ( t ) , % x m m 0
pshufb % x m m 1 , % x m m 0 # B S W A P
SHA5 1 2 _ R o u n d t - 2 # R o u n d t - 2
movdqa % x m m 0 , W _ t ( t ) # S t o r e S c h e d u l e d P a i r
paddq K _ t ( t ) , % x m m 0 # C o m p u t e W [ t ] + K [ t ]
SHA5 1 2 _ R o u n d t - 1 # R o u n d t - 1
movdqa % x m m 0 , W K _ 2 ( t ) # S t o r e W [ t ] + K [ t ] i n t o W K
.elseif t < 7 9
# Schedule 2 Q W O R D S # C o m p u t e 2 R o u n d s
SHA5 1 2 _ 2 S c h e d _ 2 R o u n d _ s s e t
.else
# Compute 2 R o u n d s
SHA5 1 2 _ R o u n d t - 2
SHA5 1 2 _ R o u n d t - 1
.endif
t = t + 2
.endr
# Update d i g e s t
add a _ 6 4 , D I G E S T ( 0 )
add b _ 6 4 , D I G E S T ( 1 )
add c _ 6 4 , D I G E S T ( 2 )
add d _ 6 4 , D I G E S T ( 3 )
add e _ 6 4 , D I G E S T ( 4 )
add f _ 6 4 , D I G E S T ( 5 )
add g _ 6 4 , D I G E S T ( 6 )
add h _ 6 4 , D I G E S T ( 7 )
# Advance t o n e x t m e s s a g e b l o c k
add $ 1 6 * 8 , m s g
dec m s g l e n
jnz u p d a t e b l o c k
# Restore S t a c k P o i n t e r
2021-02-24 19:29:25 +03:00
mov % r b p , % r s p
pop % r b p
# Restore G P R s
pop % r15
pop % r14
pop % r13
pop % r12
pop % r b x
2013-03-27 00:59:37 +04:00
nowork :
2021-12-04 16:43:40 +03:00
RET
2019-10-11 14:51:04 +03:00
SYM_ F U N C _ E N D ( s h a51 2 _ t r a n s f o r m _ s s s e 3 )
2013-03-27 00:59:37 +04:00
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # Binary D a t a
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 00:33:04 +03:00
.section .rodata .cst16 .XMM_QWORD_BSWAP , " aM" , @progbits, 16
2013-03-27 00:59:37 +04:00
.align 16
# Mask f o r b y t e - s w a p p i n g a c o u p l e o f q w o r d s i n a n X M M r e g i s t e r u s i n g ( v ) p s h u f b .
XMM_QWORD_BSWAP :
.octa 0x08090a0b0c0d0e0f0001020304050607
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 00:33:04 +03:00
# Mergeable 6 4 0 - b y t e r o d a t a s e c t i o n . T h i s a l l o w s l i n k e r t o m e r g e t h e t a b l e
# with o t h e r , e x a c t l y t h e s a m e 6 4 0 - b y t e f r a g m e n t o f a n o t h e r r o d a t a s e c t i o n
# ( if s u c h s e c t i o n e x i s t s ) .
.section .rodata .cst640 .K512 , " aM" , @progbits, 640
.align 64
2013-03-27 00:59:37 +04:00
# K[ t ] u s e d i n S H A 5 1 2 h a s h i n g
K512 :
.quad 0 x4 2 8 a2 f98 d72 8 a e 2 2 ,0 x71 3 7 4 4 9 1 2 3 e f65 c d
.quad 0 xb5 c0 f b c f e c4 d3 b2 f ,0 x e 9 b5 d b a58 1 8 9 d b b c
.quad 0 x3 9 5 6 c25 b f34 8 b53 8 ,0 x59 f11 1 f1 b60 5 d01 9
.quad 0 x9 2 3 f82 a4 a f19 4 f9 b ,0 x a b1 c5 e d5 d a6 d81 1 8
.quad 0 xd8 0 7 a a98 a30 3 0 2 4 2 ,0 x12 8 3 5 b01 4 5 7 0 6 f b e
.quad 0 x2 4 3 1 8 5 b e 4 e e 4 b28 c ,0 x55 0 c7 d c3 d5 f f b4 e 2
.quad 0 x7 2 b e 5 d74 f27 b89 6 f ,0 x80 d e b1 f e 3 b16 9 6 b1
.quad 0 x9 b d c06 a72 5 c71 2 3 5 ,0 x c19 b f17 4 c f69 2 6 9 4
.quad 0 xe4 9 b69 c19 e f14 a d2 ,0 x e f b e 4 7 8 6 3 8 4 f25 e 3
.quad 0 x0 f c19 d c68 b8 c d5 b5 ,0 x24 0 c a1 c c77 a c9 c65
.quad 0 x2 d e 9 2 c6 f59 2 b02 7 5 ,0 x4 a74 8 4 a a6 e a6 e 4 8 3
.quad 0 x5 c b0 a9 d c b d41 f b d4 ,0 x76 f98 8 d a83 1 1 5 3 b5
.quad 0 x9 8 3 e 5 1 5 2 e e 6 6 d f a b ,0 x a83 1 c66 d2 d b43 2 1 0
.quad 0 xb0 0 3 2 7 c89 8 f b21 3 f ,0 x b f59 7 f c7 b e e f0 e e 4
.quad 0 xc6 e 0 0 b f33 d a88 f c2 ,0 x d5 a79 1 4 7 9 3 0 a a72 5
.quad 0 x0 6 c a63 5 1 e 0 0 3 8 2 6 f ,0 x14 2 9 2 9 6 7 0 a0 e 6 e 7 0
.quad 0 x2 7 b70 a85 4 6 d22 f f c ,0 x2 e 1 b21 3 8 5 c26 c92 6
.quad 0 x4 d2 c6 d f c5 a c42 a e d ,0 x53 3 8 0 d13 9 d95 b3 d f
.quad 0 x6 5 0 a73 5 4 8 b a f63 d e ,0 x76 6 a0 a b b3 c77 b2 a8
.quad 0 x8 1 c2 c92 e 4 7 e d a e e 6 ,0 x92 7 2 2 c85 1 4 8 2 3 5 3 b
.quad 0 xa2 b f e 8 a14 c f10 3 6 4 ,0 x a81 a66 4 b b c42 3 0 0 1
.quad 0 xc2 4 b8 b70 d0 f89 7 9 1 ,0 x c76 c51 a30 6 5 4 b e 3 0
.quad 0 xd1 9 2 e 8 1 9 d6 e f52 1 8 ,0 x d69 9 0 6 2 4 5 5 6 5 a91 0
.quad 0 xf4 0 e 3 5 8 5 5 7 7 1 2 0 2 a ,0 x10 6 a a07 0 3 2 b b d1 b8
.quad 0 x1 9 a4 c11 6 b8 d2 d0 c8 ,0 x1 e 3 7 6 c08 5 1 4 1 a b53
.quad 0 x2 7 4 8 7 7 4 c d f8 e e b99 ,0 x34 b0 b c b5 e 1 9 b48 a8
.quad 0 x3 9 1 c0 c b3 c5 c95 a63 ,0 x4 e d8 a a4 a e 3 4 1 8 a c b
.quad 0 x5 b9 c c a4 f77 6 3 e 3 7 3 ,0 x68 2 e 6 f f3 d6 b2 b8 a3
.quad 0 x7 4 8 f82 e e 5 d e f b2 f c ,0 x78 a56 3 6 f43 1 7 2 f60
.quad 0 x8 4 c87 8 1 4 a1 f0 a b72 ,0 x8 c c70 2 0 8 1 a64 3 9 e c
.quad 0 x9 0 b e f f f a23 6 3 1 e 2 8 ,0 x a45 0 6 c e b d e 8 2 b d e 9
.quad 0 xbef9 a3 f7 b2 c67 9 1 5 ,0 x c67 1 7 8 f2 e 3 7 2 5 3 2 b
.quad 0 xca2 7 3 e c e e a26 6 1 9 c ,0 x d18 6 b8 c72 1 c0 c20 7
.quad 0 xeada7 d d6 c d e 0 e b1 e ,0 x f57 d4 f7 f e e 6 e d17 8
.quad 0 x0 6 f06 7 a a72 1 7 6 f b a ,0 x0 a63 7 d c5 a2 c89 8 a6
.quad 0 x1 1 3 f98 0 4 b e f90 d a e ,0 x1 b71 0 b35 1 3 1 c47 1 b
.quad 0 x2 8 d b77 f52 3 0 4 7 d84 ,0 x32 c a a b7 b40 c72 4 9 3
.quad 0 x3 c9 e b e 0 a15 c9 b e b c ,0 x43 1 d67 c49 c10 0 d4 c
.quad 0 x4 c c5 d4 b e c b3 e 4 2 b6 ,0 x59 7 f29 9 c f c65 7 e 2 a
.quad 0 x5 f c b6 f a b3 a d6 f a e c ,0 x6 c44 1 9 8 c4 a47 5 8 1 7