Repository navigation
Remove x86/x86_64 BSAES and AES_ASM support - #9677
bernd-edlinger wants to merge 3 commits into
Conversation
|
WIP because I cant get linux-x86 to work only if I add -DOPENSSL_IA32_SSE2 manually: |
|
Actually, it seems that the definition of |
|
Nope, I was wrong about that, it does get defined in |
|
Yes, the define is there but only in the C and .s modules when they get compiled. |
|
See #9679 |
45ac213 to
8981d50
Compare
|
Rebased, taking out of WIP. |
|
@levitte does this need a CHANGES entry? |
|
Is this OK for trunk? |
Is this a user visible change? From
I would say that yeah, if you like, but not mandatory. |
There was a problem hiding this comment.
It's better if you use defined(AES_ASM) than !defined(OPENSSL_NO_ASM), since there's potential lack of asm support even if configured without no-asm
There was a problem hiding this comment.
I think that will not work, because AES_ASM is no longer defined
in all cases.
Previously we had either AES_ASM or AES_ASM + BSAES_ASM + VPAES_ASM
or ASE_ASM + VPASE_ASM
but now we may also have AES_VPAES only.
But even without VPAES and BSAES we could still have aesni_encrypt/decrypt.
I did not remove aesni, that is constant time, but it needs a AESNI_CAPAPLE in
the ia32cap_P
|
Not sure if that is user visible, it does not change any API interface, just |
There was a problem hiding this comment.
I know this seems counterintuitive, but AES_ASM should still be defined
There was a problem hiding this comment.
I tried to do that, but aes_core.c will stop to function if AES_ASM is defined:
diff --git a/crypto/aes/build.info b/crypto/aes/build.info
index fb67a7b..2020268 100644
--- a/crypto/aes/build.info
+++ b/crypto/aes/build.info
@@ -5,12 +5,12 @@ IF[{- !$disabled{asm} -}]
$AESASM_x86=aes_core.c aes_cbc.c
$AESDEF_x86=
$AESASM_x86_sse2=vpaes-x86.s aesni-x86.s
- $AESDEF_x86_sse2=VPAES_ASM
+ $AESDEF_x86_sse2=AES_ASM VPAES_ASM
$AESASM_x86_64=\
aes_core.c aes_cbc.c vpaes-x86_64.s aesni-x86_64.s \
aesni-sha1-x86_64.s aesni-sha256-x86_64.s aesni-mb-x86_64.s
- $AESDEF_x86_64=VPAES_ASM
+ $AESDEF_x86_64=AES_ASM VPAES_ASM
$AESASM_ia64=aes_core.c aes_cbc.c aes-ia64.s
$AESDEF_ia64=AES_ASM
diff --git a/crypto/include/internal/ciphermode_platform.h b/crypto/include/internal/ciphermode_platform.h
index e55654f..6001428 100644
--- a/crypto/include/internal/ciphermode_platform.h
+++ b/crypto/include/internal/ciphermode_platform.h
@@ -94,7 +94,7 @@ void AES_xts_decrypt(const unsigned char *inp, unsigned char *out, size_t len,
# endif
# endif /* OPENSSL_CPUID_OBJ */
-# if !defined(OPENSSL_NO_ASM) && ( \
+# if defined(AES_ASM) && ( \
((defined(__i386) || defined(__i386__) || \
defined(_M_IX86)) && defined(OPENSSL_IA32_SSE2))|| \
defined(__x86_64) || defined(__x86_64__) || \
.->
gcc -Iinclude -pthread -m64 -Wa,--noexecstack -Wall -O3 -DNDEBUG -DOPENSSL_IA32_SSE2 -MMD -MF test/buildtest_c_asn1t-bin-buildtest_asn1t.d.tmp -MT test/buildtest_c_asn1t-bin-buildtest_asn1t.o -c -o test/buildtest_c_asn1t-bin-buildtest_asn1t.o test/buildtest_asn1t.c
crypto/aes/fips-dso-aes_cbc.o: In function `AES_cbc_encrypt':
aes_cbc.c:(.text+0x8): undefined reference to `AES_decrypt'
aes_cbc.c:(.text+0x1b): undefined reference to `AES_encrypt'
crypto/aes/fips-dso-aes_ecb.o: In function `AES_ecb_encrypt':
aes_ecb.c:(.text+0x6): undefined reference to `AES_decrypt'
aes_ecb.c:(.text+0x11): undefined reference to `AES_encrypt'
providers/common/ciphers/fips-dso-cipher_aes_hw.o: In function `cipher_hw_aes_initkey':
cipher_aes_hw.c:(.text+0x3d): undefined reference to `AES_encrypt'
cipher_aes_hw.c:(.text+0x120): undefined reference to `AES_decrypt'
providers/common/ciphers/fips-dso-cipher_ccm_hw.o: In function `ccm_generic_aes_initkey':
cipher_ccm_hw.c:(.text+0x252): undefined reference to `AES_encrypt'
providers/common/ciphers/fips-dso-cipher_gcm_hw.o: In function `generic_aes_gcm_initkey':
cipher_gcm_hw.c:(.text+0x299): undefined reference to `AES_encrypt'
collect2: error: ld returned 1 exit status
There was a problem hiding this comment.
Ah! Figured it out by looking at how this is done in 1.1.1. From Configure:
push @{$config{lib_defines}}, "AES_ASM" if ($target{aes_asm_src} =~ m/\baes-/);;So you're right, AES_ASM shouldn't be defined here since only aes_core.c and aes_cbc.c are used.
There was a problem hiding this comment.
However, you still need to add AES_ASM here (because vpaes-x86_64.pl)
There was a problem hiding this comment.
Please clarify, why?
There was a problem hiding this comment.
Basically, AES_ASM is meant to be added at any time there is any assembler support for AES added, such as vpaes-x86_64.pl...
The history behind this is that OpenSSL used to have a bunch of {something}_asm_src variables, which became config target attributes in 1.1.x (see Configurations/00-base-templates.conf, and as soon as those had something that could be identified as assembler amongst their files, some kind of macro is created to indicate what assembler support is added. These macros were previously added with special code in Configure...
Note that there are some files that aren't really assembler or perlasm but still generate an indicator macro... I remember that @dot-asm sometimes said that ASM should really be called AUX because of that, i.e. some units are auxilliary code, even thought most of them are assembler or perlasm.
Unfortunately, the situation is a bit messy, i.e. not all C code listens to {SOMETHING}_ASM macros, but check compiler macros for diverse hardware and simply assumes that the corresponding auxilliary files are built in as well, so things are sometimes hard to keep in sync.
I would very much like to see some kind of clean-up to make all this driven by build.info data, but that's a major task, and it's not been high priority so far ("It works, don't fix it" 'n all that...). If you're up for the task, feel free, but I think that should happen in a separate PR.
There was a problem hiding this comment.
I think the AES_ASM probably needs to be renamed globally to something new,
Probably there should be a define for AESNI_ASM, and maybe also for AES_GCM.
But I don't know for sure.
There was a problem hiding this comment.
That would be the bigger clean-up job...
This is a misleading assertion. If C version implemented same counter-measures as scalar assembly module, it would have been slower. To put it differently, counter-measures costs, and C version implements none. Apparent better performance is not a "recent GCC" phenomenon, it has been case for years. Of course one can argue that scalar assembly counter-measures are not sufficient by modern standards. But thing is that modern standards hold for modern processors, on which scalar module is not supposed to execute. So real question is how effective the counter-measures are on old systems. Are they shared-cache multi-core? If not, is timer interrupt's resolution sufficient? Of course one can still argue that one doesn't care about such old systems. Then say explicitly that, not that it's "slower." |
|
Oh, sorry, I did not want to insult you. openssl/crypto/aes/asm/aes-x86_64.pl Line 19 in 70adc64 However some counter-measures in the C code AES implementation would be good, since many use no-asm, but having an option to turn on some side-channel protection, or even constant time implementation would be great. |
??? Did I sound insulted? I care only about accuracy, so if anything was insulted, it was accuracy.
Next line reads "on Opteron 240 CPU," which is none-shared-cache processor, so CBC takes faster path [for larger blocks]. Did you fail to confirm it on the said processor with mentioned compiler? Well, not that I can confirm it by now, what I'm saying is rather that you can't really expect same coefficient on arbitrary system. As implied, key question is if cache is shared among multiple cores. Chances are that if you try to compare it on a contemporary processor, CBC will adhere to slow path at all input lengths, and you'll always observe worse performance... |
8981d50 to
ddcbbac
Compare
|
Well, when removing BSAES is not an option, then |
|
A rebase might be a good direction to start on 😉 |
ddcbbac to
ca11107
Compare
|
Rebase done. |
For BoringSSL, we did a handful of things:
The armv7 solution was a bit fussy. At the time, we didn't have the newly-written fallback implementation. I haven't looked at whether it would now make sense to use a simpler strategy. The C bits have probably diverged, but I'm happy to upstream whatever assembly changes are of interest. |
Yes, sounds good, since armv7 will continue to use BSAES, even with this PR installed. |
|
Here's the x86_64 bit: #10884 |
e5c33c2 to
b49d02f
Compare
|
rebased. |
|
This is an unhealthy situation that we cannot continue with this PR. This must cost you guys also some time. I guess I will clean up |
This leaves VPAES and AESNI support. The VPAES performance is comparable but BSAES is not completely constant time. There are table lookups using secret key data in AES_set_encrypt/decrypt_key and in ctr mode short data uses the non-constant time AES_encrypt function instead of bit-slicing. Furthermore the AES_ASM is by far outperformed by recent GCC versions. Since BSAES calls back to AES_ASM for short data blocks the performance on those is also worse than the pure software implementation. Fixes: openssl#9640
This adds an analog to the (currently unused) "2x" optimization from vpaes-armv8.pl and a ctr128_f implementation.
b49d02f to
2807606
Compare
|
Rebased, as you can see those assembler modules need adjustments all the time, |
|
This is especially paradox situation, as they are already removed in 1.1.1 |
|
Note this is part of my attempt to remove non-constant time AES code |
|
Should this be revived? |
This leaves VPAES and AESNI support.
The VPAES performance is comparable but BSAES is not
completely constant time. There are table lookups
using secret key data in AES_set_encrypt/decrypt_key
and in ctr mode short data uses the non-constant
time AES_encrypt function instead of bit-slicing.
Furthermore the AES_ASM is by far outperformed
by recent GCC versions.
Since BSAES calls back to AES_ASM for short
data blocks the performance on those is also
worse than the pure software implementaion.
Fixes: #9640
Checklist