Skip to content

add xts-aes and aes-kw(p) algos - #99

Merged
Khang (nnmkhang) merged 20 commits into
release/0.6.0from
user/khangnguyen/aes_kw_xts
May 21, 2026
Merged

add xts-aes and aes-kw(p) algos#99
Khang (nnmkhang) merged 20 commits into
release/0.6.0from
user/khangnguyen/aes_kw_xts

Conversation

@nnmkhang

@nnmkhang Khang (nnmkhang) commented May 8, 2026

Copy link
Copy Markdown
Contributor

Description of Changes:

  • adding Aes_kw_xts
  • adding AES-KW(P)

Breaking Changes if any:

✅ Admin Checklist

  • Review the PR description and ensure all necessary details are included.
  • Update/add unit tests for changed code.
  • Update/add documentation for new or changed APIs.
  • Run cargo test --all-features on Windows and WSL.

Check the Developer Guidelines in DEVELOPER.md for more info.

The previous commit drifted the SymCrypt submodule pointer from 748c20f1
(matches symcrypt-sys/VERSION.md) to 53be637. Reset it back so the
check-submodule CI workflow passes and bindings are regenerated against
the correct SymCrypt version.
Adds allowlist patterns for XTS-AES, AES-KW (RFC 3394), and AES-KWP
(RFC 5649) functions so they get exposed by symcrypt-sys.

Bindings will be regenerated via the generate_pr_label workflow.
Adds the XTS-AES (SYMCRYPT_XTS_AES_EXPANDED_KEY plus the seven XtsAes
functions) and AES-KW / AES-KWP encrypt/decrypt symbols to all four
arch-specific bindings files. Reverts the spacing-only tweak in the
bindgen comment that was used to retrigger the regen workflow.
Makes AesInnerKey pub(crate) so other modules can reuse it for AES-based
modes that share SYMCRYPT_AES_EXPANDED_KEY (AES-KW, AES-KWP). Adds a Drop
impl that calls SymCryptWipe on the inner state, matching the pattern
GcmInnerKey uses.
Three new modules backed by SymCrypt's native primitives:

- xts: XtsAes256Key with encrypt_in_place / decrypt_in_place using a
  64-bit tweak. Uses SymCryptXtsAesExpandKeyEx (FIPS-approved variant,
  enforcing the equality check on the two key halves).

- aes_kw: AesKwKey for RFC 3394 (8-byte-aligned plaintext, output =
  input + 8) and AesKwpKey for RFC 5649 (any non-zero length, output
  rounded up to a multiple of 8 plus 8). Both reuse the AES expanded
  key from cipher/mod.rs.

All entry points call crate::symcrypt_init() first, mirroring every
other primitive in the crate. KAT tests use vectors from SymCrypt's
own kat_xts.dat (IEEE 1619-2018 e/pi key) and kat_keywrap.dat
(NIST ACVP test vectors).

README documents the new APIs and notes that AES-KW(P) has no
general-purpose Windows BCrypt equivalent today; a future BCrypt-backed
variant will return a NotSupported runtime error on Windows for
AES-KW(P) until the BCrypt gap is filled upstream.
- xts.rs and aes_kw.rs move from the crate root into cipher/, joining
  cbc alongside the shared AES expanded-key infrastructure. Public
  paths become symcrypt::cipher::xts and symcrypt::cipher::aes_kw.

- AES-KW(P) methods renamed wrap/unwrap -> encrypt/decrypt to match
  the rest of the crate's cipher API (gcm, cbc) and avoid collision
  with Result::unwrap. The underlying algorithm is still described
  as wrap/unwrap in doc prose where the standards terminology applies.

- aes_kw internal import uses crate::cipher::AesInnerKey to match
  cbc.rs's existing style.

- xts.rs gains a byte-for-byte KAT test using the IEEE 1619-2018
  vector at symcrypt/unittest/kat_xts.dat:178 (e||pi key, tweak 0xff,
  512-byte plaintext as a single data unit). cbDataUnit == cbPlaintext
  for this KAT per katXtsSingle in testXts.cpp:519.

- xts.rs top-of-file docs are reorganized to mirror gcm.rs: an
  ## Encrypt in place and ## Decrypt in place sub-section under
  # Examples, each a self-contained runnable doctest.

gcm.rs and chacha.rs remain at the crate root for backwards
compatibility; they will move under cipher/ at the next intentional
breaking release.
Mirrors the cbc.rs pattern (which offers both aes_cbc_encrypt and
aes_cbc_encrypt_in_place). The new methods take separate plaintext
and ciphertext slices of equal length, useful when the caller wants
to preserve the plaintext for retry, verification, or logging.

In-place remains the natural shape for disk-sector use cases; the
out-of-place variant is purely additive.

AES-KW(P) deliberately does not get a corresponding pair because
its output size differs from input size, making 'in place' a misnomer
and the Vec-return shape match what HKDF, SP800-108, and RSA encrypt
already do for variable-size outputs.
The earlier draft used the symcrypt.h header's cbSrc shorthand. Spelling
it as plaintext.len() reads more naturally for Rust callers and the
file's top-of-module comment already directs readers to symcrypt.h for
deeper context.

Also drops two stale comments that named the kat_keywrap.dat section
the test vectors came from; the test bodies already cite the source.
@nnmkhang Khang (nnmkhang) changed the title add xts-aes and aes-kw(p) to bindgen allowlist add xts-aes and aes-kw(p) algos May 11, 2026
@nnmkhang
Khang (nnmkhang) marked this pull request as ready for review May 11, 2026 16:15
@nnmkhang Khang (nnmkhang) linked an issue May 18, 2026 that may be closed by this pull request
Comment thread rust-symcrypt/README.md Outdated
Comment thread rust-symcrypt/src/cipher/aes_kw.rs
Comment thread rust-symcrypt/src/cipher/aes_kw.rs Outdated
Comment thread rust-symcrypt/src/cipher/aes_kw.rs Outdated
Comment thread rust-symcrypt/src/cipher/aes_kw.rs Outdated
Comment thread rust-symcrypt/src/cipher/aes_kw.rs
Comment thread rust-symcrypt/src/cipher/xts.rs Outdated
Comment thread rust-symcrypt/src/cipher/xts.rs
Comment thread rust-symcrypt/src/cipher/xts.rs Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🕐

Base automatically changed from user/khangnguyen/sp800_108_kdf to release/0.6.0 May 19, 2026 01:45

@mlindgren Mitch Lindgren (mlindgren) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LLM reviewer found some additional issues:

Comment thread rust-symcrypt/src/cipher/aes_kw.rs
Comment thread rust-symcrypt/src/cipher/aes_kw.rs Outdated
Comment thread rust-symcrypt/src/cipher/aes_kw.rs
Comment thread rust-symcrypt/src/cipher/aes_kw.rs
Comment thread rust-symcrypt/src/cipher/xts.rs
Comment thread rust-symcrypt/src/cipher/xts.rs

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm modulo the one remaining discussion about Zeroize

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

shipit

@nnmkhang
Khang (nnmkhang) merged commit b76fde3 into release/0.6.0 May 21, 2026
16 checks passed
@nnmkhang
Khang (nnmkhang) deleted the user/khangnguyen/aes_kw_xts branch May 21, 2026 23:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support AES XTS

3 participants