2018-05-11 14:12:51 +02:00
/ *
* AES- N I + S S E 2 i m p l e m e n t a t i o n o f A E G I S - 1 2 8 L
*
* Copyright ( c ) 2 0 1 7 - 2 0 1 8 O n d r e j M o s n a c e k < o m o s n a c e k @gmail.com>
* Copyright ( C ) 2 0 1 7 - 2 0 1 8 R e d H a t , I n c . A l l r i g h t s r e s e r v e d .
*
* 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 / f r a m e . h >
# define S T A T E 0 % x m m 0
# define S T A T E 1 % x m m 1
# define S T A T E 2 % x m m 2
# define S T A T E 3 % x m m 3
# define S T A T E 4 % x m m 4
# define S T A T E 5 % x m m 5
# define S T A T E 6 % x m m 6
# define S T A T E 7 % x m m 7
# define M S G 0 % x m m 8
# define M S G 1 % x m m 9
# define T 0 % x m m 1 0
# define T 1 % x m m 1 1
# define T 2 % x m m 1 2
# define T 3 % x m m 1 3
# define S T A T E P % r d i
# define L E N % r s i
# define S R C % r d x
# define D S T % r c x
.section .rodata .cst16 .aegis128l_const , " aM" , @progbits, 32
.align 16
.Laegis128l_const_0 :
.byte 0 x0 0 , 0 x01 , 0 x01 , 0 x02 , 0 x03 , 0 x05 , 0 x08 , 0 x0 d
.byte 0 x1 5 , 0 x22 , 0 x37 , 0 x59 , 0 x90 , 0 x e 9 , 0 x79 , 0 x62
.Laegis128l_const_1 :
.byte 0 xdb, 0 x3 d , 0 x18 , 0 x55 , 0 x6 d , 0 x c2 , 0 x2 f , 0 x f1
.byte 0 x2 0 , 0 x11 , 0 x31 , 0 x42 , 0 x73 , 0 x b5 , 0 x28 , 0 x d d
.section .rodata .cst16 .aegis128l_counter , " aM" , @progbits, 16
.align 16
.Laegis128l_counter0 :
.byte 0 x0 0 , 0 x01 , 0 x02 , 0 x03 , 0 x04 , 0 x05 , 0 x06 , 0 x07
.byte 0 x0 8 , 0 x09 , 0 x0 a , 0 x0 b , 0 x0 c , 0 x0 d , 0 x0 e , 0 x0 f
.Laegis128l_counter1 :
.byte 0 x1 0 , 0 x11 , 0 x12 , 0 x13 , 0 x14 , 0 x15 , 0 x16 , 0 x17
.byte 0 x1 8 , 0 x19 , 0 x1 a , 0 x1 b , 0 x1 c , 0 x1 d , 0 x1 e , 0 x1 f
.text
/ *
* __load_partial : internal A B I
* input :
* LEN - b y t e s
* SRC - s r c
* output :
* MSG0 - f i r s t m e s s a g e b l o c k
* MSG1 - s e c o n d m e s s a g e b l o c k
* changed :
* T0
* % r8
* % r9
* /
__load_partial :
2018-07-02 04:31:54 -06:00
xor % r9 d , % r9 d
2018-05-11 14:12:51 +02:00
pxor M S G 0 , M S G 0
pxor M S G 1 , M S G 1
mov L E N , % r8
and $ 0 x1 , % r8
jz . L l d _ p a r t i a l _ 1
mov L E N , % r8
and $ 0 x1 E , % r8
add S R C , % r8
mov ( % r8 ) , % r9 b
.Lld_partial_1 :
mov L E N , % r8
and $ 0 x2 , % r8
jz . L l d _ p a r t i a l _ 2
mov L E N , % r8
and $ 0 x1 C , % r8
add S R C , % r8
shl $ 0 x10 , % r9
mov ( % r8 ) , % r9 w
.Lld_partial_2 :
mov L E N , % r8
and $ 0 x4 , % r8
jz . L l d _ p a r t i a l _ 4
mov L E N , % r8
and $ 0 x18 , % r8
add S R C , % r8
shl $ 3 2 , % r9
mov ( % r8 ) , % r8 d
xor % r8 , % r9
.Lld_partial_4 :
movq % r9 , M S G 0
mov L E N , % r8
and $ 0 x8 , % r8
jz . L l d _ p a r t i a l _ 8
mov L E N , % r8
and $ 0 x10 , % r8
add S R C , % r8
pslldq $ 8 , M S G 0
movq ( % r8 ) , T 0
pxor T 0 , M S G 0
.Lld_partial_8 :
mov L E N , % r8
and $ 0 x10 , % r8
jz . L l d _ p a r t i a l _ 1 6
movdqa M S G 0 , M S G 1
movdqu ( S R C ) , M S G 0
.Lld_partial_16 :
ret
ENDPROC( _ _ l o a d _ p a r t i a l )
/ *
* __store_partial : internal A B I
* input :
* LEN - b y t e s
* DST - d s t
* output :
* T0 - f i r s t m e s s a g e b l o c k
* T1 - s e c o n d m e s s a g e b l o c k
* changed :
* % r8
* % r9
* % r1 0
* /
__store_partial :
mov L E N , % r8
mov D S T , % r9
cmp $ 1 6 , % r8
jl . L s t _ p a r t i a l _ 1 6
movdqu T 0 , ( % r9 )
movdqa T 1 , T 0
sub $ 1 6 , % r8
add $ 1 6 , % r9
.Lst_partial_16 :
movq T 0 , % r10
cmp $ 8 , % r8
jl . L s t _ p a r t i a l _ 8
mov % r10 , ( % r9 )
psrldq $ 8 , T 0
movq T 0 , % r10
sub $ 8 , % r8
add $ 8 , % r9
.Lst_partial_8 :
cmp $ 4 , % r8
jl . L s t _ p a r t i a l _ 4
mov % r10 d , ( % r9 )
shr $ 3 2 , % r10
sub $ 4 , % r8
add $ 4 , % r9
.Lst_partial_4 :
cmp $ 2 , % r8
jl . L s t _ p a r t i a l _ 2
mov % r10 w , ( % r9 )
shr $ 0 x10 , % r10
sub $ 2 , % r8
add $ 2 , % r9
.Lst_partial_2 :
cmp $ 1 , % r8
jl . L s t _ p a r t i a l _ 1
mov % r10 b , ( % r9 )
.Lst_partial_1 :
ret
ENDPROC( _ _ s t o r e _ p a r t i a l )
.macro update
movdqa S T A T E 7 , T 0
aesenc S T A T E 0 , S T A T E 7
aesenc S T A T E 1 , S T A T E 0
aesenc S T A T E 2 , S T A T E 1
aesenc S T A T E 3 , S T A T E 2
aesenc S T A T E 4 , S T A T E 3
aesenc S T A T E 5 , S T A T E 4
aesenc S T A T E 6 , S T A T E 5
aesenc T 0 , S T A T E 6
.endm
.macro update0
update
pxor M S G 0 , S T A T E 7
pxor M S G 1 , S T A T E 3
.endm
.macro update1
update
pxor M S G 0 , S T A T E 6
pxor M S G 1 , S T A T E 2
.endm
.macro update2
update
pxor M S G 0 , S T A T E 5
pxor M S G 1 , S T A T E 1
.endm
.macro update3
update
pxor M S G 0 , S T A T E 4
pxor M S G 1 , S T A T E 0
.endm
.macro update4
update
pxor M S G 0 , S T A T E 3
pxor M S G 1 , S T A T E 7
.endm
.macro update5
update
pxor M S G 0 , S T A T E 2
pxor M S G 1 , S T A T E 6
.endm
.macro update6
update
pxor M S G 0 , S T A T E 1
pxor M S G 1 , S T A T E 5
.endm
.macro update7
update
pxor M S G 0 , S T A T E 0
pxor M S G 1 , S T A T E 4
.endm
.macro state_load
movdqu 0 x00 ( S T A T E P ) , S T A T E 0
movdqu 0 x10 ( S T A T E P ) , S T A T E 1
movdqu 0 x20 ( S T A T E P ) , S T A T E 2
movdqu 0 x30 ( S T A T E P ) , S T A T E 3
movdqu 0 x40 ( S T A T E P ) , S T A T E 4
movdqu 0 x50 ( S T A T E P ) , S T A T E 5
movdqu 0 x60 ( S T A T E P ) , S T A T E 6
movdqu 0 x70 ( S T A T E P ) , S T A T E 7
.endm
.macro state_store s0 s1 s2 s3 s4 s5 s6 s7
movdqu \ s7 , 0 x00 ( S T A T E P )
movdqu \ s0 , 0 x10 ( S T A T E P )
movdqu \ s1 , 0 x20 ( S T A T E P )
movdqu \ s2 , 0 x30 ( S T A T E P )
movdqu \ s3 , 0 x40 ( S T A T E P )
movdqu \ s4 , 0 x50 ( S T A T E P )
movdqu \ s5 , 0 x60 ( S T A T E P )
movdqu \ s6 , 0 x70 ( S T A T E P )
.endm
.macro state_store0
state_ s t o r e S T A T E 0 S T A T E 1 S T A T E 2 S T A T E 3 S T A T E 4 S T A T E 5 S T A T E 6 S T A T E 7
.endm
.macro state_store1
state_ s t o r e S T A T E 7 S T A T E 0 S T A T E 1 S T A T E 2 S T A T E 3 S T A T E 4 S T A T E 5 S T A T E 6
.endm
.macro state_store2
state_ s t o r e S T A T E 6 S T A T E 7 S T A T E 0 S T A T E 1 S T A T E 2 S T A T E 3 S T A T E 4 S T A T E 5
.endm
.macro state_store3
state_ s t o r e S T A T E 5 S T A T E 6 S T A T E 7 S T A T E 0 S T A T E 1 S T A T E 2 S T A T E 3 S T A T E 4
.endm
.macro state_store4
state_ s t o r e S T A T E 4 S T A T E 5 S T A T E 6 S T A T E 7 S T A T E 0 S T A T E 1 S T A T E 2 S T A T E 3
.endm
.macro state_store5
state_ s t o r e S T A T E 3 S T A T E 4 S T A T E 5 S T A T E 6 S T A T E 7 S T A T E 0 S T A T E 1 S T A T E 2
.endm
.macro state_store6
state_ s t o r e S T A T E 2 S T A T E 3 S T A T E 4 S T A T E 5 S T A T E 6 S T A T E 7 S T A T E 0 S T A T E 1
.endm
.macro state_store7
state_ s t o r e S T A T E 1 S T A T E 2 S T A T E 3 S T A T E 4 S T A T E 5 S T A T E 6 S T A T E 7 S T A T E 0
.endm
/ *
* void c r y p t o _ a e g i s12 8 l _ a e s n i _ i n i t ( v o i d * s t a t e , c o n s t v o i d * k e y , c o n s t v o i d * i v ) ;
* /
ENTRY( c r y p t o _ a e g i s12 8 l _ a e s n i _ i n i t )
FRAME_ B E G I N
/* load key: */
movdqa ( % r s i ) , M S G 1
movdqa M S G 1 , S T A T E 0
movdqa M S G 1 , S T A T E 4
movdqa M S G 1 , S T A T E 5
movdqa M S G 1 , S T A T E 6
movdqa M S G 1 , S T A T E 7
/* load IV: */
movdqu ( % r d x ) , M S G 0
pxor M S G 0 , S T A T E 0
pxor M S G 0 , S T A T E 4
/* load the constants: */
movdqa . L a e g i s12 8 l _ c o n s t _ 0 , S T A T E 2
movdqa . L a e g i s12 8 l _ c o n s t _ 1 , S T A T E 1
movdqa S T A T E 1 , S T A T E 3
pxor S T A T E 2 , S T A T E 5
pxor S T A T E 1 , S T A T E 6
pxor S T A T E 2 , S T A T E 7
/* update 10 times with IV and KEY: */
update0
update1
update2
update3
update4
update5
update6
update7
update0
update1
state_ s t o r e 1
FRAME_ E N D
ret
ENDPROC( c r y p t o _ a e g i s12 8 l _ a e s n i _ i n i t )
.macro ad_block a i
movdq\ a ( \ i * 0 x20 + 0 x00 ) ( S R C ) , M S G 0
movdq\ a ( \ i * 0 x20 + 0 x10 ) ( S R C ) , M S G 1
update\ i
sub $ 0 x20 , L E N
cmp $ 0 x20 , L E N
jl . L a d _ o u t _ \ i
.endm
/ *
* void c r y p t o _ a e g i s12 8 l _ a e s n i _ a d ( v o i d * s t a t e , u n s i g n e d i n t l e n g t h ,
* const v o i d * d a t a ) ;
* /
ENTRY( c r y p t o _ a e g i s12 8 l _ a e s n i _ a d )
FRAME_ B E G I N
cmp $ 0 x20 , L E N
jb . L a d _ o u t
state_ l o a d
mov S R C , % r8
and $ 0 x f , % r8
jnz . L a d _ u _ l o o p
.align 8
.Lad_a_loop :
ad_ b l o c k a 0
ad_ b l o c k a 1
ad_ b l o c k a 2
ad_ b l o c k a 3
ad_ b l o c k a 4
ad_ b l o c k a 5
ad_ b l o c k a 6
ad_ b l o c k a 7
add $ 0 x10 0 , S R C
jmp . L a d _ a _ l o o p
.align 8
.Lad_u_loop :
ad_ b l o c k u 0
ad_ b l o c k u 1
ad_ b l o c k u 2
ad_ b l o c k u 3
ad_ b l o c k u 4
ad_ b l o c k u 5
ad_ b l o c k u 6
ad_ b l o c k u 7
add $ 0 x10 0 , S R C
jmp . L a d _ u _ l o o p
.Lad_out_0 :
state_ s t o r e 0
FRAME_ E N D
ret
.Lad_out_1 :
state_ s t o r e 1
FRAME_ E N D
ret
.Lad_out_2 :
state_ s t o r e 2
FRAME_ E N D
ret
.Lad_out_3 :
state_ s t o r e 3
FRAME_ E N D
ret
.Lad_out_4 :
state_ s t o r e 4
FRAME_ E N D
ret
.Lad_out_5 :
state_ s t o r e 5
FRAME_ E N D
ret
.Lad_out_6 :
state_ s t o r e 6
FRAME_ E N D
ret
.Lad_out_7 :
state_ s t o r e 7
FRAME_ E N D
ret
.Lad_out :
FRAME_ E N D
ret
ENDPROC( c r y p t o _ a e g i s12 8 l _ a e s n i _ a d )
.macro crypt m0 m 1 s0 s1 s2 s3 s4 s5 s6 s7
pxor \ s1 , \ m 0
pxor \ s6 , \ m 0
movdqa \ s2 , T 3
pand \ s3 , T 3
pxor T 3 , \ m 0
pxor \ s2 , \ m 1
pxor \ s5 , \ m 1
movdqa \ s6 , T 3
pand \ s7 , T 3
pxor T 3 , \ m 1
.endm
.macro crypt0 m0 m 1
crypt \ m 0 \ m 1 S T A T E 0 S T A T E 1 S T A T E 2 S T A T E 3 S T A T E 4 S T A T E 5 S T A T E 6 S T A T E 7
.endm
.macro crypt1 m0 m 1
crypt \ m 0 \ m 1 S T A T E 7 S T A T E 0 S T A T E 1 S T A T E 2 S T A T E 3 S T A T E 4 S T A T E 5 S T A T E 6
.endm
.macro crypt2 m0 m 1
crypt \ m 0 \ m 1 S T A T E 6 S T A T E 7 S T A T E 0 S T A T E 1 S T A T E 2 S T A T E 3 S T A T E 4 S T A T E 5
.endm
.macro crypt3 m0 m 1
crypt \ m 0 \ m 1 S T A T E 5 S T A T E 6 S T A T E 7 S T A T E 0 S T A T E 1 S T A T E 2 S T A T E 3 S T A T E 4
.endm
.macro crypt4 m0 m 1
crypt \ m 0 \ m 1 S T A T E 4 S T A T E 5 S T A T E 6 S T A T E 7 S T A T E 0 S T A T E 1 S T A T E 2 S T A T E 3
.endm
.macro crypt5 m0 m 1
crypt \ m 0 \ m 1 S T A T E 3 S T A T E 4 S T A T E 5 S T A T E 6 S T A T E 7 S T A T E 0 S T A T E 1 S T A T E 2
.endm
.macro crypt6 m0 m 1
crypt \ m 0 \ m 1 S T A T E 2 S T A T E 3 S T A T E 4 S T A T E 5 S T A T E 6 S T A T E 7 S T A T E 0 S T A T E 1
.endm
.macro crypt7 m0 m 1
crypt \ m 0 \ m 1 S T A T E 1 S T A T E 2 S T A T E 3 S T A T E 4 S T A T E 5 S T A T E 6 S T A T E 7 S T A T E 0
.endm
.macro encrypt_block a i
movdq\ a ( \ i * 0 x20 + 0 x00 ) ( S R C ) , M S G 0
movdq\ a ( \ i * 0 x20 + 0 x10 ) ( S R C ) , M S G 1
movdqa M S G 0 , T 0
movdqa M S G 1 , T 1
crypt\ i T 0 , T 1
movdq\ a T 0 , ( \ i * 0 x20 + 0 x00 ) ( D S T )
movdq\ a T 1 , ( \ i * 0 x20 + 0 x10 ) ( D S T )
update\ i
sub $ 0 x20 , L E N
cmp $ 0 x20 , L E N
jl . L e n c _ o u t _ \ i
.endm
.macro decrypt_block a i
movdq\ a ( \ i * 0 x20 + 0 x00 ) ( S R C ) , M S G 0
movdq\ a ( \ i * 0 x20 + 0 x10 ) ( S R C ) , M S G 1
crypt\ i M S G 0 , M S G 1
movdq\ a M S G 0 , ( \ i * 0 x20 + 0 x00 ) ( D S T )
movdq\ a M S G 1 , ( \ i * 0 x20 + 0 x10 ) ( D S T )
update\ i
sub $ 0 x20 , L E N
cmp $ 0 x20 , L E N
jl . L d e c _ o u t _ \ i
.endm
/ *
* void c r y p t o _ a e g i s12 8 l _ a e s n i _ e n c ( v o i d * s t a t e , u n s i g n e d i n t l e n g t h ,
* const v o i d * s r c , v o i d * d s t ) ;
* /
ENTRY( c r y p t o _ a e g i s12 8 l _ a e s n i _ e n c )
FRAME_ B E G I N
cmp $ 0 x20 , L E N
jb . L e n c _ o u t
state_ l o a d
mov S R C , % r8
or D S T , % r8
and $ 0 x f , % r8
jnz . L e n c _ u _ l o o p
.align 8
.Lenc_a_loop :
encrypt_ b l o c k a 0
encrypt_ b l o c k a 1
encrypt_ b l o c k a 2
encrypt_ b l o c k a 3
encrypt_ b l o c k a 4
encrypt_ b l o c k a 5
encrypt_ b l o c k a 6
encrypt_ b l o c k a 7
add $ 0 x10 0 , S R C
add $ 0 x10 0 , D S T
jmp . L e n c _ a _ l o o p
.align 8
.Lenc_u_loop :
encrypt_ b l o c k u 0
encrypt_ b l o c k u 1
encrypt_ b l o c k u 2
encrypt_ b l o c k u 3
encrypt_ b l o c k u 4
encrypt_ b l o c k u 5
encrypt_ b l o c k u 6
encrypt_ b l o c k u 7
add $ 0 x10 0 , S R C
add $ 0 x10 0 , D S T
jmp . L e n c _ u _ l o o p
.Lenc_out_0 :
state_ s t o r e 0
FRAME_ E N D
ret
.Lenc_out_1 :
state_ s t o r e 1
FRAME_ E N D
ret
.Lenc_out_2 :
state_ s t o r e 2
FRAME_ E N D
ret
.Lenc_out_3 :
state_ s t o r e 3
FRAME_ E N D
ret
.Lenc_out_4 :
state_ s t o r e 4
FRAME_ E N D
ret
.Lenc_out_5 :
state_ s t o r e 5
FRAME_ E N D
ret
.Lenc_out_6 :
state_ s t o r e 6
FRAME_ E N D
ret
.Lenc_out_7 :
state_ s t o r e 7
FRAME_ E N D
ret
.Lenc_out :
FRAME_ E N D
ret
ENDPROC( c r y p t o _ a e g i s12 8 l _ a e s n i _ e n c )
/ *
* void c r y p t o _ a e g i s12 8 l _ a e s n i _ e n c _ t a i l ( v o i d * s t a t e , u n s i g n e d i n t l e n g t h ,
* const v o i d * s r c , v o i d * d s t ) ;
* /
ENTRY( c r y p t o _ a e g i s12 8 l _ a e s n i _ e n c _ t a i l )
FRAME_ B E G I N
state_ l o a d
/* encrypt message: */
call _ _ l o a d _ p a r t i a l
movdqa M S G 0 , T 0
movdqa M S G 1 , T 1
crypt0 T 0 , T 1
call _ _ s t o r e _ p a r t i a l
update0
state_ s t o r e 0
FRAME_ E N D
2018-06-23 12:36:22 +02:00
ret
2018-05-11 14:12:51 +02:00
ENDPROC( c r y p t o _ a e g i s12 8 l _ a e s n i _ e n c _ t a i l )
/ *
* void c r y p t o _ a e g i s12 8 l _ a e s n i _ d e c ( v o i d * s t a t e , u n s i g n e d i n t l e n g t h ,
* const v o i d * s r c , v o i d * d s t ) ;
* /
ENTRY( c r y p t o _ a e g i s12 8 l _ a e s n i _ d e c )
FRAME_ B E G I N
cmp $ 0 x20 , L E N
jb . L d e c _ o u t
state_ l o a d
mov S R C , % r8
or D S T , % r8
and $ 0 x F , % r8
jnz . L d e c _ u _ l o o p
.align 8
.Ldec_a_loop :
decrypt_ b l o c k a 0
decrypt_ b l o c k a 1
decrypt_ b l o c k a 2
decrypt_ b l o c k a 3
decrypt_ b l o c k a 4
decrypt_ b l o c k a 5
decrypt_ b l o c k a 6
decrypt_ b l o c k a 7
add $ 0 x10 0 , S R C
add $ 0 x10 0 , D S T
jmp . L d e c _ a _ l o o p
.align 8
.Ldec_u_loop :
decrypt_ b l o c k u 0
decrypt_ b l o c k u 1
decrypt_ b l o c k u 2
decrypt_ b l o c k u 3
decrypt_ b l o c k u 4
decrypt_ b l o c k u 5
decrypt_ b l o c k u 6
decrypt_ b l o c k u 7
add $ 0 x10 0 , S R C
add $ 0 x10 0 , D S T
jmp . L d e c _ u _ l o o p
.Ldec_out_0 :
state_ s t o r e 0
FRAME_ E N D
ret
.Ldec_out_1 :
state_ s t o r e 1
FRAME_ E N D
ret
.Ldec_out_2 :
state_ s t o r e 2
FRAME_ E N D
ret
.Ldec_out_3 :
state_ s t o r e 3
FRAME_ E N D
ret
.Ldec_out_4 :
state_ s t o r e 4
FRAME_ E N D
ret
.Ldec_out_5 :
state_ s t o r e 5
FRAME_ E N D
ret
.Ldec_out_6 :
state_ s t o r e 6
FRAME_ E N D
ret
.Ldec_out_7 :
state_ s t o r e 7
FRAME_ E N D
ret
.Ldec_out :
FRAME_ E N D
ret
ENDPROC( c r y p t o _ a e g i s12 8 l _ a e s n i _ d e c )
/ *
* void c r y p t o _ a e g i s12 8 l _ a e s n i _ d e c _ t a i l ( v o i d * s t a t e , u n s i g n e d i n t l e n g t h ,
* const v o i d * s r c , v o i d * d s t ) ;
* /
ENTRY( c r y p t o _ a e g i s12 8 l _ a e s n i _ d e c _ t a i l )
FRAME_ B E G I N
state_ l o a d
/* decrypt message: */
call _ _ l o a d _ p a r t i a l
crypt0 M S G 0 , M S G 1
movdqa M S G 0 , T 0
movdqa M S G 1 , T 1
call _ _ s t o r e _ p a r t i a l
/* mask with byte count: */
movq L E N , T 0
punpcklbw T 0 , T 0
punpcklbw T 0 , T 0
punpcklbw T 0 , T 0
punpcklbw T 0 , T 0
movdqa T 0 , T 1
movdqa . L a e g i s12 8 l _ c o u n t e r0 , T 2
movdqa . L a e g i s12 8 l _ c o u n t e r1 , T 3
pcmpgtb T 2 , T 0
pcmpgtb T 3 , T 1
pand T 0 , M S G 0
pand T 1 , M S G 1
update0
state_ s t o r e 0
FRAME_ E N D
ret
ENDPROC( c r y p t o _ a e g i s12 8 l _ a e s n i _ d e c _ t a i l )
/ *
* void c r y p t o _ a e g i s12 8 l _ a e s n i _ f i n a l ( v o i d * s t a t e , v o i d * t a g _ x o r ,
* u6 4 a s s o c l e n , u 6 4 c r y p t l e n ) ;
* /
ENTRY( c r y p t o _ a e g i s12 8 l _ a e s n i _ f i n a l )
FRAME_ B E G I N
state_ l o a d
/* prepare length block: */
movq % r d x , M S G 0
movq % r c x , T 0
pslldq $ 8 , T 0
pxor T 0 , M S G 0
psllq $ 3 , M S G 0 / * m u l t i p l y b y 8 ( t o g e t b i t c o u n t ) * /
pxor S T A T E 2 , M S G 0
movdqa M S G 0 , M S G 1
/* update state: */
update0
update1
update2
update3
update4
update5
update6
/* xor tag: */
movdqu ( % r s i ) , T 0
pxor S T A T E 1 , T 0
pxor S T A T E 2 , T 0
pxor S T A T E 3 , T 0
pxor S T A T E 4 , T 0
pxor S T A T E 5 , T 0
pxor S T A T E 6 , T 0
pxor S T A T E 7 , T 0
movdqu T 0 , ( % r s i )
FRAME_ E N D
ret
ENDPROC( c r y p t o _ a e g i s12 8 l _ a e s n i _ f i n a l )