2012-09-14 03:00:49 +04:00
/ *
* SHA- 1 i m p l e m e n t a t i o n f o r P o w e r P C .
*
* Copyright ( C ) 2 0 0 5 P a u l M a c k e r r a s < p a u l u s @samba.org>
* /
# include < a s m / p p c _ a s m . h >
# include < a s m / a s m - o f f s e t s . h >
2016-09-23 22:31:56 +03:00
# ifdef _ _ B I G _ E N D I A N _ _
# define L W Z ( r t , d , r a ) \
lwz r t ,d ( r a )
# else
# define L W Z ( r t , d , r a ) \
li r t ,d ; \
lwbrx r t ,r t ,r a
# endif
2012-09-14 03:00:49 +04:00
/ *
* We r o l l t h e r e g i s t e r s f o r T , A , B , C , D , E a r o u n d o n e a c h
* iteration; T on iteration t is A on iteration t+1, and so on.
* We u s e r e g i s t e r s 7 - 1 2 f o r t h i s .
* /
# define R T ( t ) ( ( ( ( t ) + 5 ) % 6 ) + 7 )
# define R A ( t ) ( ( ( ( t ) + 4 ) % 6 ) + 7 )
# define R B ( t ) ( ( ( ( t ) + 3 ) % 6 ) + 7 )
# define R C ( t ) ( ( ( ( t ) + 2 ) % 6 ) + 7 )
# define R D ( t ) ( ( ( ( t ) + 1 ) % 6 ) + 7 )
# define R E ( t ) ( ( ( ( t ) + 0 ) % 6 ) + 7 )
/* We use registers 16 - 31 for the W values */
# define W ( t ) ( ( ( t ) % 1 6 ) + 1 6 )
# define L O A D W ( t ) \
2016-09-23 22:31:56 +03:00
LWZ( W ( t ) ,( t ) * 4 ,r4 )
2012-09-14 03:00:49 +04:00
# define S T E P D 0 _ L O A D ( t ) \
andc r0 ,R D ( t ) ,R B ( t ) ; \
and r6 ,R B ( t ) ,R C ( t ) ; \
rotlwi R T ( t ) ,R A ( t ) ,5 ; \
or r6 ,r6 ,r0 ; \
add r0 ,R E ( t ) ,r15 ; \
add R T ( t ) ,R T ( t ) ,r6 ; \
add r14 ,r0 ,W ( t ) ; \
2016-09-23 22:31:56 +03:00
LWZ( W ( ( t ) + 4 ) ,( ( t ) + 4 ) * 4 ,r4 ) ; \
2012-09-14 03:00:49 +04:00
rotlwi R B ( t ) ,R B ( t ) ,3 0 ; \
add R T ( t ) ,R T ( t ) ,r14
# define S T E P D 0 _ U P D A T E ( t ) \
and r6 ,R B ( t ) ,R C ( t ) ; \
andc r0 ,R D ( t ) ,R B ( t ) ; \
rotlwi R T ( t ) ,R A ( t ) ,5 ; \
rotlwi R B ( t ) ,R B ( t ) ,3 0 ; \
or r6 ,r6 ,r0 ; \
add r0 ,R E ( t ) ,r15 ; \
xor r5 ,W ( ( t ) + 4 - 3 ) ,W ( ( t ) + 4 - 8 ) ; \
add R T ( t ) ,R T ( t ) ,r6 ; \
xor W ( ( t ) + 4 ) ,W ( ( t ) + 4 - 1 6 ) ,W ( ( t ) + 4 - 1 4 ) ; \
add r0 ,r0 ,W ( t ) ; \
xor W ( ( t ) + 4 ) ,W ( ( t ) + 4 ) ,r5 ; \
add R T ( t ) ,R T ( t ) ,r0 ; \
rotlwi W ( ( t ) + 4 ) ,W ( ( t ) + 4 ) ,1
# define S T E P D 1 ( t ) \
xor r6 ,R B ( t ) ,R C ( t ) ; \
rotlwi R T ( t ) ,R A ( t ) ,5 ; \
rotlwi R B ( t ) ,R B ( t ) ,3 0 ; \
xor r6 ,r6 ,R D ( t ) ; \
add r0 ,R E ( t ) ,r15 ; \
add R T ( t ) ,R T ( t ) ,r6 ; \
add r0 ,r0 ,W ( t ) ; \
add R T ( t ) ,R T ( t ) ,r0
# define S T E P D 1 _ U P D A T E ( t ) \
xor r6 ,R B ( t ) ,R C ( t ) ; \
rotlwi R T ( t ) ,R A ( t ) ,5 ; \
rotlwi R B ( t ) ,R B ( t ) ,3 0 ; \
xor r6 ,r6 ,R D ( t ) ; \
add r0 ,R E ( t ) ,r15 ; \
xor r5 ,W ( ( t ) + 4 - 3 ) ,W ( ( t ) + 4 - 8 ) ; \
add R T ( t ) ,R T ( t ) ,r6 ; \
xor W ( ( t ) + 4 ) ,W ( ( t ) + 4 - 1 6 ) ,W ( ( t ) + 4 - 1 4 ) ; \
add r0 ,r0 ,W ( t ) ; \
xor W ( ( t ) + 4 ) ,W ( ( t ) + 4 ) ,r5 ; \
add R T ( t ) ,R T ( t ) ,r0 ; \
rotlwi W ( ( t ) + 4 ) ,W ( ( t ) + 4 ) ,1
# define S T E P D 2 _ U P D A T E ( t ) \
and r6 ,R B ( t ) ,R C ( t ) ; \
and r0 ,R B ( t ) ,R D ( t ) ; \
rotlwi R T ( t ) ,R A ( t ) ,5 ; \
or r6 ,r6 ,r0 ; \
rotlwi R B ( t ) ,R B ( t ) ,3 0 ; \
and r0 ,R C ( t ) ,R D ( t ) ; \
xor r5 ,W ( ( t ) + 4 - 3 ) ,W ( ( t ) + 4 - 8 ) ; \
or r6 ,r6 ,r0 ; \
xor W ( ( t ) + 4 ) ,W ( ( t ) + 4 - 1 6 ) ,W ( ( t ) + 4 - 1 4 ) ; \
add r0 ,R E ( t ) ,r15 ; \
add R T ( t ) ,R T ( t ) ,r6 ; \
add r0 ,r0 ,W ( t ) ; \
xor W ( ( t ) + 4 ) ,W ( ( t ) + 4 ) ,r5 ; \
add R T ( t ) ,R T ( t ) ,r0 ; \
rotlwi W ( ( t ) + 4 ) ,W ( ( t ) + 4 ) ,1
# define S T E P 0 L D 4 ( t ) \
STEPD0 _ L O A D ( t ) ; \
STEPD0 _ L O A D ( ( t ) + 1 ) ; \
STEPD0 _ L O A D ( ( t ) + 2 ) ; \
STEPD0 _ L O A D ( ( t ) + 3 )
# define S T E P U P 4 ( t , f n ) \
STEP## f n # # _ U P D A T E ( t ) ; \
STEP## f n # # _ U P D A T E ( ( t ) + 1 ) ; \
STEP## f n # # _ U P D A T E ( ( t ) + 2 ) ; \
STEP## f n # # _ U P D A T E ( ( t ) + 3 )
# define S T E P U P 2 0 ( t , f n ) \
STEPUP4 ( t , f n ) ; \
STEPUP4 ( ( t ) + 4 , f n ) ; \
STEPUP4 ( ( t ) + 8 , f n ) ; \
STEPUP4 ( ( t ) + 1 2 , f n ) ; \
STEPUP4 ( ( t ) + 1 6 , f n )
_ GLOBAL( p o w e r p c _ s h a _ t r a n s f o r m )
2013-02-25 20:20:05 +04:00
PPC_ S T L U r1 ,- I N T _ F R A M E _ S I Z E ( r1 )
2012-09-14 03:00:49 +04:00
SAVE_ 8 G P R S ( 1 4 , r1 )
SAVE_ 1 0 G P R S ( 2 2 , r1 )
/* Load up A - E */
lwz R A ( 0 ) ,0 ( r3 ) / * A * /
lwz R B ( 0 ) ,4 ( r3 ) / * B * /
lwz R C ( 0 ) ,8 ( r3 ) / * C * /
lwz R D ( 0 ) ,1 2 ( r3 ) / * D * /
lwz R E ( 0 ) ,1 6 ( r3 ) / * E * /
LOADW( 0 )
LOADW( 1 )
LOADW( 2 )
LOADW( 3 )
lis r15 ,0 x5 a82 / * K 0 - 1 9 * /
ori r15 ,r15 ,0 x79 9 9
STEP0 L D 4 ( 0 )
STEP0 L D 4 ( 4 )
STEP0 L D 4 ( 8 )
STEPUP4 ( 1 2 , D 0 )
STEPUP4 ( 1 6 , D 0 )
lis r15 ,0 x6 e d9 / * K 2 0 - 3 9 * /
ori r15 ,r15 ,0 x e b a1
STEPUP2 0 ( 2 0 , D 1 )
lis r15 ,0 x8 f1 b / * K 4 0 - 5 9 * /
ori r15 ,r15 ,0 x b c d c
STEPUP2 0 ( 4 0 , D 2 )
lis r15 ,0 x c a62 / * K 6 0 - 7 9 * /
ori r15 ,r15 ,0 x c1 d6
STEPUP4 ( 6 0 , D 1 )
STEPUP4 ( 6 4 , D 1 )
STEPUP4 ( 6 8 , D 1 )
STEPUP4 ( 7 2 , D 1 )
lwz r20 ,1 6 ( r3 )
STEPD1 ( 7 6 )
lwz r19 ,1 2 ( r3 )
STEPD1 ( 7 7 )
lwz r18 ,8 ( r3 )
STEPD1 ( 7 8 )
lwz r17 ,4 ( r3 )
STEPD1 ( 7 9 )
lwz r16 ,0 ( r3 )
add r20 ,R E ( 8 0 ) ,r20
add R D ( 0 ) ,R D ( 8 0 ) ,r19
add R C ( 0 ) ,R C ( 8 0 ) ,r18
add R B ( 0 ) ,R B ( 8 0 ) ,r17
add R A ( 0 ) ,R A ( 8 0 ) ,r16
mr R E ( 0 ) ,r20
stw R A ( 0 ) ,0 ( r3 )
stw R B ( 0 ) ,4 ( r3 )
stw R C ( 0 ) ,8 ( r3 )
stw R D ( 0 ) ,1 2 ( r3 )
stw R E ( 0 ) ,1 6 ( r3 )
REST_ 8 G P R S ( 1 4 , r1 )
REST_ 1 0 G P R S ( 2 2 , r1 )
2013-02-25 20:20:05 +04:00
addi r1 ,r1 ,I N T _ F R A M E _ S I Z E
2012-09-14 03:00:49 +04:00
blr