2014-03-26 20:53:05 +01:00
/ *
* Accelerated G H A S H i m p l e m e n t a t i o n w i t h A R M v8 P M U L L i n s t r u c t 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
* under 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 p u b l i s h e d
* by 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 >
2014-06-16 11:02:16 +01:00
SHASH . r e q v0
SHASH2 . r e q v1
2014-03-26 20:53:05 +01:00
T1 . r e q v2
T2 . r e q v3
2014-06-16 11:02:16 +01:00
MASK . r e q v4
XL . r e q v5
XM . r e q v6
XH . r e q v7
IN1 . r e q v7
2014-03-26 20:53:05 +01:00
.text
.arch armv8 - a + c r y p t o
/ *
* void p m u l l _ g h a s h _ u p d a t e ( i n t b l o c k s , u 6 4 d g [ ] , c o n s t c h a r * s r c ,
* struct g h a s h _ k e y c o n s t * k , c o n s t c h a r * h e a d )
* /
ENTRY( p m u l l _ g h a s h _ u p d a t e )
2016-10-11 19:15:14 +01:00
ld1 { S H A S H . 2 d } , [ x3 ]
ld1 { X L . 2 d } , [ x1 ]
2014-06-16 11:02:16 +01:00
movi M A S K . 1 6 b , #0xe1
ext S H A S H 2 . 1 6 b , S H A S H . 1 6 b , S H A S H . 1 6 b , #8
shl M A S K . 2 d , M A S K . 2 d , #57
eor S H A S H 2 . 1 6 b , S H A S H 2 . 1 6 b , S H A S H . 1 6 b
2014-03-26 20:53:05 +01:00
/* do the head block first, if supplied */
cbz x4 , 0 f
2014-06-16 11:02:16 +01:00
ld1 { T 1 . 2 d } , [ x4 ]
2014-03-26 20:53:05 +01:00
b 1 f
2014-06-16 11:02:16 +01:00
0 : ld1 { T 1 . 2 d } , [ x2 ] , #16
2014-03-26 20:53:05 +01:00
sub w0 , w0 , #1
2014-06-16 11:02:16 +01:00
1 : /* multiply XL by SHASH in GF(2^128) */
CPU_ L E ( r e v64 T 1 . 1 6 b , T 1 . 1 6 b )
2014-03-26 20:53:05 +01:00
2014-06-16 11:02:16 +01:00
ext T 2 . 1 6 b , X L . 1 6 b , X L . 1 6 b , #8
ext I N 1 . 1 6 b , T 1 . 1 6 b , T 1 . 1 6 b , #8
eor T 1 . 1 6 b , T 1 . 1 6 b , T 2 . 1 6 b
eor X L . 1 6 b , X L . 1 6 b , I N 1 . 1 6 b
2014-03-26 20:53:05 +01:00
2014-06-16 11:02:16 +01:00
pmull2 X H . 1 q , S H A S H . 2 d , X L . 2 d / / a1 * b1
eor T 1 . 1 6 b , T 1 . 1 6 b , X L . 1 6 b
pmull X L . 1 q , S H A S H . 1 d , X L . 1 d / / a0 * b0
pmull X M . 1 q , S H A S H 2 . 1 d , T 1 . 1 d / / ( a1 + a0 ) ( b1 + b0 )
2014-03-26 20:53:05 +01:00
2014-06-16 11:02:16 +01:00
ext T 1 . 1 6 b , X L . 1 6 b , X H . 1 6 b , #8
eor T 2 . 1 6 b , X L . 1 6 b , X H . 1 6 b
eor X M . 1 6 b , X M . 1 6 b , T 1 . 1 6 b
eor X M . 1 6 b , X M . 1 6 b , T 2 . 1 6 b
pmull T 2 . 1 q , X L . 1 d , M A S K . 1 d
2014-03-26 20:53:05 +01:00
2014-06-16 11:02:16 +01:00
mov X H . d [ 0 ] , X M . d [ 1 ]
mov X M . d [ 1 ] , X L . d [ 0 ]
eor X L . 1 6 b , X M . 1 6 b , T 2 . 1 6 b
ext T 2 . 1 6 b , X L . 1 6 b , X L . 1 6 b , #8
pmull X L . 1 q , X L . 1 d , M A S K . 1 d
eor T 2 . 1 6 b , T 2 . 1 6 b , X H . 1 6 b
eor X L . 1 6 b , X L . 1 6 b , T 2 . 1 6 b
2014-03-26 20:53:05 +01:00
cbnz w0 , 0 b
2016-10-11 19:15:14 +01:00
st1 { X L . 2 d } , [ x1 ]
2014-03-26 20:53:05 +01:00
ret
ENDPROC( p m u l l _ g h a s h _ u p d a t e )