hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit c0cd6193d3bde990525f19d3cbe669ac2130e39c
parent 16f7d6b204656cafb68672507d224c579401ed6d
Author: Armin Preiml <apreiml@strohwolke.at>
Date:   Sun, 24 Apr 2022 10:20:38 +0200

crypto::aes::x86ni_init: save some jumps

Move the round key length earlier to the rax register as return value,
so that it can be used in the decryption round key derivation as offset
to the last element.

Signed-off-by: Armin Preiml <apreiml@strohwolke.at>

Diffstat:
Mcrypto/aes/+x86_64/ni_native.s | 34+++++++++++++++-------------------
1 file changed, 15 insertions(+), 19 deletions(-)

diff --git a/crypto/aes/+x86_64/ni_native.s b/crypto/aes/+x86_64/ni_native.s @@ -52,6 +52,9 @@ enc_key_128: call key_expand_128 movdqu %xmm1, 0xa0(%rcx) + # return rklen + mov $176, %rax + jmp dec_key key_expand_128: vpslldq $0x4, %xmm1, %xmm3 @@ -124,6 +127,9 @@ enc_key_192: movdqu %xmm1, 0xc0(%rcx) movdqu %xmm3, %xmm5 + # return rklen + mov $208, %rax + jmp dec_key key_expand_192: @@ -191,6 +197,10 @@ enc_key_256: aeskeygenassist $0x40, %xmm3, %xmm2 call key_expand_256_a movdqu %xmm1, 0xe0(%rcx) + + # return rklen + mov $240, %rax + jmp dec_key key_expand_256_a: @@ -224,17 +234,10 @@ key_expand_256_b: dec_key: movq 0x40(%rbp), %rdx # &dec_rk - # store key in reverse order, therefore add rklen to rk pointer - mov $0x18, %rbx - je rklen_dec_key_192 - jle rklen_dec_key_256 - add $160, %rdx - jmp dec_key_start -rklen_dec_key_192: - add $192, %rdx - jmp dec_key_start -rklen_dec_key_256: - add $224, %rdx + # store key in reverse order, therefore add offset to last rk item + add %rax, %rdx + sub $16, %rdx + dec_key_start: movdqu 0x0(%rcx), %xmm1 @@ -268,6 +271,7 @@ dec_key_start: aesimc %xmm1, %xmm1 movdqu %xmm1, -0x90(%rdx) + mov $208, %rbx cmp %rax, %rbx je dec_key_192 jle dec_key_256 @@ -275,9 +279,6 @@ dec_key_start: movdqu 0xa0(%rcx), %xmm1 movdqu %xmm1, -0xa0(%rdx) - # return rklen - movl $176, %eax - jmp key_exp_end dec_key_192: @@ -292,8 +293,6 @@ dec_key_192: movdqu 0xc0(%rcx), %xmm1 movdqu %xmm1, -0xc0(%rdx) - # return rklen - movl $208, %eax jmp key_exp_end dec_key_256: movdqu 0xa0(%rcx), %xmm1 @@ -313,9 +312,6 @@ dec_key_256: movdqu 0xe0(%rcx), %xmm1 movdqu %xmm1, -0xe0(%rdx) - # return rklen - movl $240, %eax - key_exp_end: pxor %xmm0, %xmm0 pxor %xmm1, %xmm1