2019-06-04 10:11:33 +02:00
/* SPDX-License-Identifier: GPL-2.0-only */
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
*
* 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 .
* /
# include < l i n u x / l i n k a g e . h >
2022-11-18 11:44:10 -08:00
# include < l i n u x / c f i _ t y p e s . h >
2018-05-11 14:12:51 +02:00
# 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 K E Y % x m m 5
# define M S G % x m m 5
# define T 0 % x m m 6
# define T 1 % x m m 7
# 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 .aegis128_const , " aM" , @progbits, 32
.align 16
.Laegis128_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
.Laegis128_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 .aegis128_counter , " aM" , @progbits, 16
.align 16
.Laegis128_counter :
.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
.text
/ *
* aegis1 2 8 _ u p d a t e
* input :
* STATE[ 0 - 4 ] - i n p u t s t a t e
* output :
* STATE[ 0 - 4 ] - o u t p u t s t a t e ( s h i f t e d p o s i t i o n s )
* changed :
* T0
* /
.macro aegis128_update
movdqa S T A T E 4 , T 0
aesenc S T A T E 0 , S T A T E 4
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 T 0 , S T A T E 3
.endm
/ *
* __load_partial : internal A B I
* input :
* LEN - b y t e s
* SRC - s r c
* output :
* MSG - m e s s a g e b l o c k
* changed :
* T0
* % r8
* % r9
* /
2019-10-11 13:50:46 +02:00
SYM_ F U N C _ S T A R T _ L O C A L ( _ _ l o a d _ p a r t i a l )
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 , M S G
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
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
movq ( % r8 ) , T 0
pxor T 0 , M S G
.Lld_partial_8 :
2021-12-04 14:43:40 +01:00
RET
2019-10-11 13:50:46 +02:00
SYM_ F U N C _ E N D ( _ _ l o a d _ p a r t i a l )
2018-05-11 14:12:51 +02:00
/ *
* __store_partial : internal A B I
* input :
* LEN - b y t e s
* DST - d s t
* output :
* T0 - m e s s a g e b l o c k
* changed :
* % r8
* % r9
* % r1 0
* /
2019-10-11 13:50:46 +02:00
SYM_ F U N C _ S T A R T _ L O C A L ( _ _ s t o r e _ p a r t i a l )
2018-05-11 14:12:51 +02:00
mov L E N , % r8
mov D S T , % r9
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 :
2021-12-04 14:43:40 +01:00
RET
2019-10-11 13:50:46 +02:00
SYM_ F U N C _ E N D ( _ _ s t o r e _ p a r t i a l )
2018-05-11 14:12:51 +02:00
/ *
* void c r y p t o _ a e g i s12 8 _ 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 ) ;
* /
2019-10-11 13:51:04 +02:00
SYM_ F U N C _ S T A R T ( c r y p t o _ a e g i s12 8 _ a e s n i _ i n i t )
2018-05-11 14:12:51 +02:00
FRAME_ B E G I N
/* load IV: */
movdqu ( % r d x ) , T 1
/* load key: */
movdqa ( % r s i ) , K E Y
pxor K E Y , T 1
movdqa T 1 , S T A T E 0
movdqa K E Y , S T A T E 3
movdqa K E Y , S T A T E 4
/* load the constants: */
2023-04-12 13:00:23 +02:00
movdqa . L a e g i s12 8 _ c o n s t _ 0 ( % r i p ) , S T A T E 2
movdqa . L a e g i s12 8 _ c o n s t _ 1 ( % r i p ) , S T A T E 1
2018-05-11 14:12:51 +02:00
pxor S T A T E 2 , S T A T E 3
pxor S T A T E 1 , S T A T E 4
/* update 10 times with KEY / KEY xor IV: */
aegis1 2 8 _ u p d a t e ; pxor KEY, STATE4
aegis1 2 8 _ u p d a t e ; pxor T1, STATE3
aegis1 2 8 _ u p d a t e ; pxor KEY, STATE2
aegis1 2 8 _ u p d a t e ; pxor T1, STATE1
aegis1 2 8 _ u p d a t e ; pxor KEY, STATE0
aegis1 2 8 _ u p d a t e ; pxor T1, STATE4
aegis1 2 8 _ u p d a t e ; pxor KEY, STATE3
aegis1 2 8 _ u p d a t e ; pxor T1, STATE2
aegis1 2 8 _ u p d a t e ; pxor KEY, STATE1
aegis1 2 8 _ u p d a t e ; pxor T1, STATE0
/* store the state: */
movdqu S T A T E 0 , 0 x00 ( S T A T E P )
movdqu S T A T E 1 , 0 x10 ( S T A T E P )
movdqu S T A T E 2 , 0 x20 ( S T A T E P )
movdqu S T A T E 3 , 0 x30 ( S T A T E P )
movdqu S T A T E 4 , 0 x40 ( S T A T E P )
FRAME_ E N D
2021-12-04 14:43:40 +01:00
RET
2019-10-11 13:51:04 +02:00
SYM_ F U N C _ E N D ( c r y p t o _ a e g i s12 8 _ a e s n i _ i n i t )
2018-05-11 14:12:51 +02:00
/ *
* void c r y p t o _ a e g i s12 8 _ 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 ) ;
* /
2019-10-11 13:51:04 +02:00
SYM_ F U N C _ S T A R T ( c r y p t o _ a e g i s12 8 _ a e s n i _ a d )
2018-05-11 14:12:51 +02:00
FRAME_ B E G I N
cmp $ 0 x10 , L E N
jb . L a d _ o u t
/* load the state: */
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
mov S R C , % r8
and $ 0 x F , % r8
jnz . L a d _ u _ l o o p
.align 8
.Lad_a_loop :
movdqa 0 x00 ( S R C ) , M S G
aegis1 2 8 _ u p d a t e
pxor M S G , S T A T E 4
sub $ 0 x10 , L E N
cmp $ 0 x10 , L E N
jl . L a d _ o u t _ 1
movdqa 0 x10 ( S R C ) , M S G
aegis1 2 8 _ u p d a t e
pxor M S G , S T A T E 3
sub $ 0 x10 , L E N
cmp $ 0 x10 , L E N
jl . L a d _ o u t _ 2
movdqa 0 x20 ( S R C ) , M S G
aegis1 2 8 _ u p d a t e
pxor M S G , S T A T E 2
sub $ 0 x10 , L E N
cmp $ 0 x10 , L E N
jl . L a d _ o u t _ 3
movdqa 0 x30 ( S R C ) , M S G
aegis1 2 8 _ u p d a t e
pxor M S G , S T A T E 1
sub $ 0 x10 , L E N
cmp $ 0 x10 , L E N
jl . L a d _ o u t _ 4
movdqa 0 x40 ( S R C ) , M S G
aegis1 2 8 _ u p d a t e
pxor M S G , S T A T E 0
sub $ 0 x10 , L E N
cmp $ 0 x10 , L E N
jl . L a d _ o u t _ 0
add $ 0 x50 , S R C
jmp . L a d _ a _ l o o p
.align 8
.Lad_u_loop :
movdqu 0 x00 ( S R C ) , M S G
aegis1 2 8 _ u p d a t e
pxor M S G , S T A T E 4
sub $ 0 x10 , L E N
cmp $ 0 x10 , L E N
jl . L a d _ o u t _ 1
movdqu 0 x10 ( S R C ) , M S G
aegis1 2 8 _ u p d a t e
pxor M S G , S T A T E 3
sub $ 0 x10 , L E N
cmp $ 0 x10 , L E N
jl . L a d _ o u t _ 2
movdqu 0 x20 ( S R C ) , M S G
aegis1 2 8 _ u p d a t e
pxor M S G , S T A T E 2
sub $ 0 x10 , L E N
cmp $ 0 x10 , L E N
jl . L a d _ o u t _ 3
movdqu 0 x30 ( S R C ) , M S G
aegis1 2 8 _ u p d a t e
pxor M S G , S T A T E 1
sub $ 0 x10 , L E N
cmp $ 0 x10 , L E N
jl . L a d _ o u t _ 4
movdqu 0 x40 ( S R C ) , M S G
aegis1 2 8 _ u p d a t e
pxor M S G , S T A T E 0
sub $ 0 x10 , L E N
cmp $ 0 x10 , L E N
jl . L a d _ o u t _ 0
add $ 0 x50 , S R C
jmp . L a d _ u _ l o o p
/* store the state: */
.Lad_out_0 :
movdqu S T A T E 0 , 0 x00 ( S T A T E P )
movdqu S T A T E 1 , 0 x10 ( S T A T E P )
movdqu S T A T E 2 , 0 x20 ( S T A T E P )
movdqu S T A T E 3 , 0 x30 ( S T A T E P )
movdqu S T A T E 4 , 0 x40 ( S T A T E P )
FRAME_ E N D
2021-12-04 14:43:40 +01:00
RET
2018-05-11 14:12:51 +02:00
.Lad_out_1 :
movdqu S T A T E 4 , 0 x00 ( S T A T E P )
movdqu S T A T E 0 , 0 x10 ( S T A T E P )
movdqu S T A T E 1 , 0 x20 ( S T A T E P )
movdqu S T A T E 2 , 0 x30 ( S T A T E P )
movdqu S T A T E 3 , 0 x40 ( S T A T E P )
FRAME_ E N D
2021-12-04 14:43:40 +01:00
RET
2018-05-11 14:12:51 +02:00
.Lad_out_2 :
movdqu S T A T E 3 , 0 x00 ( S T A T E P )
movdqu S T A T E 4 , 0 x10 ( S T A T E P )
movdqu S T A T E 0 , 0 x20 ( S T A T E P )
movdqu S T A T E 1 , 0 x30 ( S T A T E P )
movdqu S T A T E 2 , 0 x40 ( S T A T E P )
FRAME_ E N D
2021-12-04 14:43:40 +01:00
RET
2018-05-11 14:12:51 +02:00
.Lad_out_3 :
movdqu S T A T E 2 , 0 x00 ( S T A T E P )
movdqu S T A T E 3 , 0 x10 ( S T A T E P )
movdqu S T A T E 4 , 0 x20 ( S T A T E P )
movdqu S T A T E 0 , 0 x30 ( S T A T E P )
movdqu S T A T E 1 , 0 x40 ( S T A T E P )
FRAME_ E N D
2021-12-04 14:43:40 +01:00
RET
2018-05-11 14:12:51 +02:00
.Lad_out_4 :
movdqu S T A T E 1 , 0 x00 ( S T A T E P )
movdqu S T A T E 2 , 0 x10 ( S T A T E P )
movdqu S T A T E 3 , 0 x20 ( S T A T E P )
movdqu S T A T E 4 , 0 x30 ( S T A T E P )
movdqu S T A T E 0 , 0 x40 ( S T A T E P )
FRAME_ E N D
2021-12-04 14:43:40 +01:00
RET
2018-05-11 14:12:51 +02:00
.Lad_out :
FRAME_ E N D
2021-12-04 14:43:40 +01:00
RET
2019-10-11 13:51:04 +02:00
SYM_ F U N C _ E N D ( c r y p t o _ a e g i s12 8 _ a e s n i _ a d )
2018-05-11 14:12:51 +02:00
.macro encrypt_block a s0 s1 s2 s3 s4 i
movdq\ a ( \ i * 0 x10 ) ( S R C ) , M S G
movdqa M S G , T 0
pxor \ s1 , T 0
pxor \ s4 , T 0
movdqa \ s2 , T 1
pand \ s3 , T 1
pxor T 1 , T 0
movdq\ a T 0 , ( \ i * 0 x10 ) ( D S T )
aegis1 2 8 _ u p d a t e
pxor M S G , \ s4
sub $ 0 x10 , L E N
cmp $ 0 x10 , L E N
jl . L e n c _ o u t _ \ i
.endm
/ *
* void c r y p t o _ a e g i s12 8 _ 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 ) ;
* /
2022-11-18 11:44:10 -08:00
SYM_ T Y P E D _ F U N C _ S T A R T ( c r y p t o _ a e g i s12 8 _ a e s n i _ e n c )
2018-05-11 14:12:51 +02:00
FRAME_ B E G I N
cmp $ 0 x10 , L E N
jb . L e n c _ o u t
/* load the state: */
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
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 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 0
encrypt_ b l o c k a S T A T E 4 S T A T E 0 S T A T E 1 S T A T E 2 S T A T E 3 1
encrypt_ b l o c k a S T A T E 3 S T A T E 4 S T A T E 0 S T A T E 1 S T A T E 2 2
encrypt_ b l o c k a S T A T E 2 S T A T E 3 S T A T E 4 S T A T E 0 S T A T E 1 3
encrypt_ b l o c k a 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 0 4
add $ 0 x50 , S R C
add $ 0 x50 , 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 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 0
encrypt_ b l o c k u S T A T E 4 S T A T E 0 S T A T E 1 S T A T E 2 S T A T E 3 1
encrypt_ b l o c k u S T A T E 3 S T A T E 4 S T A T E 0 S T A T E 1 S T A T E 2 2
encrypt_ b l o c k u S T A T E 2 S T A T E 3 S T A T E 4 S T A T E 0 S T A T E 1 3
encrypt_ b l o c k u 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 0 4
add $ 0 x50 , S R C
add $ 0 x50 , D S T
jmp . L e n c _ u _ l o o p
/* store the state: */
.Lenc_out_0 :
movdqu S T A T E 4 , 0 x00 ( S T A T E P )
movdqu S T A T E 0 , 0 x10 ( S T A T E P )
movdqu S T A T E 1 , 0 x20 ( S T A T E P )
movdqu S T A T E 2 , 0 x30 ( S T A T E P )
movdqu S T A T E 3 , 0 x40 ( S T A T E P )
FRAME_ E N D
2021-12-04 14:43:40 +01:00
RET
2018-05-11 14:12:51 +02:00
.Lenc_out_1 :
movdqu S T A T E 3 , 0 x00 ( S T A T E P )
movdqu S T A T E 4 , 0 x10 ( S T A T E P )
movdqu S T A T E 0 , 0 x20 ( S T A T E P )
movdqu S T A T E 1 , 0 x30 ( S T A T E P )
movdqu S T A T E 2 , 0 x40 ( S T A T E P )
FRAME_ E N D
2021-12-04 14:43:40 +01:00
RET
2018-05-11 14:12:51 +02:00
.Lenc_out_2 :
movdqu S T A T E 2 , 0 x00 ( S T A T E P )
movdqu S T A T E 3 , 0 x10 ( S T A T E P )
movdqu S T A T E 4 , 0 x20 ( S T A T E P )
movdqu S T A T E 0 , 0 x30 ( S T A T E P )
movdqu S T A T E 1 , 0 x40 ( S T A T E P )
FRAME_ E N D
2021-12-04 14:43:40 +01:00
RET
2018-05-11 14:12:51 +02:00
.Lenc_out_3 :
movdqu S T A T E 1 , 0 x00 ( S T A T E P )
movdqu S T A T E 2 , 0 x10 ( S T A T E P )
movdqu S T A T E 3 , 0 x20 ( S T A T E P )
movdqu S T A T E 4 , 0 x30 ( S T A T E P )
movdqu S T A T E 0 , 0 x40 ( S T A T E P )
FRAME_ E N D
2021-12-04 14:43:40 +01:00
RET
2018-05-11 14:12:51 +02:00
.Lenc_out_4 :
movdqu S T A T E 0 , 0 x00 ( S T A T E P )
movdqu S T A T E 1 , 0 x10 ( S T A T E P )
movdqu S T A T E 2 , 0 x20 ( S T A T E P )
movdqu S T A T E 3 , 0 x30 ( S T A T E P )
movdqu S T A T E 4 , 0 x40 ( S T A T E P )
FRAME_ E N D
2021-12-04 14:43:40 +01:00
RET
2018-05-11 14:12:51 +02:00
.Lenc_out :
FRAME_ E N D
2021-12-04 14:43:40 +01:00
RET
2019-10-11 13:51:04 +02:00
SYM_ F U N C _ E N D ( c r y p t o _ a e g i s12 8 _ a e s n i _ e n c )
2018-05-11 14:12:51 +02:00
/ *
* void c r y p t o _ a e g i s12 8 _ 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 ) ;
* /
2022-11-18 11:44:10 -08:00
SYM_ T Y P E D _ F U N C _ S T A R T ( c r y p t o _ a e g i s12 8 _ a e s n i _ e n c _ t a i l )
2018-05-11 14:12:51 +02:00
FRAME_ B E G I N
/* load the state: */
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
/* encrypt message: */
call _ _ l o a d _ p a r t i a l
movdqa M S G , T 0
pxor S T A T E 1 , T 0
pxor S T A T E 4 , T 0
movdqa S T A T E 2 , T 1
pand S T A T E 3 , T 1
pxor T 1 , T 0
call _ _ s t o r e _ p a r t i a l
aegis1 2 8 _ u p d a t e
pxor M S G , S T A T E 4
/* store the state: */
movdqu S T A T E 4 , 0 x00 ( S T A T E P )
movdqu S T A T E 0 , 0 x10 ( S T A T E P )
movdqu S T A T E 1 , 0 x20 ( S T A T E P )
movdqu S T A T E 2 , 0 x30 ( S T A T E P )
movdqu S T A T E 3 , 0 x40 ( S T A T E P )
FRAME_ E N D
2021-12-04 14:43:40 +01:00
RET
2019-10-11 13:51:04 +02:00
SYM_ F U N C _ E N D ( c r y p t o _ a e g i s12 8 _ a e s n i _ e n c _ t a i l )
2018-05-11 14:12:51 +02:00
.macro decrypt_block a s0 s1 s2 s3 s4 i
movdq\ a ( \ i * 0 x10 ) ( S R C ) , M S G
pxor \ s1 , M S G
pxor \ s4 , M S G
movdqa \ s2 , T 1
pand \ s3 , T 1
pxor T 1 , M S G
movdq\ a M S G , ( \ i * 0 x10 ) ( D S T )
aegis1 2 8 _ u p d a t e
pxor M S G , \ s4
sub $ 0 x10 , L E N
cmp $ 0 x10 , 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 _ 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 ) ;
* /
2022-11-18 11:44:10 -08:00
SYM_ T Y P E D _ F U N C _ S T A R T ( c r y p t o _ a e g i s12 8 _ a e s n i _ d e c )
2018-05-11 14:12:51 +02:00
FRAME_ B E G I N
cmp $ 0 x10 , L E N
jb . L d e c _ o u t
/* load the state: */
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
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 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 0
decrypt_ b l o c k a S T A T E 4 S T A T E 0 S T A T E 1 S T A T E 2 S T A T E 3 1
decrypt_ b l o c k a S T A T E 3 S T A T E 4 S T A T E 0 S T A T E 1 S T A T E 2 2
decrypt_ b l o c k a S T A T E 2 S T A T E 3 S T A T E 4 S T A T E 0 S T A T E 1 3
decrypt_ b l o c k a 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 0 4
add $ 0 x50 , S R C
add $ 0 x50 , 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 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 0
decrypt_ b l o c k u S T A T E 4 S T A T E 0 S T A T E 1 S T A T E 2 S T A T E 3 1
decrypt_ b l o c k u S T A T E 3 S T A T E 4 S T A T E 0 S T A T E 1 S T A T E 2 2
decrypt_ b l o c k u S T A T E 2 S T A T E 3 S T A T E 4 S T A T E 0 S T A T E 1 3
decrypt_ b l o c k u 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 0 4
add $ 0 x50 , S R C
add $ 0 x50 , D S T
jmp . L d e c _ u _ l o o p
/* store the state: */
.Ldec_out_0 :
movdqu S T A T E 4 , 0 x00 ( S T A T E P )
movdqu S T A T E 0 , 0 x10 ( S T A T E P )
movdqu S T A T E 1 , 0 x20 ( S T A T E P )
movdqu S T A T E 2 , 0 x30 ( S T A T E P )
movdqu S T A T E 3 , 0 x40 ( S T A T E P )
FRAME_ E N D
2021-12-04 14:43:40 +01:00
RET
2018-05-11 14:12:51 +02:00
.Ldec_out_1 :
movdqu S T A T E 3 , 0 x00 ( S T A T E P )
movdqu S T A T E 4 , 0 x10 ( S T A T E P )
movdqu S T A T E 0 , 0 x20 ( S T A T E P )
movdqu S T A T E 1 , 0 x30 ( S T A T E P )
movdqu S T A T E 2 , 0 x40 ( S T A T E P )
FRAME_ E N D
2021-12-04 14:43:40 +01:00
RET
2018-05-11 14:12:51 +02:00
.Ldec_out_2 :
movdqu S T A T E 2 , 0 x00 ( S T A T E P )
movdqu S T A T E 3 , 0 x10 ( S T A T E P )
movdqu S T A T E 4 , 0 x20 ( S T A T E P )
movdqu S T A T E 0 , 0 x30 ( S T A T E P )
movdqu S T A T E 1 , 0 x40 ( S T A T E P )
FRAME_ E N D
2021-12-04 14:43:40 +01:00
RET
2018-05-11 14:12:51 +02:00
.Ldec_out_3 :
movdqu S T A T E 1 , 0 x00 ( S T A T E P )
movdqu S T A T E 2 , 0 x10 ( S T A T E P )
movdqu S T A T E 3 , 0 x20 ( S T A T E P )
movdqu S T A T E 4 , 0 x30 ( S T A T E P )
movdqu S T A T E 0 , 0 x40 ( S T A T E P )
FRAME_ E N D
2021-12-04 14:43:40 +01:00
RET
2018-05-11 14:12:51 +02:00
.Ldec_out_4 :
movdqu S T A T E 0 , 0 x00 ( S T A T E P )
movdqu S T A T E 1 , 0 x10 ( S T A T E P )
movdqu S T A T E 2 , 0 x20 ( S T A T E P )
movdqu S T A T E 3 , 0 x30 ( S T A T E P )
movdqu S T A T E 4 , 0 x40 ( S T A T E P )
FRAME_ E N D
2021-12-04 14:43:40 +01:00
RET
2018-05-11 14:12:51 +02:00
.Ldec_out :
FRAME_ E N D
2021-12-04 14:43:40 +01:00
RET
2019-10-11 13:51:04 +02:00
SYM_ F U N C _ E N D ( c r y p t o _ a e g i s12 8 _ a e s n i _ d e c )
2018-05-11 14:12:51 +02:00
/ *
* void c r y p t o _ a e g i s12 8 _ 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 ) ;
* /
2022-11-18 11:44:10 -08:00
SYM_ T Y P E D _ F U N C _ S T A R T ( c r y p t o _ a e g i s12 8 _ a e s n i _ d e c _ t a i l )
2018-05-11 14:12:51 +02:00
FRAME_ B E G I N
/* load the state: */
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
/* decrypt message: */
call _ _ l o a d _ p a r t i a l
pxor S T A T E 1 , M S G
pxor S T A T E 4 , M S G
movdqa S T A T E 2 , T 1
pand S T A T E 3 , T 1
pxor T 1 , M S G
movdqa M S G , T 0
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
2023-04-12 13:00:23 +02:00
movdqa . L a e g i s12 8 _ c o u n t e r ( % r i p ) , T 1
2018-05-11 14:12:51 +02:00
pcmpgtb T 1 , T 0
pand T 0 , M S G
aegis1 2 8 _ u p d a t e
pxor M S G , S T A T E 4
/* store the state: */
movdqu S T A T E 4 , 0 x00 ( S T A T E P )
movdqu S T A T E 0 , 0 x10 ( S T A T E P )
movdqu S T A T E 1 , 0 x20 ( S T A T E P )
movdqu S T A T E 2 , 0 x30 ( S T A T E P )
movdqu S T A T E 3 , 0 x40 ( S T A T E P )
FRAME_ E N D
2021-12-04 14:43:40 +01:00
RET
2019-10-11 13:51:04 +02:00
SYM_ F U N C _ E N D ( c r y p t o _ a e g i s12 8 _ a e s n i _ d e c _ t a i l )
2018-05-11 14:12:51 +02:00
/ *
* void c r y p t o _ a e g i s12 8 _ 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 ) ;
* /
2019-10-11 13:51:04 +02:00
SYM_ F U N C _ S T A R T ( c r y p t o _ a e g i s12 8 _ a e s n i _ f i n a l )
2018-05-11 14:12:51 +02:00
FRAME_ B E G I N
/* load the state: */
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
/* prepare length block: */
movq % r d x , M S G
movq % r c x , T 0
pslldq $ 8 , T 0
pxor T 0 , M S G
psllq $ 3 , M S G / * 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 3 , M S G
/* update state: */
aegis1 2 8 _ u p d a t e ; pxor MSG, STATE4
aegis1 2 8 _ u p d a t e ; pxor MSG, STATE3
aegis1 2 8 _ u p d a t e ; pxor MSG, STATE2
aegis1 2 8 _ u p d a t e ; pxor MSG, STATE1
aegis1 2 8 _ u p d a t e ; pxor MSG, STATE0
aegis1 2 8 _ u p d a t e ; pxor MSG, STATE4
aegis1 2 8 _ u p d a t e ; pxor MSG, STATE3
/* xor tag: */
movdqu ( % r s i ) , M S G
pxor S T A T E 0 , M S G
pxor S T A T E 1 , M S G
pxor S T A T E 2 , M S G
pxor S T A T E 3 , M S G
pxor S T A T E 4 , M S G
movdqu M S G , ( % r s i )
FRAME_ E N D
2021-12-04 14:43:40 +01:00
RET
2019-10-11 13:51:04 +02:00
SYM_ F U N C _ E N D ( c r y p t o _ a e g i s12 8 _ a e s n i _ f i n a l )