Skip to content

aes: add AES-128-XTS and AES-256-XTS - #506

Open
MarkAtwood wants to merge 1 commit into
wolfSSL:masterfrom
MarkAtwood:aes-xts
Open

MarkAtwood wants to merge 1 commit into
wolfSSL:masterfrom
MarkAtwood:aes-xts

Conversation

@MarkAtwood

Copy link
Copy Markdown
Contributor

Colton is going to do this, you can take what you want from this

wolfProvider registers no AES-XTS cipher, so with wolfProvider as the default provider any EVP fetch of XTS fails:

EVP_CIPHER_fetch(NULL, "AES-256-XTS", NULL) = NULL
...:error:0308010C:digital envelope routines:inner_evp_generic_fetch:unsupported:crypto/evp/evp_fetch.c:375:Global default library context, Algorithm (AES-256-XTS : 17), Properties (<null>)

Ceph librbd image encryption and other disk-encryption code use AES-XTS through EVP. wolfCrypt already has XTS (wc_AesXts*); only the provider glue is missing. See #433.

This adds AES-128-XTS and AES-256-XTS in a new src/wp_aes_xts.c, following OpenSSL's AES-XTS: the key is the data key followed by the tweak key, the IV is the 16-byte tweak, and each update is one data unit (16 bytes to 2^20 blocks, ciphertext stealing for a partial last block). Two deliberate differences from the default provider: equal key halves are rejected for decryption too (as OpenSSL's FIPS provider and wolfCrypt FIPS do), and a re-init that changes direction without a new key fails. In FIPS builds the entries are registered fips=no, so a fips=yes fetch does not get them. Gated on WOLFSSL_AES_XTS and wolfSSL 5.6.6+ (wc_AesXtsSetKeyNoInit).

New unit tests test_aes128_xts and test_aes256_xts check IEEE Std 1619-2007 vectors 2 and 15 and NIST CAVP XTSGenAES128/XTSGenAES256 vectors (hex tweak format, including a 200-bit data unit), compare against OpenSSL's default provider for 16 to 1023 bytes and two data units in one context, and check rejection of short input, equal key halves and a direction change without a key.

Tested on master cd8836f with scripts/build-wolfprovider.sh (OpenSSL 3.5.4, wolfSSL 5.9.4):

  • Default build: 249/249 unit tests pass. With the src/ and include/ changes reverted (keeping only the WP_HAVE_AESXTS define so the tests compile), both new tests fail and the other 247 pass.
  • --replace-default --enable-replace-default-testing: 249/249 pass. The fetch above fails on master and succeeds with this change.
  • FIPS Ready 5.9.4 bundle (--fips-check=ready): 226/226 pass, including both XTS tests.

OpenSSL applications that fetch AES-XTS get "unsupported" from
wolfProvider. Register AES-128-XTS and AES-256-XTS on wolfCrypt's
wc_AesXts* API, following OpenSSL's AES-XTS:

- the key is the data key followed by the tweak key (32 or 64 bytes)
  and the IV is the 16-byte tweak;
- each update is one data unit using that tweak: at least 16 bytes,
  with ciphertext stealing for a partial last block, and at most 2^20
  blocks (IEEE Std 1619-2018, NIST SP 800-38E); final outputs nothing.

Two deliberate differences from OpenSSL's default provider:

- equal key halves are rejected for encryption and decryption. The
  default provider rejects them only for encryption; its FIPS provider
  and wolfCrypt FIPS builds reject both, so FIPS and non-FIPS builds of
  wolfProvider behave the same;
- a re-init that changes direction without a new key fails, and the
  context then refuses data, because the key schedule is set up for
  one direction.

In FIPS builds the XTS entries are registered with fips=no rather than
fips=yes, so a fetch that asks for fips=yes does not get them. Other
algorithms are unchanged. There is no AES-192-XTS, as in OpenSSL.

Needs wolfSSL 5.6.6 or later (wc_AesXtsSetKeyNoInit) built with
WOLFSSL_AES_XTS.

Add test_aes128_xts and test_aes256_xts: IEEE Std 1619-2007 vectors 2
and 15 and NIST CAVP XTSGenAES128/XTSGenAES256 vectors (hex tweak
format, including a 200-bit data unit), interop with OpenSSL's default
provider for 16 to 1023 bytes (and two data units in one context), and
rejection of short input, equal key halves and a direction change
without a key.
Copilot AI balanced review requested due to automatic review settings October 7, 2026 18:47

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Context duplication and partial initialization cleanup leave unresolved resource-ownership defects.

2 open findings
What changed in this PR

Adds wolfCrypt-backed AES-XTS support for EVP disk-encryption consumers, addressing #433.

Changes:

  • Registers AES-128-XTS and AES-256-XTS with version gating and non-FIPS properties.
  • Implements cipher operations and adds vector, interoperability, and rejection tests.
  • Updates build integration and documentation.
File Description
test/​unit.h Declares XTS tests.
test/​unit.c Registers XTS tests.
test/​test_cipher.c Adds XTS validation and interoperability coverage.
src/​wp_wolfprov.c Registers XTS cipher implementations.
src/​wp_aes_xts.c Implements AES-XTS provider operations.
src/​include.am Adds XTS to Automake sources.
README.md Lists XTS support.
include/​wolfprovider/​settings.h Gates XTS on wolfSSL support.
include/​wolfprovider/​alg_funcs.h Adds algorithm names and dispatch declarations.
IDE/​WINVS/​wolfprovider/​wolfprovider.vcxproj Adds XTS to the Windows build.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/wp_aes_xts.c
Comment on lines +95 to +96
/* XtsAes is copied by value, as Aes is for the other AES ciphers. */
XMEMCPY(dst, src, sizeof(*src));
Comment thread src/wp_aes_xts.c
Comment on lines +568 to +570
if ((ctx != NULL) && \
(wc_AesXtsInit(&ctx->xts, NULL, INVALID_DEVID) != 0)) { \
OPENSSL_free(ctx); \
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants