Skip to content

Commit a0927a0

Browse files
ebiggersherbertx
authored andcommitted
crypto: x86/aegis128 - take advantage of block-aligned len
Update a caller of aegis128_aesni_ad() to round down the length to a block boundary. After that, aegis128_aesni_ad(), aegis128_aesni_enc(), and aegis128_aesni_dec() are only passed whole blocks. Update the assembly code to take advantage of that, which eliminates some unneeded instructions. For aegis128_aesni_enc() and aegis128_aesni_dec(), the length is also always nonzero, so stop checking for zero length. Reviewed-by: Ondrej Mosnacek <[email protected]> Signed-off-by: Eric Biggers <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 933e897 commit a0927a0

File tree

2 files changed

+17
-24
lines changed

2 files changed

+17
-24
lines changed

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

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -190,15 +190,17 @@ SYM_FUNC_END(aegis128_aesni_init)
190190
/*
191191
* void aegis128_aesni_ad(struct aegis_state *state, const u8 *data,
192192
* unsigned int len);
193+
*
194+
* len must be a multiple of 16.
193195
*/
194196
SYM_FUNC_START(aegis128_aesni_ad)
195197
.set STATEP, %rdi
196198
.set SRC, %rsi
197199
.set LEN, %edx
198200
FRAME_BEGIN
199201

200-
cmp $0x10, LEN
201-
jb .Lad_out
202+
test LEN, LEN
203+
jz .Lad_out
202204

203205
/* load the state: */
204206
movdqu 0x00(STATEP), STATE0
@@ -213,36 +215,31 @@ SYM_FUNC_START(aegis128_aesni_ad)
213215
aegis128_update
214216
pxor MSG, STATE4
215217
sub $0x10, LEN
216-
cmp $0x10, LEN
217-
jl .Lad_out_1
218+
jz .Lad_out_1
218219

219220
movdqu 0x10(SRC), MSG
220221
aegis128_update
221222
pxor MSG, STATE3
222223
sub $0x10, LEN
223-
cmp $0x10, LEN
224-
jl .Lad_out_2
224+
jz .Lad_out_2
225225

226226
movdqu 0x20(SRC), MSG
227227
aegis128_update
228228
pxor MSG, STATE2
229229
sub $0x10, LEN
230-
cmp $0x10, LEN
231-
jl .Lad_out_3
230+
jz .Lad_out_3
232231

233232
movdqu 0x30(SRC), MSG
234233
aegis128_update
235234
pxor MSG, STATE1
236235
sub $0x10, LEN
237-
cmp $0x10, LEN
238-
jl .Lad_out_4
236+
jz .Lad_out_4
239237

240238
movdqu 0x40(SRC), MSG
241239
aegis128_update
242240
pxor MSG, STATE0
243241
sub $0x10, LEN
244-
cmp $0x10, LEN
245-
jl .Lad_out_0
242+
jz .Lad_out_0
246243

247244
add $0x50, SRC
248245
jmp .Lad_loop
@@ -312,13 +309,14 @@ SYM_FUNC_END(aegis128_aesni_ad)
312309
pxor MSG, \s4
313310

314311
sub $0x10, LEN
315-
cmp $0x10, LEN
316-
jl .Lenc_out_\i
312+
jz .Lenc_out_\i
317313
.endm
318314

319315
/*
320316
* void aegis128_aesni_enc(struct aegis_state *state, const u8 *src, u8 *dst,
321317
* unsigned int len);
318+
*
319+
* len must be nonzero and a multiple of 16.
322320
*/
323321
SYM_FUNC_START(aegis128_aesni_enc)
324322
.set STATEP, %rdi
@@ -327,9 +325,6 @@ SYM_FUNC_START(aegis128_aesni_enc)
327325
.set LEN, %ecx
328326
FRAME_BEGIN
329327

330-
cmp $0x10, LEN
331-
jb .Lenc_out
332-
333328
/* load the state: */
334329
movdqu 0x00(STATEP), STATE0
335330
movdqu 0x10(STATEP), STATE1
@@ -459,13 +454,14 @@ SYM_FUNC_END(aegis128_aesni_enc_tail)
459454
pxor MSG, \s4
460455

461456
sub $0x10, LEN
462-
cmp $0x10, LEN
463-
jl .Ldec_out_\i
457+
jz .Ldec_out_\i
464458
.endm
465459

466460
/*
467461
* void aegis128_aesni_dec(struct aegis_state *state, const u8 *src, u8 *dst,
468462
* unsigned int len);
463+
*
464+
* len must be nonzero and a multiple of 16.
469465
*/
470466
SYM_FUNC_START(aegis128_aesni_dec)
471467
.set STATEP, %rdi
@@ -474,9 +470,6 @@ SYM_FUNC_START(aegis128_aesni_dec)
474470
.set LEN, %ecx
475471
FRAME_BEGIN
476472

477-
cmp $0x10, LEN
478-
jb .Ldec_out
479-
480473
/* load the state: */
481474
movdqu 0x00(STATEP), STATE0
482475
movdqu 0x10(STATEP), STATE1

arch/x86/crypto/aegis128-aesni-glue.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ static void crypto_aegis128_aesni_process_ad(
8787
src += fill;
8888
}
8989

90-
aegis128_aesni_ad(state, src, left);
91-
90+
aegis128_aesni_ad(state, src,
91+
left & ~(AEGIS128_BLOCK_SIZE - 1));
9292
src += left & ~(AEGIS128_BLOCK_SIZE - 1);
9393
left &= AEGIS128_BLOCK_SIZE - 1;
9494
}

0 commit comments

Comments
 (0)