2018-11-16 17:26:30 -08:00
/* SPDX-License-Identifier: GPL-2.0 */
/ *
* NH - ε - a l m o s t - u n i v e r s a l h a s h f u n c t i o n , N E O N a c c e l e r a t e d v e r s i o n
*
* Copyright 2 0 1 8 G o o g l e L L C
*
* Author : Eric B i g g e r s < e b i g g e r s @google.com>
* /
# include < l i n u x / l i n k a g e . h >
.text
.fpu neon
KEY . r e q r0
MESSAGE . r e q r1
MESSAGE_ L E N . r e q r2
HASH . r e q r3
PASS0 _ S U M S . r e q q0
PASS0 _ S U M _ A . r e q d0
PASS0 _ S U M _ B . r e q d1
PASS1 _ S U M S . r e q q1
PASS1 _ S U M _ A . r e q d2
PASS1 _ S U M _ B . r e q d3
PASS2 _ S U M S . r e q q2
PASS2 _ S U M _ A . r e q d4
PASS2 _ S U M _ B . r e q d5
PASS3 _ S U M S . r e q q3
PASS3 _ S U M _ A . r e q d6
PASS3 _ S U M _ B . r e q d7
K0 . r e q q4
K1 . r e q q5
K2 . r e q q6
K3 . r e q q7
T0 . r e q q8
T0 _ L . r e q d16
T0 _ H . r e q d17
T1 . r e q q9
T1 _ L . r e q d18
T1 _ H . r e q d19
T2 . r e q q10
T2 _ L . r e q d20
T2 _ H . r e q d21
T3 . r e q q11
T3 _ L . r e q d22
T3 _ H . r e q d23
.macro _nh_stride k0 , k 1 , k 2 , k 3
/ / Load n e x t m e s s a g e s t r i d e
vld1 . 8 { T 3 } , [ M E S S A G E ] !
/ / Load n e x t k e y s t r i d e
vld1 . 3 2 { \ k 3 } , [ K E Y ] !
/ / Add m e s s a g e w o r d s t o k e y w o r d s
vadd. u 3 2 T 0 , T 3 , \ k 0
vadd. u 3 2 T 1 , T 3 , \ k 1
vadd. u 3 2 T 2 , T 3 , \ k 2
vadd. u 3 2 T 3 , T 3 , \ k 3
/ / Multiply 3 2 x32 = > 6 4 a n d a c c u m u l a t e
vmlal. u 3 2 P A S S 0 _ S U M S , T 0 _ L , T 0 _ H
vmlal. u 3 2 P A S S 1 _ S U M S , T 1 _ L , T 1 _ H
vmlal. u 3 2 P A S S 2 _ S U M S , T 2 _ L , T 2 _ H
vmlal. u 3 2 P A S S 3 _ S U M S , T 3 _ L , T 3 _ H
.endm
/ *
* void n h _ n e o n ( c o n s t u 3 2 * k e y , c o n s t u 8 * m e s s a g e , s i z e _ t m e s s a g e _ l e n ,
2022-11-18 11:44:20 -08:00
* _ _ le6 4 h a s h [ N H _ N U M _ P A S S E S ] )
2018-11-16 17:26:30 -08:00
*
* It' s g u a r a n t e e d t h a t m e s s a g e _ l e n % 1 6 = = 0 .
* /
ENTRY( n h _ n e o n )
vld1 . 3 2 { K 0 ,K 1 } , [ K E Y ] !
vmov. u 6 4 P A S S 0 _ S U M S , #0
vmov. u 6 4 P A S S 1 _ S U M S , #0
vld1 . 3 2 { K 2 } , [ K E Y ] !
vmov. u 6 4 P A S S 2 _ S U M S , #0
vmov. u 6 4 P A S S 3 _ S U M S , #0
subs M E S S A G E _ L E N , M E S S A G E _ L E N , #64
blt . L l o o p4 _ d o n e
.Lloop4 :
_ nh_ s t r i d e K 0 , K 1 , K 2 , K 3
_ nh_ s t r i d e K 1 , K 2 , K 3 , K 0
_ nh_ s t r i d e K 2 , K 3 , K 0 , K 1
_ nh_ s t r i d e K 3 , K 0 , K 1 , K 2
subs M E S S A G E _ L E N , M E S S A G E _ L E N , #64
bge . L l o o p4
.Lloop4_done :
ands M E S S A G E _ L E N , M E S S A G E _ L E N , #63
beq . L d o n e
_ nh_ s t r i d e K 0 , K 1 , K 2 , K 3
subs M E S S A G E _ L E N , M E S S A G E _ L E N , #16
beq . L d o n e
_ nh_ s t r i d e K 1 , K 2 , K 3 , K 0
subs M E S S A G E _ L E N , M E S S A G E _ L E N , #16
beq . L d o n e
_ nh_ s t r i d e K 2 , K 3 , K 0 , K 1
.Ldone :
/ / Sum t h e a c c u m u l a t o r s f o r e a c h p a s s , t h e n s t o r e t h e s u m s t o ' h a s h '
vadd. u 6 4 T 0 _ L , P A S S 0 _ S U M _ A , P A S S 0 _ S U M _ B
vadd. u 6 4 T 0 _ H , P A S S 1 _ S U M _ A , P A S S 1 _ S U M _ B
vadd. u 6 4 T 1 _ L , P A S S 2 _ S U M _ A , P A S S 2 _ S U M _ B
vadd. u 6 4 T 1 _ H , P A S S 3 _ S U M _ A , P A S S 3 _ S U M _ B
vst1 . 8 { T 0 - T 1 } , [ H A S H ]
bx l r
ENDPROC( n h _ n e o n )