Skip to content

Fix/xwing integrity length check#445

Open
sverma98015-commits wants to merge 3 commits into
apple:mainfrom
sverma98015-commits:fix/xwing-integrity-length-check
Open

Fix/xwing integrity length check#445
sverma98015-commits wants to merge 3 commits into
apple:mainfrom
sverma98015-commits:fix/xwing-integrity-length-check

Conversation

@sverma98015-commits

Copy link
Copy Markdown

Enforce correct byte size check and prevent out-of-bounds slicing in X-Wing integrityCheckedRepresentation initializer.

Checklist

  • I've run tests to see all new and existing tests pass
  • I've followed the code style of the rest of the project
  • I've read the Contribution Guidelines
  • I've updated the documentation if necessary

Motivation

The XWingMLKEM768X25519.PrivateKey initializer for integrityCheckedRepresentation previously enforced a guard check requiring a total count of 96 bytes. However, the X-Wing private key structure under the hood expects a 32-byte seed representation concatenated with a 32-byte SHA3-256 public key hash suffix, making the actual payload size exactly 64 bytes.

Because of this size mismatch, passing a valid 64-byte representation threw an incorrectParameterSize error. Additionally, attempting to slice the trailing 32 bytes using .dropFirst(32) on a strictly 64-byte collection was prone to slicing index issues depending on the underlying DataProtocol backing type.

Modifications

  • Updated the size verification guard check in init(integrityCheckedRepresentation:) from 96 to strictly enforce 64 bytes.
  • Swapped out the starting-slice logic for publicKeyHashBytes to use .suffix(32), ensuring a reliable slice of the final 32 bytes regardless of the input data layout.

Result

  • Valid X-Wing integrityCheckedRepresentation keys can now be successfully initialized without triggering a parameter size mismatch error.
  • All 4 targeted validation unit tests in XWingTests now pass successfully.

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.

1 participant