-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support hw-accelerated AES on Thumb and Arm #8326
Conversation
cb9a096
to
ebaf8c3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some comments
I just push a commit to remove plain c code. I test it with below commands. Clang version is 14.0
And the result is
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just check the clang versions. poly64*_t
are available in clang 11.0 on aarch32
@yuhaoth I think the existing implementation of |
This looks good - please raise as a separate PR when this is in - let's avoid scope creep on this one. |
ab90683
to
8e39454
Compare
@bensze01 please could you add the linux-headers package to the CI (at least on the Ubuntu image) so that we can test the runtime-detection here? thanks |
It's easy to add the package to the docker images, but should we? Compiling a Linux application should not require kernel headers. If we do something that relies on them (and we aren't testing mbedtls as a Linux kernel component), it's good that it fails to compile on the CI: it tells us we're doing something wrong. |
That is what I thought. On my local Ubuntu 22.04, it's OK to only include Currently in |
I don't know why the cross-compilation toolchain packages are split this way. The native packages have a similar split, but In fact, we do have the |
Yes, it is wrong. |
library/aesce.c
Outdated
# if __clang_major__ < 4 | ||
# error "Minimum version of Clang for MBEDTLS_AESCE_C is 4.0." | ||
# if defined(MBEDTLS_ARCH_IS_ARM32) && (__clang_major__ < 11) | ||
# error "Minimum version of Clang for MBEDTLS_AESCE_C on 32-bit Arm or Thumb is 111.0." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrong typo
# error "Minimum version of Clang for MBEDTLS_AESCE_C on 32-bit Arm or Thumb is 111.0." | |
# error "Minimum version of Clang for MBEDTLS_AESCE_C on 32-bit Arm or Thumb is 11.0." |
library/sha256.c
Outdated
asm ("sha256h q0, q0, v0.4s" : : : "v0"); | ||
#else | ||
asm ("sha256h.32 q0, q0, q0" : : : "q0"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to put the volatile
on these two lines? (I was going to raise a PR to do this, but it would conflict with this one)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DId you mean to make this comment on the SHA PR? I can do that there if you like.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, yes, but we should always have asm volatile
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not for asm that does not have optimisable-out side effects - for this (i.e. the normal case where the asm is just used to compute something) we can allow the compiler to re-order this with respect to surrounding code if it wants.
Thanks. I think that it's not the arm64 packages that we are missing, but the 32-bit Armv8 packages, i.e. the hard-float ABI packages? On further investigation on my system (aarch64 Ubuntu 22.04), In searching the web, So in this case, I think we're missing |
ChangeLog.d/sha256-armce-arm.txt
Outdated
Features | ||
* Support Armv8 Crypto Extension acceleration for SHA-256 | ||
when compiling for Thumb or 32-bit Arm. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(a) extra blank line at the end of the file
(b) PR title references AES, this is about SHA-256 - isn't that #8298?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, you've commented on the wrong PR :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this PR missing needs-preceding-pr
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's based on 8298 in order to pick up the definition of MBEDTLS_ARCH_IS_ARMV8
. Yes, I'll add the label.
CI failure is spurious - OpenCI passed |
Co-authored-by: Jerry Yu <[email protected]> Signed-off-by: Dave Rodgman <[email protected]>
Co-authored-by: Jerry Yu <[email protected]> Signed-off-by: Dave Rodgman <[email protected]>
Signed-off-by: Dave Rodgman <[email protected]>
Signed-off-by: Dave Rodgman <[email protected]>
Signed-off-by: Dave Rodgman <[email protected]>
Signed-off-by: Dave Rodgman <[email protected]>
Signed-off-by: Dave Rodgman <[email protected]>
Signed-off-by: Dave Rodgman <[email protected]>
Signed-off-by: Dave Rodgman <[email protected]>
Signed-off-by: Dave Rodgman <[email protected]>
Signed-off-by: Dave Rodgman <[email protected]>
Signed-off-by: Dave Rodgman <[email protected]>
Signed-off-by: Dave Rodgman <[email protected]>
972eb15
to
5e41937
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
support_build_aes_armce() { | ||
# clang >= 4 is required to build with AES extensions | ||
ver="$(clang --version|grep version|sed -E 's#.*version ([0-9]+).*#\1#')" | ||
[ "${ver}" -ge 11 ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bah, missed that this doesn't match the comment two lines above. I have a PR touching this function that I'll fix this in
make -B library/aesce.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb -S" | ||
not grep -E 'aes[0-9a-z]+.[0-9]\s*[qv]' library/aesce.o | ||
msg "clang, test aarch64 crypto instructions not built" | ||
make -B library/aesce.o CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a -S" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tom-cosgrove-arm I'm confused as to exactly in what setting we test the absence of AES instructions. Specifically, why are we testing that on armv8-a
and not armv8-a+crypto
? Is that just copypasta or is there a reason?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I think the errors are on lines 4441 and 4444. Here we are checking that we don't emit AES instructions when we don't ask for them, so that (for example) we won't get SIGILL when run on an older Raspberry Pi (IIRC the RPi5 is the first with crypto extensions). If we passed +crypto
to the compiler it would be allowed to use any of those instructions itself, so could give false positives. So not having +crypto
here is correct, but having +crypto
in the two cases above is incorrect
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, thanks! I'll fix it in #9286.
Hmmm...
we don't emit AES instructions when we don't ask for them
But if we're telling the compiler not to use AES instructions, how would the test ever fail? If we were enabling assembly that calls AES instructions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And below with sha256:
make -B library/sha256.s CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a"
grep -E 'sha256[a-z0-9]+\s+[qv]' library/sha256.s
So we do find sha256 instructions on armv8-a
, presumably from our assembly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just following this thread for interest, but I just noticed and was about to raise: does this grepping work? It seems like we are grepping for the assembler mnemonic in the object file, which doesn't seem like it would work, even if we have intrinsics.
Surely we need to objdump
it first?
[I have checked on x86 in case I'm missing something and the aeskeygenassist
intrinsic doesn't leave a symbol in the object file, for example]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The -S
in CFLAGS
means "output assembly, not object code, into the output file" (which we still name with.o
, but hey-ho)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah okay, makes sense, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
commit acbdbc7c2b32368b07a5b49a170b202d880afa12
Author: Gilles Peskine <[email protected]>
Date: 2024-06-19 14:16:05 +0200
Use .s extension for assembly
Having assembly files called *.o was confusing.
Description
Extend support for AESCE to 32-bit builds.
Saves around 450b for Thumb 2 -Oz (but not for TF-M, because our reference target doesn't have Neon).
Manually tested via qemu, for arm, thumb and aarch64 with gcc and clang.
Do we want to put this in the Changelog as Security, because it enables const-time AES for these targets?
PR checklist
Please tick as appropriate and edit the reasons (e.g.: "backport: not needed because this is a new feature")