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>
*
* 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 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 v e r s i o n 2 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 .
* /
# 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
/ *
* The S H A 1 r o u n d c o n s t a n t s
* /
.align 4
.Lsha1_rcon :
.word 0 x5 a82 7 9 9 9 , 0 x6 e d9 e b a1 , 0 x8 f1 b b c d c , 0 x c a62 c1 d6
/ *
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
* /
ENTRY( s h a1 _ c e _ t r a n s f o r m )
/* load round constants */
adr x6 , . L s h a1 _ r c o n
ld1 r { k 0 . 4 s } , [ x6 ] , #4
ld1 r { k 1 . 4 s } , [ x6 ] , #4
ld1 r { k 2 . 4 s } , [ x6 ] , #4
ld1 r { k 3 . 4 s } , [ x6 ]
/* load state */
2016-10-11 19:15:15 +01:00
ld1 { d g a v . 4 s } , [ x0 ]
2015-04-09 12:55:44 +02:00
ldr d g b , [ x0 , #16 ]
2014-03-06 16:23:33 +08:00
2015-04-09 12:55:44 +02:00
/* load sha1_ce_state::finalize */
ldr w4 , [ x0 , #: l o 12 : s h a1 _ c e _ o f f s e t o f _ f i n a l i z e ]
2014-03-06 16:23:33 +08:00
/* load input */
0 : ld1 { v8 . 4 s - v11 . 4 s } , [ x1 ] , #64
2015-04-09 12:55:44 +02:00
sub w2 , w2 , #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 )
2015-04-09 12:55:44 +02:00
1 : 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
2015-04-09 12:55:44 +02:00
cbnz w2 , 0 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
* /
cbz x4 , 3 f
2015-04-09 12:55:44 +02:00
ldr x4 , [ x0 , #: l o 12 : s h a1 _ c e _ o f f s e t o f _ c o u n t ]
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
2015-04-09 12:55:44 +02:00
b 1 b
2014-03-06 16:23:33 +08:00
/* store new state */
2016-10-11 19:15:15 +01:00
3 : st1 { d g a v . 4 s } , [ x0 ]
2015-04-09 12:55:44 +02:00
str d g b , [ x0 , #16 ]
2014-03-06 16:23:33 +08:00
ret
ENDPROC( s h a1 _ c e _ t r a n s f o r m )