2014-03-20 15:35:40 +01:00
/ *
* sha2 - c e - c o r e . S - c o r e S H A - 2 2 4 / S H A - 2 5 6 t r a n s f o r m u s i n g 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
dga . r e q q20
dgav . r e q v20
dgb . r e q q21
dgbv . r e q v21
t0 . r e q v22
t1 . r e q v23
dg0 q . r e q q24
dg0 v . r e q v24
dg1 q . r e q q25
dg1 v . r e q v25
dg2 q . r e q q26
dg2 v . r e q v26
.macro add_ o n l y , e v , r c , s0
mov d g 2 v . 1 6 b , d g 0 v . 1 6 b
.ifeq \ ev
add t 1 . 4 s , v \ s0 \ ( ) . 4 s , \ r c \ ( ) . 4 s
sha2 5 6 h d g 0 q , d g 1 q , t 0 . 4 s
sha2 5 6 h2 d g 1 q , d g 2 q , t 0 . 4 s
.else
.ifnb \ s0
add t 0 . 4 s , v \ s0 \ ( ) . 4 s , \ r c \ ( ) . 4 s
.endif
sha2 5 6 h d g 0 q , d g 1 q , t 1 . 4 s
sha2 5 6 h2 d g 1 q , d g 2 q , t 1 . 4 s
.endif
.endm
.macro add_ u p d a t e , e v , r c , s0 , s1 , s2 , s3
sha2 5 6 s u 0 v \ s0 \ ( ) . 4 s , v \ s1 \ ( ) . 4 s
add_ o n l y \ e v , \ r c , \ s1
sha2 5 6 s u 1 v \ s0 \ ( ) . 4 s , v \ s2 \ ( ) . 4 s , v \ s3 \ ( ) . 4 s
.endm
/ *
* The S H A - 2 5 6 r o u n d c o n s t a n t s
* /
.align 4
.Lsha2_rcon :
.word 0 x4 2 8 a2 f98 , 0 x71 3 7 4 4 9 1 , 0 x b5 c0 f b c f , 0 x e 9 b5 d b a5
.word 0 x3 9 5 6 c25 b , 0 x59 f11 1 f1 , 0 x92 3 f82 a4 , 0 x a b1 c5 e d5
.word 0 xd8 0 7 a a98 , 0 x12 8 3 5 b01 , 0 x24 3 1 8 5 b e , 0 x55 0 c7 d c3
.word 0 x7 2 b e 5 d74 , 0 x80 d e b1 f e , 0 x9 b d c06 a7 , 0 x c19 b f17 4
.word 0 xe4 9 b69 c1 , 0 x e f b e 4 7 8 6 , 0 x0 f c19 d c6 , 0 x24 0 c a1 c c
.word 0 x2 d e 9 2 c6 f , 0 x4 a74 8 4 a a , 0 x5 c b0 a9 d c , 0 x76 f98 8 d a
.word 0 x9 8 3 e 5 1 5 2 , 0 x a83 1 c66 d , 0 x b00 3 2 7 c8 , 0 x b f59 7 f c7
.word 0 xc6 e 0 0 b f3 , 0 x d5 a79 1 4 7 , 0 x06 c a63 5 1 , 0 x14 2 9 2 9 6 7
.word 0 x2 7 b70 a85 , 0 x2 e 1 b21 3 8 , 0 x4 d2 c6 d f c , 0 x53 3 8 0 d13
.word 0 x6 5 0 a73 5 4 , 0 x76 6 a0 a b b , 0 x81 c2 c92 e , 0 x92 7 2 2 c85
.word 0 xa2 b f e 8 a1 , 0 x a81 a66 4 b , 0 x c24 b8 b70 , 0 x c76 c51 a3
.word 0 xd1 9 2 e 8 1 9 , 0 x d69 9 0 6 2 4 , 0 x f40 e 3 5 8 5 , 0 x10 6 a a07 0
.word 0 x1 9 a4 c11 6 , 0 x1 e 3 7 6 c08 , 0 x27 4 8 7 7 4 c , 0 x34 b0 b c b5
.word 0 x3 9 1 c0 c b3 , 0 x4 e d8 a a4 a , 0 x5 b9 c c a4 f , 0 x68 2 e 6 f f3
.word 0 x7 4 8 f82 e e , 0 x78 a56 3 6 f , 0 x84 c87 8 1 4 , 0 x8 c c70 2 0 8
.word 0 x9 0 b e f f f a , 0 x a45 0 6 c e b , 0 x b e f9 a3 f7 , 0 x c67 1 7 8 f2
/ *
2015-04-09 12:55:45 +02:00
* void s h a2 _ c e _ t r a n s f o r m ( s t r u c t s h a25 6 _ 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-20 15:35:40 +01:00
* /
ENTRY( s h a2 _ c e _ t r a n s f o r m )
/* load round constants */
adr x8 , . L s h a2 _ r c o n
ld1 { v0 . 4 s - v3 . 4 s } , [ x8 ] , #64
ld1 { v4 . 4 s - v7 . 4 s } , [ x8 ] , #64
ld1 { v8 . 4 s - v11 . 4 s } , [ x8 ] , #64
ld1 { v12 . 4 s - v15 . 4 s } , [ x8 ]
/* load state */
2016-10-11 19:15:16 +01:00
ld1 { d g a v . 4 s , d g b v . 4 s } , [ x0 ]
2014-03-20 15:35:40 +01:00
2015-04-09 12:55:45 +02:00
/* load sha256_ce_state::finalize */
ldr w4 , [ x0 , #: l o 12 : s h a25 6 _ c e _ o f f s e t o f _ f i n a l i z e ]
2014-03-20 15:35:40 +01:00
/* load input */
0 : ld1 { v16 . 4 s - v19 . 4 s } , [ x1 ] , #64
2015-04-09 12:55:45 +02:00
sub w2 , w2 , #1
2014-03-20 15:35:40 +01:00
CPU_ L E ( r e v32 v16 . 1 6 b , v16 . 1 6 b )
CPU_ L E ( r e v32 v17 . 1 6 b , v17 . 1 6 b )
CPU_ L E ( r e v32 v18 . 1 6 b , v18 . 1 6 b )
CPU_ L E ( r e v32 v19 . 1 6 b , v19 . 1 6 b )
2015-04-09 12:55:45 +02:00
1 : add t 0 . 4 s , v16 . 4 s , v0 . 4 s
2014-03-20 15:35:40 +01:00
mov d g 0 v . 1 6 b , d g a v . 1 6 b
mov d g 1 v . 1 6 b , d g b v . 1 6 b
add_ u p d a t e 0 , v1 , 1 6 , 1 7 , 1 8 , 1 9
add_ u p d a t e 1 , v2 , 1 7 , 1 8 , 1 9 , 1 6
add_ u p d a t e 0 , v3 , 1 8 , 1 9 , 1 6 , 1 7
add_ u p d a t e 1 , v4 , 1 9 , 1 6 , 1 7 , 1 8
add_ u p d a t e 0 , v5 , 1 6 , 1 7 , 1 8 , 1 9
add_ u p d a t e 1 , v6 , 1 7 , 1 8 , 1 9 , 1 6
add_ u p d a t e 0 , v7 , 1 8 , 1 9 , 1 6 , 1 7
add_ u p d a t e 1 , v8 , 1 9 , 1 6 , 1 7 , 1 8
add_ u p d a t e 0 , v9 , 1 6 , 1 7 , 1 8 , 1 9
add_ u p d a t e 1 , v10 , 1 7 , 1 8 , 1 9 , 1 6
add_ u p d a t e 0 , v11 , 1 8 , 1 9 , 1 6 , 1 7
add_ u p d a t e 1 , v12 , 1 9 , 1 6 , 1 7 , 1 8
add_ o n l y 0 , v13 , 1 7
add_ o n l y 1 , v14 , 1 8
add_ o n l y 0 , v15 , 1 9
add_ o n l y 1
/* update state */
add d g a v . 4 s , d g a v . 4 s , d g 0 v . 4 s
add d g b v . 4 s , d g b v . 4 s , d g 1 v . 4 s
/* handled all input blocks? */
2015-04-09 12:55:45 +02:00
cbnz w2 , 0 b
2014-03-20 15:35:40 +01: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:45 +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-20 15:35:40 +01:00
* /
cbz x4 , 3 f
2015-04-09 12:55:45 +02:00
ldr x4 , [ x0 , #: l o 12 : s h a25 6 _ c e _ o f f s e t o f _ c o u n t ]
2014-03-20 15:35:40 +01:00
movi v17 . 2 d , #0
mov x8 , #0x80000000
movi v18 . 2 d , #0
ror x7 , x4 , #29 / / r o r ( l s l ( x4 , 3 ) , 3 2 )
fmov d16 , x8
mov x4 , #0
mov v19 . d [ 0 ] , x z r
mov v19 . d [ 1 ] , x7
2015-04-09 12:55:45 +02:00
b 1 b
2014-03-20 15:35:40 +01:00
/* store new state */
2016-10-11 19:15:16 +01:00
3 : st1 { d g a v . 4 s , d g b v . 4 s } , [ x0 ]
2014-03-20 15:35:40 +01:00
ret
ENDPROC( s h a2 _ c e _ t r a n s f o r m )