Skip to content

Commit 933d6ae

Browse files
Dave Watsonherbertx
authored andcommitted
crypto: aesni - Add fast path for > 16 byte update
We can fast-path any < 16 byte read if the full message is > 16 bytes, and shift over by the appropriate amount. Usually we are reading > 16 bytes, so this should be faster than the READ_PARTIAL macro introduced in b20209c for the average case. Signed-off-by: Dave Watson <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent ae952c5 commit 933d6ae

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

arch/x86/crypto/aesni-intel_asm.S

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,12 +356,37 @@ _zero_cipher_left_\@:
356356
ENCRYPT_SINGLE_BLOCK %xmm0, %xmm1 # Encrypt(K, Yn)
357357
movdqu %xmm0, PBlockEncKey(%arg2)
358358

359+
cmp $16, %arg5
360+
jge _large_enough_update_\@
361+
359362
lea (%arg4,%r11,1), %r10
360363
mov %r13, %r12
361364
READ_PARTIAL_BLOCK %r10 %r12 %xmm2 %xmm1
365+
jmp _data_read_\@
366+
367+
_large_enough_update_\@:
368+
sub $16, %r11
369+
add %r13, %r11
370+
371+
# receive the last <16 Byte block
372+
movdqu (%arg4, %r11, 1), %xmm1
362373

374+
sub %r13, %r11
375+
add $16, %r11
376+
377+
lea SHIFT_MASK+16(%rip), %r12
378+
# adjust the shuffle mask pointer to be able to shift 16-r13 bytes
379+
# (r13 is the number of bytes in plaintext mod 16)
380+
sub %r13, %r12
381+
# get the appropriate shuffle mask
382+
movdqu (%r12), %xmm2
383+
# shift right 16-r13 bytes
384+
PSHUFB_XMM %xmm2, %xmm1
385+
386+
_data_read_\@:
363387
lea ALL_F+16(%rip), %r12
364388
sub %r13, %r12
389+
365390
.ifc \operation, dec
366391
movdqa %xmm1, %xmm2
367392
.endif

0 commit comments

Comments
 (0)