Add support for AES-XTS #538

Open
ruiliio wants to merge 2 commits from ruiliio/psa_xts into development
ruiliio commented 2025-10-20 16:46:50 -05:00 (Migrated from github.com)

Description

Add support for AES-XTS / PSA_ALG_XTS cipher in PSA: AES-128-XTS with a 256-bit key, AES-256-XTS with a 512-bit key. The changes include:

  • Enable generation and import of the double-length AES-XTS keys (256/512-bit) via a new helper psa_xts_adjust_key_bits() that halves the key size for validation.
  • Add a flag xts_unit_done to the cipher context to enforce one update call per operation, preventing a second call from reusing the tweak and producing wrong output.

Fix https://github.com/Mbed-TLS/mbedtls/issues/6384

PR checklist

## Description Add support for AES-XTS / `PSA_ALG_XTS` cipher in PSA: AES-128-XTS with a 256-bit key, AES-256-XTS with a 512-bit key. The changes include: - Enable generation and import of the double-length AES-XTS keys (256/512-bit) via a new helper `psa_xts_adjust_key_bits()` that halves the key size for validation. - Add a flag `xts_unit_done` to the cipher context to enforce one update call per operation, preventing a second call from reusing the tweak and producing wrong output. Fix https://github.com/Mbed-TLS/mbedtls/issues/6384 ## PR checklist - [x] **changelog** provided - [x] **framework PR** provided Mbed-TLS/mbedtls-framework# https://github.com/Mbed-TLS/mbedtls-framework/pull/228 - [x] **mbedtls development PR** not required because: no changes - [x] **mbedtls 3.6 PR** not required because: no backport - **tests** provided
davidhorstmann-arm commented 2026-01-14 04:58:13 -06:00 (Migrated from github.com)

Thanks for this contribution!

This is on the larger side of size-s. Luckily it's mostly plumbing to the existing legacy implementation rather than a new implementation, so that should make it easier to review. It looks well-tested which is great!

Thanks for this contribution! This is on the larger side of size-s. Luckily it's mostly plumbing to the existing legacy implementation rather than a new implementation, so that should make it easier to review. It looks well-tested which is great!
ruiliio commented 2026-02-04 15:24:14 -06:00 (Migrated from github.com)

Thanks for your feedback. I've fixed the previous CI errors. This is ready for review now.

Thanks for your feedback. I've fixed the previous CI errors. This is ready for review now.
ruiliio commented 2026-02-22 18:38:31 -06:00 (Migrated from github.com)

I have pushed additional CI fixes. Ready for another run whenever you get a chance. Thank you.

I have pushed additional CI fixes. Ready for another run whenever you get a chance. Thank you.
ruiliio commented 2026-02-23 22:07:22 -06:00 (Migrated from github.com)

Rebased and ready for another CI run. Thank you very much.

Rebased and ready for another CI run. Thank you very much.
dbuenzli commented 2026-05-20 14:34:03 -05:00 (Migrated from github.com)

Is there a version ETA on this getting merged?

Is there a version ETA on this getting merged?
bjwtaylor (Migrated from github.com) reviewed 2026-07-08 04:12:43 -05:00
bjwtaylor (Migrated from github.com) left a comment

Some initial comments

Some initial comments
@ -0,0 +1,3 @@
Features
bjwtaylor (Migrated from github.com) commented 2026-07-07 07:40:56 -05:00

Putting this at the beginning as the file isn't modified. include/psa/crypto_sizes.h:1089-1095` still says XTS is unsupported. The size is also too small to support the 64 bit keys.

Putting this at the beginning as the file isn't modified. include/psa/crypto_sizes.h:1089`-`1095` still says XTS is unsupported. The size is also too small to support the 64 bit keys.
bjwtaylor (Migrated from github.com) commented 2026-07-08 04:12:25 -05:00

Will this combined with drivers/builtin/src/psa_crypto_cipher.c:111 mean that more alg type key type combinations than are currently supported are advertised. Such as?
PSA_ALG_XTS + PSA_KEY_TYPE_AES -> AES, XTS
PSA_ALG_XTS + PSA_KEY_TYPE_ARIA -> ARIA, XTS
PSA_ALG_XTS + PSA_KEY_TYPE_CAMELLIA -> CAMELLIA, XTS

Will this combined with drivers/builtin/src/psa_crypto_cipher.c:111 mean that more alg type key type combinations than are currently supported are advertised. Such as? PSA_ALG_XTS + PSA_KEY_TYPE_AES -> AES, XTS PSA_ALG_XTS + PSA_KEY_TYPE_ARIA -> ARIA, XTS PSA_ALG_XTS + PSA_KEY_TYPE_CAMELLIA -> CAMELLIA, XTS
bjwtaylor (Migrated from github.com) reviewed 2026-07-08 04:13:45 -05:00
bjwtaylor (Migrated from github.com) left a comment

Also the Ci is currently failing and this will require resolution

Also the Ci is currently failing and this will require resolution
ruiliio (Migrated from github.com) reviewed 2026-07-15 17:55:04 -05:00
@ -0,0 +1,3 @@
Features
ruiliio (Migrated from github.com) commented 2026-07-15 17:55:03 -05:00

Thanks for pointing it out. Fixed in the new commits. PSA_CIPHER_MAX_KEY_LENGTH is now raised to 64 bytes when XTS is enabled.

Thanks for pointing it out. Fixed in the new commits. `PSA_CIPHER_MAX_KEY_LENGTH` is now raised to 64 bytes when XTS is enabled.
ruiliio (Migrated from github.com) reviewed 2026-07-15 17:56:15 -05:00
ruiliio (Migrated from github.com) commented 2026-07-15 17:56:14 -05:00

Yes. Changed to only advertise AES-XTS.

Yes. Changed to only advertise AES-XTS.
ruiliio commented 2026-08-03 18:01:08 -05:00 (Migrated from github.com)

@bjwtaylor Thanks for the review. Rebased and ready for a CI run when you get a chance.

@bjwtaylor Thanks for the review. Rebased and ready for a CI run when you get a chance.
This pull request has changes conflicting with the target branch.
  • configs/crypto-config-symmetric-only.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 'ruiliio/psa_xts:ruiliio/psa_xts'
git switch 'ruiliio/psa_xts'

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 'ruiliio/psa_xts'
git switch 'ruiliio/psa_xts'
git rebase 'development'
git switch 'development'
git merge --ff-only 'ruiliio/psa_xts'
git switch 'ruiliio/psa_xts'
git rebase 'development'
git switch 'development'
git merge --no-ff 'ruiliio/psa_xts'
git switch 'development'
git merge --squash 'ruiliio/psa_xts'
git switch 'development'
git merge --ff-only 'ruiliio/psa_xts'
git switch 'development'
git merge 'ruiliio/psa_xts'
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!538
No description provided.