Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 <omosnace@redhat.com>
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Eric Biggers and committed by
Herbert Xu
a0927a03 933e8974

+17 -24
+15 -22
arch/x86/crypto/aegis128-aesni-asm.S
··· 190 190 /* 191 191 * void aegis128_aesni_ad(struct aegis_state *state, const u8 *data, 192 192 * unsigned int len); 193 + * 194 + * len must be a multiple of 16. 193 195 */ 194 196 SYM_FUNC_START(aegis128_aesni_ad) 195 197 .set STATEP, %rdi ··· 199 197 .set LEN, %edx 200 198 FRAME_BEGIN 201 199 202 - cmp $0x10, LEN 203 - jb .Lad_out 200 + test LEN, LEN 201 + jz .Lad_out 204 202 205 203 /* load the state: */ 206 204 movdqu 0x00(STATEP), STATE0 ··· 215 213 aegis128_update 216 214 pxor MSG, STATE4 217 215 sub $0x10, LEN 218 - cmp $0x10, LEN 219 - jl .Lad_out_1 216 + jz .Lad_out_1 220 217 221 218 movdqu 0x10(SRC), MSG 222 219 aegis128_update 223 220 pxor MSG, STATE3 224 221 sub $0x10, LEN 225 - cmp $0x10, LEN 226 - jl .Lad_out_2 222 + jz .Lad_out_2 227 223 228 224 movdqu 0x20(SRC), MSG 229 225 aegis128_update 230 226 pxor MSG, STATE2 231 227 sub $0x10, LEN 232 - cmp $0x10, LEN 233 - jl .Lad_out_3 228 + jz .Lad_out_3 234 229 235 230 movdqu 0x30(SRC), MSG 236 231 aegis128_update 237 232 pxor MSG, STATE1 238 233 sub $0x10, LEN 239 - cmp $0x10, LEN 240 - jl .Lad_out_4 234 + jz .Lad_out_4 241 235 242 236 movdqu 0x40(SRC), MSG 243 237 aegis128_update 244 238 pxor MSG, STATE0 245 239 sub $0x10, LEN 246 - cmp $0x10, LEN 247 - jl .Lad_out_0 240 + jz .Lad_out_0 248 241 249 242 add $0x50, SRC 250 243 jmp .Lad_loop ··· 309 312 pxor MSG, \s4 310 313 311 314 sub $0x10, LEN 312 - cmp $0x10, LEN 313 - jl .Lenc_out_\i 315 + jz .Lenc_out_\i 314 316 .endm 315 317 316 318 /* 317 319 * void aegis128_aesni_enc(struct aegis_state *state, const u8 *src, u8 *dst, 318 320 * unsigned int len); 321 + * 322 + * len must be nonzero and a multiple of 16. 319 323 */ 320 324 SYM_FUNC_START(aegis128_aesni_enc) 321 325 .set STATEP, %rdi ··· 324 326 .set DST, %rdx 325 327 .set LEN, %ecx 326 328 FRAME_BEGIN 327 - 328 - cmp $0x10, LEN 329 - jb .Lenc_out 330 329 331 330 /* load the state: */ 332 331 movdqu 0x00(STATEP), STATE0 ··· 454 459 pxor MSG, \s4 455 460 456 461 sub $0x10, LEN 457 - cmp $0x10, LEN 458 - jl .Ldec_out_\i 462 + jz .Ldec_out_\i 459 463 .endm 460 464 461 465 /* 462 466 * void aegis128_aesni_dec(struct aegis_state *state, const u8 *src, u8 *dst, 463 467 * unsigned int len); 468 + * 469 + * len must be nonzero and a multiple of 16. 464 470 */ 465 471 SYM_FUNC_START(aegis128_aesni_dec) 466 472 .set STATEP, %rdi ··· 469 473 .set DST, %rdx 470 474 .set LEN, %ecx 471 475 FRAME_BEGIN 472 - 473 - cmp $0x10, LEN 474 - jb .Ldec_out 475 476 476 477 /* load the state: */ 477 478 movdqu 0x00(STATEP), STATE0
+2 -2
arch/x86/crypto/aegis128-aesni-glue.c
··· 87 87 src += fill; 88 88 } 89 89 90 - aegis128_aesni_ad(state, src, left); 91 - 90 + aegis128_aesni_ad(state, src, 91 + left & ~(AEGIS128_BLOCK_SIZE - 1)); 92 92 src += left & ~(AEGIS128_BLOCK_SIZE - 1); 93 93 left &= AEGIS128_BLOCK_SIZE - 1; 94 94 }