AES performance #664

Open
daverodgman wants to merge 29 commits from daverodgman/aes12 into development
daverodgman commented 2026-01-18 15:42:00 -06:00 (Migrated from github.com)

Description

This PR improves AES performance for a range of variants, mostly focused on AES-CTR. gcc benefits significantly more.

AES-CTR: AESCE AES-CTR improves around 3.3x for GCC, 2.1x for clang. Scalar AES-CTR improves around 7-16%.
AES-GCM: Scalar AES-GCM typically improves a little (1-5%, both clang and gcc). With AESCE, gcc improves 39-45%, clang is not much different (-1% to 7%).
CTR-DRBG gets 14-39% benefit with gcc, and smaller (5% to 14%) benefit with clang.

Perf increases are fairly similar for -192 and -256 variants.

Size is a bit mixed, depending on config and compiler. GCC is smaller for all variants I tested, in the 120 - 356 bytes range. clang is -128 to +175 bytes.

This includes #649 .

compiler AESCE MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH size AES-CTR-128 AES-GCM-128 CTR-DRBG-NOPR
gcc-15 0 0 -196 14% 3% 14%
gcc-15 0 1 -120 16% 5% 20%
gcc-15 1 0 -208 238% 39% 29%
gcc-15 1 1 -356 220% 45% 39%
clang-17 0 0 -128 7% 1% 5%
clang-17 0 1 32 7% 3% 9%
clang-17 1 0 175 114% -1% 4%
clang-17 1 1 131 110% 8% 14%

PR checklist

  • changelog provided
  • framework PR provided Mbed-TLS/mbedtls-framework# | not required
  • mbedtls development PR provided Mbed-TLS/mbedtls# | not required because: non-functional change
  • mbedtls 3.6 PR provided Mbed-TLS/mbedtls# | not required because: non-functional change
  • tests provided | some additional tests to help cover AES-CTR corner cases

Notes for the submitter

Please refer to the contributing guidelines, especially the
checklist for PR contributors.

Help make review efficient:

  • Multiple simple commits
    • please structure your PR into a series of small commits, each of which does one thing
  • Avoid force-push
    • please do not force-push to update your PR - just add new commit(s)
  • See our Guidelines for Contributors for more details about the review process.
## Description This PR improves AES performance for a range of variants, mostly focused on AES-CTR. gcc benefits significantly more. AES-CTR: AESCE AES-CTR improves around 3.3x for GCC, 2.1x for clang. Scalar AES-CTR improves around 7-16%. AES-GCM: Scalar AES-GCM typically improves a little (1-5%, both clang and gcc). With AESCE, gcc improves 39-45%, clang is not much different (-1% to 7%). CTR-DRBG gets 14-39% benefit with gcc, and smaller (5% to 14%) benefit with clang. Perf increases are fairly similar for -192 and -256 variants. Size is a bit mixed, depending on config and compiler. GCC is smaller for all variants I tested, in the 120 - 356 bytes range. clang is -128 to +175 bytes. This includes #649 . | compiler | AESCE | MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH | size | AES-CTR-128 | AES-GCM-128 | CTR-DRBG-NOPR | |------------|-------|------------------------------------|------|-------------|-------------|---------------| | gcc-15 | 0 | 0 | -196 | 14% | 3% | 14% | | gcc-15 | 0 | 1 | -120 | 16% | 5% | 20% | | gcc-15 | 1 | 0 | -208 | 238% | 39% | 29% | | gcc-15 | 1 | 1 | -356 | 220% | 45% | 39% | | clang-17 | 0 | 0 | -128 | 7% | 1% | 5% | | clang-17 | 0 | 1 | 32 | 7% | 3% | 9% | | clang-17 | 1 | 0 | 175 | 114% | -1% | 4% | | clang-17 | 1 | 1 | 131 | 110% | 8% | 14% | ## PR checklist - [ ] **changelog** provided - [ ] **framework PR** provided Mbed-TLS/mbedtls-framework# | not required - [ ] **mbedtls development PR** provided Mbed-TLS/mbedtls# | not required because: non-functional change - [ ] **mbedtls 3.6 PR** provided Mbed-TLS/mbedtls# | not required because: non-functional change - [ ] **tests** provided | some additional tests to help cover AES-CTR corner cases ## Notes for the submitter Please refer to the [contributing guidelines](https://github.com/Mbed-TLS/TF-PSA-Crypto/blob/development/CONTRIBUTING.md), especially the checklist for PR contributors. Help make review efficient: * Multiple simple commits - please structure your PR into a series of small commits, each of which does one thing * Avoid force-push - please do not force-push to update your PR - just add new commit(s) * See our [Guidelines for Contributors](https://mbed-tls.readthedocs.io/en/latest/reviews/review-for-contributors/) for more details about the review process.
ronald-cron-arm commented 2026-01-19 10:01:55 -06:00 (Migrated from github.com)

Thanks for this pull request. It is probably too large for a normal community review and we might have to schedule its review or ask for a PR split.

Thanks for this pull request. It is probably too large for a normal community review and we might have to schedule its review or ask for a PR split.
This pull request has changes conflicting with the target branch.
  • core/alignment.h
  • core/tf_psa_crypto_common.h
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'daverodgman/aes12:daverodgman/aes12'
git switch 'daverodgman/aes12'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'development'
git merge --no-ff 'daverodgman/aes12'
git switch 'daverodgman/aes12'
git rebase 'development'
git switch 'development'
git merge --ff-only 'daverodgman/aes12'
git switch 'daverodgman/aes12'
git rebase 'development'
git switch 'development'
git merge --no-ff 'daverodgman/aes12'
git switch 'development'
git merge --squash 'daverodgman/aes12'
git switch 'development'
git merge --ff-only 'daverodgman/aes12'
git switch 'development'
git merge 'daverodgman/aes12'
git push origin 'development'
Sign in to join this conversation.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-Mbed-TLS/TF-PSA-Crypto!664
No description provided.