2019-06-04 11:11:33 +03:00
/* SPDX-License-Identifier: GPL-2.0-only */
2018-01-19 15:04:39 +03:00
/ *
* sm3 - c e - c o r e . S - S M 3 s e c u r e h a s h u s i n g A R M v8 . 2 C r y p t o E x t e n s i o n s
*
* Copyright ( C ) 2 0 1 8 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 >
.irp b, 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 1 0 , 1 1 , 1 2
.set .Lv \ b\ ( ) . 4 s , \ b
.endr
.macro sm3 p a r t w1 , r d , r n , r m
.inst 0xce60c000 | .L \ rd | ( . L \ r n < < 5 ) | ( . L \ r m < < 1 6 )
.endm
.macro sm3 p a r t w2 , r d , r n , r m
.inst 0xce60c400 | .L \ rd | ( . L \ r n < < 5 ) | ( . L \ r m < < 1 6 )
.endm
.macro sm3 s s1 , r d , r n , r m , r a
.inst 0xce400000 | .L \ rd | ( . L \ r n < < 5 ) | ( . L \ r a < < 1 0 ) | ( . L \ r m < < 1 6 )
.endm
.macro sm3 t t 1 a , r d , r n , r m , i m m 2
.inst 0xce408000 | .L \ rd | ( . L \ r n < < 5 ) | ( ( \ i m m 2 ) < < 1 2 ) | ( . L \ r m < < 1 6 )
.endm
.macro sm3 t t 1 b , r d , r n , r m , i m m 2
.inst 0xce408400 | .L \ rd | ( . L \ r n < < 5 ) | ( ( \ i m m 2 ) < < 1 2 ) | ( . L \ r m < < 1 6 )
.endm
.macro sm3 t t 2 a , r d , r n , r m , i m m 2
.inst 0xce408800 | .L \ rd | ( . L \ r n < < 5 ) | ( ( \ i m m 2 ) < < 1 2 ) | ( . L \ r m < < 1 6 )
.endm
.macro sm3 t t 2 b , r d , r n , r m , i m m 2
.inst 0xce408c00 | .L \ rd | ( . L \ r n < < 5 ) | ( ( \ i m m 2 ) < < 1 2 ) | ( . L \ r m < < 1 6 )
.endm
.macro round, a b , s0 , t 0 , t 1 , i
sm3 s s1 v5 . 4 s , v8 . 4 s , \ t 0 \ ( ) . 4 s , v9 . 4 s
shl \ t 1 \ ( ) . 4 s , \ t 0 \ ( ) . 4 s , #1
sri \ t 1 \ ( ) . 4 s , \ t 0 \ ( ) . 4 s , #31
sm3 t t 1 \ a b v8 . 4 s , v5 . 4 s , v10 . 4 s , \ i
sm3 t t 2 \ a b v9 . 4 s , v5 . 4 s , \ s0 \ ( ) . 4 s , \ i
.endm
.macro qround, a b , s0 , s1 , s2 , s3 , s4
.ifnb \ s4
ext \ s4 \ ( ) . 1 6 b , \ s1 \ ( ) . 1 6 b , \ s2 \ ( ) . 1 6 b , #12
ext v6 . 1 6 b , \ s0 \ ( ) . 1 6 b , \ s1 \ ( ) . 1 6 b , #12
ext v7 . 1 6 b , \ s2 \ ( ) . 1 6 b , \ s3 \ ( ) . 1 6 b , #8
sm3 p a r t w1 \ s4 \ ( ) . 4 s , \ s0 \ ( ) . 4 s , \ s3 \ ( ) . 4 s
.endif
eor v10 . 1 6 b , \ s0 \ ( ) . 1 6 b , \ s1 \ ( ) . 1 6 b
round \ a b , \ s0 , v11 , v12 , 0
round \ a b , \ s0 , v12 , v11 , 1
round \ a b , \ s0 , v11 , v12 , 2
round \ a b , \ s0 , v12 , v11 , 3
.ifnb \ s4
sm3 p a r t w2 \ s4 \ ( ) . 4 s , v7 . 4 s , v6 . 4 s
.endif
.endm
/ *
* void s m 3 _ c e _ t r a n s f o r m ( s t r u c t s m 3 _ 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 )
* /
.text
2019-12-13 18:49:10 +03:00
SYM_ F U N C _ S T A R T ( s m 3 _ c e _ t r a n s f o r m )
2018-01-19 15:04:39 +03:00
/* load state */
ld1 { v8 . 4 s - v9 . 4 s } , [ x0 ]
rev6 4 v8 . 4 s , v8 . 4 s
rev6 4 v9 . 4 s , v9 . 4 s
ext v8 . 1 6 b , v8 . 1 6 b , v8 . 1 6 b , #8
ext v9 . 1 6 b , v9 . 1 6 b , v9 . 1 6 b , #8
adr_ l x8 , . L t
ldp s13 , s14 , [ x8 ]
/* load input */
0 : ld1 { v0 . 1 6 b - v3 . 1 6 b } , [ x1 ] , #64
sub w2 , w2 , #1
mov v15 . 1 6 b , v8 . 1 6 b
mov v16 . 1 6 b , v9 . 1 6 b
CPU_ L E ( r e v32 v0 . 1 6 b , v0 . 1 6 b )
CPU_ L E ( r e v32 v1 . 1 6 b , v1 . 1 6 b )
CPU_ L E ( r e v32 v2 . 1 6 b , v2 . 1 6 b )
CPU_ L E ( r e v32 v3 . 1 6 b , v3 . 1 6 b )
ext v11 . 1 6 b , v13 . 1 6 b , v13 . 1 6 b , #4
qround a , v0 , v1 , v2 , v3 , v4
qround a , v1 , v2 , v3 , v4 , v0
qround a , v2 , v3 , v4 , v0 , v1
qround a , v3 , v4 , v0 , v1 , v2
ext v11 . 1 6 b , v14 . 1 6 b , v14 . 1 6 b , #4
qround b , v4 , v0 , v1 , v2 , v3
qround b , v0 , v1 , v2 , v3 , v4
qround b , v1 , v2 , v3 , v4 , v0
qround b , v2 , v3 , v4 , v0 , v1
qround b , v3 , v4 , v0 , v1 , v2
qround b , v4 , v0 , v1 , v2 , v3
qround b , v0 , v1 , v2 , v3 , v4
qround b , v1 , v2 , v3 , v4 , v0
qround b , v2 , v3 , v4 , v0 , v1
qround b , v3 , v4
qround b , v4 , v0
qround b , v0 , v1
eor v8 . 1 6 b , v8 . 1 6 b , v15 . 1 6 b
eor v9 . 1 6 b , v9 . 1 6 b , v16 . 1 6 b
/* handled all input blocks? */
cbnz w2 , 0 b
/* save state */
rev6 4 v8 . 4 s , v8 . 4 s
rev6 4 v9 . 4 s , v9 . 4 s
ext v8 . 1 6 b , v8 . 1 6 b , v8 . 1 6 b , #8
ext v9 . 1 6 b , v9 . 1 6 b , v9 . 1 6 b , #8
st1 { v8 . 4 s - v9 . 4 s } , [ x0 ]
ret
2019-12-13 18:49:10 +03:00
SYM_ F U N C _ E N D ( s m 3 _ c e _ t r a n s f o r m )
2018-01-19 15:04:39 +03:00
.section " .rodata " , " a"
.align 3
.Lt : .word 0 x7 9 c c45 1 9 , 0 x9 d8 a7 a87