2018-12-04 06:52:49 +03: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 , A R M 6 4 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 >
KEY . r e q x0
MESSAGE . r e q x1
MESSAGE_ L E N . r e q x2
HASH . r e q x3
PASS0 _ S U M S . r e q v0
PASS1 _ S U M S . r e q v1
PASS2 _ S U M S . r e q v2
PASS3 _ S U M S . r e q v3
K0 . r e q v4
K1 . r e q v5
K2 . r e q v6
K3 . r e q v7
T0 . r e q v8
T1 . r e q v9
T2 . r e q v10
T3 . r e q v11
T4 . r e q v12
T5 . r e q v13
T6 . r e q v14
T7 . r e q v15
.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
ld1 { T 3 . 1 6 b } , [ M E S S A G E ] , #16
/ / Load n e x t k e y s t r i d e
ld1 { \ k 3 \ ( ) . 4 s } , [ K E Y ] , #16
/ / Add m e s s a g e w o r d s t o k e y w o r d s
add T 0 . 4 s , T 3 . 4 s , \ k 0 \ ( ) . 4 s
add T 1 . 4 s , T 3 . 4 s , \ k 1 \ ( ) . 4 s
add T 2 . 4 s , T 3 . 4 s , \ k 2 \ ( ) . 4 s
add T 3 . 4 s , T 3 . 4 s , \ k 3 \ ( ) . 4 s
/ / Multiply 3 2 x32 = > 6 4 a n d a c c u m u l a t e
mov T 4 . d [ 0 ] , T 0 . d [ 1 ]
mov T 5 . d [ 0 ] , T 1 . d [ 1 ]
mov T 6 . d [ 0 ] , T 2 . d [ 1 ]
mov T 7 . d [ 0 ] , T 3 . d [ 1 ]
umlal P A S S 0 _ S U M S . 2 d , T 0 . 2 s , T 4 . 2 s
umlal P A S S 1 _ S U M S . 2 d , T 1 . 2 s , T 5 . 2 s
umlal P A S S 2 _ S U M S . 2 d , T 2 . 2 s , T 6 . 2 s
umlal P A S S 3 _ S U M S . 2 d , T 3 . 2 s , T 7 . 2 s
.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 ,
* u8 h a s h [ N H _ H A S H _ B Y T E S ] )
*
* 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 .
* /
2019-12-13 18:49:10 +03:00
SYM_ F U N C _ S T A R T ( n h _ n e o n )
2018-12-04 06:52:49 +03:00
ld1 { K 0 . 4 s ,K 1 . 4 s } , [ K E Y ] , #32
movi P A S S 0 _ S U M S . 2 d , #0
movi P A S S 1 _ S U M S . 2 d , #0
ld1 { K 2 . 4 s } , [ K E Y ] , #16
movi P A S S 2 _ S U M S . 2 d , #0
movi P A S S 3 _ S U M S . 2 d , #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 '
addp T 0 . 2 d , P A S S 0 _ S U M S . 2 d , P A S S 1 _ S U M S . 2 d
addp T 1 . 2 d , P A S S 2 _ S U M S . 2 d , P A S S 3 _ S U M S . 2 d
st1 { T 0 . 1 6 b ,T 1 . 1 6 b } , [ H A S H ]
ret
2019-12-13 18:49:10 +03:00
SYM_ F U N C _ E N D ( n h _ n e o n )