2019-06-04 10:11:33 +02:00
/* SPDX-License-Identifier: GPL-2.0-only */
2014-03-06 16:23:33 +08:00
/ *
* sha1 - c e - c o r e . S - S H A - 1 s e c u r e h a s h u s i n g A R M v8 C r y p t o E x t e n s i o n s
*
* Copyright ( C ) 2 0 1 4 L i n a r o L t d < a r d . b i e s h e u v e l @linaro.org>
* /
# include < l i n u x / l i n k a g e . h >
# include < a s m / a s s e m b l e r . h >
.text
.arch armv8 - a + c r y p t o
k0 . r e q v0
k1 . r e q v1
k2 . r e q v2
k3 . r e q v3
t0 . r e q v4
t1 . r e q v5
dga . r e q q6
dgav . r e q v6
dgb . r e q s7
dgbv . r e q v7
dg0 q . r e q q12
dg0 s . r e q s12
dg0 v . r e q v12
dg1 s . r e q s13
dg1 v . r e q v13
dg2 s . r e q s14
.macro add_ o n l y , o p , e v , r c , s0 , d g 1
.ifc \ ev, e v
add t 1 . 4 s , v \ s0 \ ( ) . 4 s , \ r c \ ( ) . 4 s
sha1 h d g 2 s , d g 0 s
.ifnb \ dg1
sha1 \ o p d g 0 q , \ d g 1 , t 0 . 4 s
.else
sha1 \ o p d g 0 q , d g 1 s , t 0 . 4 s
.endif
.else
.ifnb \ s0
add t 0 . 4 s , v \ s0 \ ( ) . 4 s , \ r c \ ( ) . 4 s
.endif
sha1 h d g 1 s , d g 0 s
sha1 \ o p d g 0 q , d g 2 s , t 1 . 4 s
.endif
.endm
.macro add_ u p d a t e , o p , e v , r c , s0 , s1 , s2 , s3 , d g 1
sha1 s u 0 v \ s0 \ ( ) . 4 s , v \ s1 \ ( ) . 4 s , v \ s2 \ ( ) . 4 s
add_ o n l y \ o p , \ e v , \ r c , \ s1 , \ d g 1
sha1 s u 1 v \ s0 \ ( ) . 4 s , v \ s3 \ ( ) . 4 s
.endm
2018-01-10 12:11:42 +00:00
.macro loadrc, k , v a l , t m p
movz \ t m p , : a b s _ g 0 _ n c : \ v a l
movk \ t m p , : a b s _ g 1 : \ v a l
dup \ k , \ t m p
.endm
2014-03-06 16:23:33 +08:00
/ *
2015-04-09 12:55:44 +02:00
* void s h a1 _ c e _ t r a n s f o r m ( s t r u c t s h a1 _ c e _ s t a t e * s s t , u 8 c o n s t * s r c ,
* int b l o c k s )
2014-03-06 16:23:33 +08:00
* /
2019-12-13 15:49:10 +00:00
SYM_ F U N C _ S T A R T ( s h a1 _ c e _ t r a n s f o r m )
2018-04-30 18:18:21 +02:00
frame_ p u s h 3
mov x19 , x0
mov x20 , x1
mov x21 , x2
2014-03-06 16:23:33 +08:00
/* load round constants */
2018-04-30 18:18:21 +02:00
0 : loadrc k 0 . 4 s , 0 x5 a82 7 9 9 9 , w6
2018-01-10 12:11:42 +00:00
loadrc k 1 . 4 s , 0 x6 e d9 e b a1 , w6
loadrc k 2 . 4 s , 0 x8 f1 b b c d c , w6
loadrc k 3 . 4 s , 0 x c a62 c1 d6 , w6
2014-03-06 16:23:33 +08:00
/* load state */
2018-04-30 18:18:21 +02:00
ld1 { d g a v . 4 s } , [ x19 ]
ldr d g b , [ x19 , #16 ]
2014-03-06 16:23:33 +08:00
2015-04-09 12:55:44 +02:00
/* load sha1_ce_state::finalize */
2017-04-26 17:11:32 +01:00
ldr_ l w4 , s h a1 _ c e _ o f f s e t o f _ f i n a l i z e , x4
2018-04-30 18:18:21 +02:00
ldr w4 , [ x19 , x4 ]
2014-03-06 16:23:33 +08:00
/* load input */
2018-04-30 18:18:21 +02:00
1 : ld1 { v8 . 4 s - v11 . 4 s } , [ x20 ] , #64
sub w21 , w21 , #1
2014-03-06 16:23:33 +08:00
CPU_ L E ( r e v32 v8 . 1 6 b , v8 . 1 6 b )
CPU_ L E ( r e v32 v9 . 1 6 b , v9 . 1 6 b )
CPU_ L E ( r e v32 v10 . 1 6 b , v10 . 1 6 b )
CPU_ L E ( r e v32 v11 . 1 6 b , v11 . 1 6 b )
2018-04-30 18:18:21 +02:00
2 : add t 0 . 4 s , v8 . 4 s , k 0 . 4 s
2014-03-06 16:23:33 +08:00
mov d g 0 v . 1 6 b , d g a v . 1 6 b
add_ u p d a t e c , e v , k 0 , 8 , 9 , 1 0 , 1 1 , d g b
add_ u p d a t e c , o d , k 0 , 9 , 1 0 , 1 1 , 8
add_ u p d a t e c , e v , k 0 , 1 0 , 1 1 , 8 , 9
add_ u p d a t e c , o d , k 0 , 1 1 , 8 , 9 , 1 0
add_ u p d a t e c , e v , k 1 , 8 , 9 , 1 0 , 1 1
add_ u p d a t e p , o d , k 1 , 9 , 1 0 , 1 1 , 8
add_ u p d a t e p , e v , k 1 , 1 0 , 1 1 , 8 , 9
add_ u p d a t e p , o d , k 1 , 1 1 , 8 , 9 , 1 0
add_ u p d a t e p , e v , k 1 , 8 , 9 , 1 0 , 1 1
add_ u p d a t e p , o d , k 2 , 9 , 1 0 , 1 1 , 8
add_ u p d a t e m , e v , k 2 , 1 0 , 1 1 , 8 , 9
add_ u p d a t e m , o d , k 2 , 1 1 , 8 , 9 , 1 0
add_ u p d a t e m , e v , k 2 , 8 , 9 , 1 0 , 1 1
add_ u p d a t e m , o d , k 2 , 9 , 1 0 , 1 1 , 8
add_ u p d a t e m , e v , k 3 , 1 0 , 1 1 , 8 , 9
add_ u p d a t e p , o d , k 3 , 1 1 , 8 , 9 , 1 0
add_ o n l y p , e v , k 3 , 9
add_ o n l y p , o d , k 3 , 1 0
add_ o n l y p , e v , k 3 , 1 1
add_ o n l y p , o d
/* update state */
add d g b v . 2 s , d g b v . 2 s , d g 1 v . 2 s
add d g a v . 4 s , d g a v . 4 s , d g 0 v . 4 s
2018-04-30 18:18:21 +02:00
cbz w21 , 3 f
if_ w i l l _ c o n d _ y i e l d _ n e o n
st1 { d g a v . 4 s } , [ x19 ]
str d g b , [ x19 , #16 ]
do_ c o n d _ y i e l d _ n e o n
b 0 b
endif_ y i e l d _ n e o n
b 1 b
2014-03-06 16:23:33 +08:00
/ *
* Final b l o c k : a d d p a d d i n g a n d t o t a l b i t c o u n t .
2015-04-09 12:55:44 +02:00
* Skip i f t h e i n p u t s i z e w a s n o t a r o u n d m u l t i p l e o f t h e b l o c k s i z e ,
* the p a d d i n g i s h a n d l e d b y t h e C c o d e i n t h a t c a s e .
2014-03-06 16:23:33 +08:00
* /
2018-04-30 18:18:21 +02:00
3 : cbz x4 , 4 f
2017-04-26 17:11:32 +01:00
ldr_ l w4 , s h a1 _ c e _ o f f s e t o f _ c o u n t , x4
2018-04-30 18:18:21 +02:00
ldr x4 , [ x19 , x4 ]
2014-03-06 16:23:33 +08:00
movi v9 . 2 d , #0
mov x8 , #0x80000000
movi v10 . 2 d , #0
ror x7 , x4 , #29 / / r o r ( l s l ( x4 , 3 ) , 3 2 )
fmov d8 , x8
mov x4 , #0
mov v11 . d [ 0 ] , x z r
mov v11 . d [ 1 ] , x7
2018-04-30 18:18:21 +02:00
b 2 b
2014-03-06 16:23:33 +08:00
/* store new state */
2018-04-30 18:18:21 +02:00
4 : st1 { d g a v . 4 s } , [ x19 ]
str d g b , [ x19 , #16 ]
frame_ p o p
2014-03-06 16:23:33 +08:00
ret
2019-12-13 15:49:10 +00:00
SYM_ F U N C _ E N D ( s h a1 _ c e _ t r a n s f o r m )