Skip to content

Commit 3b2f2d2

Browse files
ebiggersherbertx
authored andcommitted
crypto: x86/aegis128 - access 32-bit arguments as 32-bit
Fix the AEGIS assembly code to access 'unsigned int' arguments as 32-bit values instead of 64-bit, since the upper bits of the corresponding 64-bit registers are not guaranteed to be zero. Note: there haven't been any reports of this bug actually causing incorrect behavior. Neither gcc nor clang guarantee zero-extension to 64 bits, but zero-extension is likely to happen in practice because most instructions that operate on 32-bit registers zero-extend to 64 bits. Fixes: 1d373d4 ("crypto: x86 - Add optimized AEGIS implementations") Cc: [email protected] Reviewed-by: Ondrej Mosnacek <[email protected]> Signed-off-by: Eric Biggers <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 16739ef commit 3b2f2d2

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

arch/x86/crypto/aegis128-aesni-asm.S

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#define T1 %xmm7
2222

2323
#define STATEP %rdi
24-
#define LEN %rsi
24+
#define LEN %esi
2525
#define SRC %rdx
2626
#define DST %rcx
2727

@@ -76,32 +76,32 @@ SYM_FUNC_START_LOCAL(__load_partial)
7676
xor %r9d, %r9d
7777
pxor MSG, MSG
7878

79-
mov LEN, %r8
79+
mov LEN, %r8d
8080
and $0x1, %r8
8181
jz .Lld_partial_1
8282

83-
mov LEN, %r8
83+
mov LEN, %r8d
8484
and $0x1E, %r8
8585
add SRC, %r8
8686
mov (%r8), %r9b
8787

8888
.Lld_partial_1:
89-
mov LEN, %r8
89+
mov LEN, %r8d
9090
and $0x2, %r8
9191
jz .Lld_partial_2
9292

93-
mov LEN, %r8
93+
mov LEN, %r8d
9494
and $0x1C, %r8
9595
add SRC, %r8
9696
shl $0x10, %r9
9797
mov (%r8), %r9w
9898

9999
.Lld_partial_2:
100-
mov LEN, %r8
100+
mov LEN, %r8d
101101
and $0x4, %r8
102102
jz .Lld_partial_4
103103

104-
mov LEN, %r8
104+
mov LEN, %r8d
105105
and $0x18, %r8
106106
add SRC, %r8
107107
shl $32, %r9
@@ -111,11 +111,11 @@ SYM_FUNC_START_LOCAL(__load_partial)
111111
.Lld_partial_4:
112112
movq %r9, MSG
113113

114-
mov LEN, %r8
114+
mov LEN, %r8d
115115
and $0x8, %r8
116116
jz .Lld_partial_8
117117

118-
mov LEN, %r8
118+
mov LEN, %r8d
119119
and $0x10, %r8
120120
add SRC, %r8
121121
pslldq $8, MSG
@@ -139,7 +139,7 @@ SYM_FUNC_END(__load_partial)
139139
* %r10
140140
*/
141141
SYM_FUNC_START_LOCAL(__store_partial)
142-
mov LEN, %r8
142+
mov LEN, %r8d
143143
mov DST, %r9
144144

145145
movq T0, %r10
@@ -677,7 +677,7 @@ SYM_TYPED_FUNC_START(crypto_aegis128_aesni_dec_tail)
677677
call __store_partial
678678

679679
/* mask with byte count: */
680-
movq LEN, T0
680+
movd LEN, T0
681681
punpcklbw T0, T0
682682
punpcklbw T0, T0
683683
punpcklbw T0, T0
@@ -702,7 +702,8 @@ SYM_FUNC_END(crypto_aegis128_aesni_dec_tail)
702702

703703
/*
704704
* void crypto_aegis128_aesni_final(void *state, void *tag_xor,
705-
* u64 assoclen, u64 cryptlen);
705+
* unsigned int assoclen,
706+
* unsigned int cryptlen);
706707
*/
707708
SYM_FUNC_START(crypto_aegis128_aesni_final)
708709
FRAME_BEGIN
@@ -715,8 +716,8 @@ SYM_FUNC_START(crypto_aegis128_aesni_final)
715716
movdqu 0x40(STATEP), STATE4
716717

717718
/* prepare length block: */
718-
movq %rdx, MSG
719-
movq %rcx, T0
719+
movd %edx, MSG
720+
movd %ecx, T0
720721
pslldq $8, T0
721722
pxor T0, MSG
722723
psllq $3, MSG /* multiply by 8 (to get bit count) */

0 commit comments

Comments
 (0)